git: 8671e823b767 - main - amd64: do not pass SYSENTER frame to FRED fast syscall handler

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 27 Oct 2026 12:01:21 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=8671e823b7678731cd1aaf8850ccde4a2c293527

commit 8671e823b7678731cd1aaf8850ccde4a2c293527
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-10-27 10:08:14 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-10-27 11:59:41 +0000

    amd64: do not pass SYSENTER frame to FRED fast syscall handler
    
    With FRED, SYSCALL is delivered as event type syscall (7) and vector 1.
    SYSENTER is syscall with vector 2.  Handle SYSENTER in slow path,
    otherwise 32bit code is able to execute 64bit syscalls.
    
    Also check that SYSCALL comes from the 64bit mode. Intel already
    specifies that SYSCALL causes #UD in compatibility mode, but there is no
    AMD specification for SYSCALL under FRED yet, and SYSCALL is allowed
    in compatibility mode on AMD with IDT event delivery.
    
    Fixes:  6e93f5e4d693 ("amd64: FRED support")
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
---
 sys/amd64/amd64/exception.S | 8 ++++----
 sys/amd64/amd64/genassym.c  | 6 ++++++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/sys/amd64/amd64/exception.S b/sys/amd64/amd64/exception.S
index 206b56abc545..1fa797cf5d9e 100644
--- a/sys/amd64/amd64/exception.S
+++ b/sys/amd64/amd64/exception.S
@@ -1650,10 +1650,10 @@ fred_events_handlers:
 	movq	%rsi,TF_RSI(%rsp)
 	movl	TF_FRED_EVINFO2(%rsp),%edi
 	movl	%edi,%eax
-	andl	$TF_FRED_EVINFO2_TYPEMASK,%edi
-	cmpl	$TF_FRED_EVINFO2_TYPE_SYSCALL,%edi
-	je	user_fred_syscall
-	jmp	user_fred_non_syscall
+	andl	$TF_FRED_EVINFO2_SYSCALLMASK,%edi
+	cmpl	$TF_FRED_EVINFO2_SYSCALLVAL,%edi
+	jne	user_fred_non_syscall
+	jmp	user_fred_syscall
 
 	. = fred_events_handlers + 256
 	subq	$TF_ERR,%rsp
diff --git a/sys/amd64/amd64/genassym.c b/sys/amd64/amd64/genassym.c
index 9a5a74b3f6d6..e9ab1e23c81f 100644
--- a/sys/amd64/amd64/genassym.c
+++ b/sys/amd64/amd64/genassym.c
@@ -190,9 +190,15 @@ ASSYM(TF_FRED_EVINFO2, offsetof(struct trapframe, tf_fred_evinfo2));
 ASSYM(TF_FLAGS, offsetof(struct trapframe, tf_flags));
 ASSYM(TF_SIZE, sizeof(struct trapframe));
 ASSYM(TF_HASSEGS, TF_HASSEGS);
+ASSYM(TF_FRED_EVINFO2_VECMASK, TF_FRED_EVINFO2_VECMASK);
+ASSYM(TF_FRED_EVINFO2_VEC_SYSCALL, TF_FRED_EVINFO2_VEC_SYSCALL);
+ASSYM(TF_FRED_EVINFO2_SYSCALLMASK, TF_FRED_EVINFO2_TYPEMASK |
+    TF_FRED_EVINFO2_VECMASK | TF_FRED_EVINFO2_LM);
 ASSYM(TF_FRED_EVINFO2_TYPE_EXC, TF_FRED_EVINFO2_TYPE_EXC);
 ASSYM(TF_FRED_EVINFO2_TYPE_SYSCALL, TF_FRED_EVINFO2_TYPE_SYSCALL);
 ASSYM(TF_FRED_EVINFO2_TYPEMASK, TF_FRED_EVINFO2_TYPEMASK);
+ASSYM(TF_FRED_EVINFO2_SYSCALLVAL, TF_FRED_EVINFO2_TYPE_SYSCALL |
+    TF_FRED_EVINFO2_VEC_SYSCALL | TF_FRED_EVINFO2_LM);
 ASSYM(TF_FRED_EVINFO2_INSTLENMASK, TF_FRED_EVINFO2_INSTLENMASK);
 ASSYM(TF_FRED_EVINFO2_INSTLENSHIFT, TF_FRED_EVINFO2_INSTLENSHIFT);