git: 3416c2f3c5cf - stable/13 - irettraps: i386 does not push %ss/%esp when exception does not switch rings

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 31 Aug 2022 01:32:12 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=3416c2f3c5cff141c60effbd272757feb21fc81b

commit 3416c2f3c5cff141c60effbd272757feb21fc81b
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-08-22 01:20:28 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-08-31 01:20:27 +0000

    irettraps: i386 does not push %ss/%esp when exception does not switch rings
    
    (cherry picked from commit a03e4799e76bdfe432f560d96448895ba6ee6133)
---
 sys/i386/i386/exception.s | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/sys/i386/i386/exception.s b/sys/i386/i386/exception.s
index ac687aa502fb..7dad1cc5978b 100644
--- a/sys/i386/i386/exception.s
+++ b/sys/i386/i386/exception.s
@@ -234,22 +234,23 @@ irettraps:
 	leal	(doreti_iret - 1b)(%ebx), %edx
 	cmpl	%edx, TF_EIP(%esp)
 	jne	2f
-	movl	$(2 * TF_SZ - TF_EIP), %ecx
+	/* -8 because exception did not switch ring */
+	movl	$(2 * TF_SZ - TF_EIP - 8), %ecx
 	jmp	6f
 2:	leal	(doreti_popl_ds - 1b)(%ebx), %edx
 	cmpl	%edx, TF_EIP(%esp)
 	jne	3f
-	movl	$(2 * TF_SZ - TF_DS), %ecx
+	movl	$(2 * TF_SZ - TF_DS - 8), %ecx
 	jmp	6f
 3:	leal	(doreti_popl_es - 1b)(%ebx), %edx
 	cmpl	%edx, TF_EIP(%esp)
 	jne	4f
-	movl	$(2 * TF_SZ - TF_ES), %ecx
+	movl	$(2 * TF_SZ - TF_ES - 8), %ecx
 	jmp	6f
 4:	leal	(doreti_popl_fs - 1b)(%ebx), %edx
 	cmpl	%edx, TF_EIP(%esp)
 	jne	5f
-	movl	$(2 * TF_SZ - TF_FS), %ecx
+	movl	$(2 * TF_SZ - TF_FS - 8), %ecx
 	jmp	6f
 	/* kernel mode, normal */
 5:	FAKE_MCOUNT(TF_EIP(%esp))