Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F110655929
D43155.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D43155.diff
View Options
diff --git a/sys/arm64/arm64/exception.S b/sys/arm64/arm64/exception.S
--- a/sys/arm64/arm64/exception.S
+++ b/sys/arm64/arm64/exception.S
@@ -193,55 +193,89 @@
2:
.endm
+#ifdef KMSAN
+/*
+ * The KMSAN runtime relies on a TLS block to track initialization and origin
+ * state for function parameters and return values. To keep this state
+ * consistent in the face of asynchronous kernel-mode traps, the runtime
+ * maintains a stack of blocks: when handling an exception or interrupt,
+ * kmsan_intr_enter() pushes the new block to be used until the handler is
+ * complete, at which point kmsan_intr_leave() restores the previous block.
+ *
+ * Thus, KMSAN_ENTER/LEAVE hooks are required only in handlers for events that
+ * may have happened while in kernel-mode. In particular, they are not required
+ * around amd64_syscall() or ast() calls. Otherwise, kmsan_intr_enter() can be
+ * called unconditionally, without distinguishing between entry from user-mode
+ * or kernel-mode.
+ */
+#define KMSAN_ENTER bl kmsan_intr_enter
+#define KMSAN_LEAVE bl kmsan_intr_leave
+#else
+#define KMSAN_ENTER
+#define KMSAN_LEAVE
+#endif
+
ENTRY(handle_el1h_sync)
save_registers 1
+ KMSAN_ENTER
ldr x0, [x18, #PC_CURTHREAD]
mov x1, sp
bl do_el1h_sync
+ KMSAN_LEAVE
restore_registers 1
ERET
END(handle_el1h_sync)
ENTRY(handle_el1h_irq)
save_registers 1
+ KMSAN_ENTER
mov x0, sp
bl intr_irq_handler
+ KMSAN_LEAVE
restore_registers 1
ERET
END(handle_el1h_irq)
ENTRY(handle_el0_sync)
save_registers 0
+ KMSAN_ENTER
ldr x0, [x18, #PC_CURTHREAD]
mov x1, sp
str x1, [x0, #TD_FRAME]
bl do_el0_sync
do_ast
+ KMSAN_LEAVE
restore_registers 0
ERET
END(handle_el0_sync)
ENTRY(handle_el0_irq)
save_registers 0
+ KMSAN_ENTER
mov x0, sp
bl intr_irq_handler
do_ast
+ KMSAN_LEAVE
restore_registers 0
ERET
END(handle_el0_irq)
ENTRY(handle_serror)
save_registers 0
+ KMSAN_ENTER
mov x0, sp
1: bl do_serror
b 1b
+ KMSAN_LEAVE
END(handle_serror)
ENTRY(handle_empty_exception)
save_registers 0
+ KMSAN_ENTER
mov x0, sp
1: bl unhandled_exception
b 1b
+ KMSAN_LEAVE
END(handle_empty_exception)
.macro vector name, el
diff --git a/sys/arm64/arm64/trap.c b/sys/arm64/arm64/trap.c
--- a/sys/arm64/arm64/trap.c
+++ b/sys/arm64/arm64/trap.c
@@ -33,6 +33,7 @@
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
+#include <sys/msan.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/ptrace.h>
@@ -478,6 +479,8 @@
int dfsc;
kasan_mark(frame, sizeof(*frame), sizeof(*frame), 0);
+ kmsan_mark(frame, sizeof(*frame), KMSAN_STATE_INITED);
+
far = frame->tf_far;
/* Read the esr register to get the exception details */
esr = frame->tf_esr;
@@ -591,6 +594,8 @@
get_pcpu(), READ_SPECIALREG(tpidr_el1)));
kasan_mark(frame, sizeof(*frame), sizeof(*frame), 0);
+ kmsan_mark(frame, sizeof(*frame), KMSAN_STATE_INITED);
+
far = frame->tf_far;
esr = frame->tf_esr;
exception = ESR_ELx_EXCEPTION(esr);
@@ -737,6 +742,8 @@
uint64_t esr, far;
kasan_mark(frame, sizeof(*frame), sizeof(*frame), 0);
+ kmsan_mark(frame, sizeof(*frame), KMSAN_STATE_INITED);
+
far = frame->tf_far;
esr = frame->tf_esr;
@@ -752,6 +759,8 @@
uint64_t esr, far;
kasan_mark(frame, sizeof(*frame), sizeof(*frame), 0);
+ kmsan_mark(frame, sizeof(*frame), KMSAN_STATE_INITED);
+
far = frame->tf_far;
esr = frame->tf_esr;
diff --git a/sys/kern/subr_intr.c b/sys/kern/subr_intr.c
--- a/sys/kern/subr_intr.c
+++ b/sys/kern/subr_intr.c
@@ -54,6 +54,7 @@
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
+#include <sys/msan.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/queue.h>
@@ -334,6 +335,7 @@
KASSERT(irq_root_filter != NULL, ("%s: no filter", __func__));
kasan_mark(tf, sizeof(*tf), sizeof(*tf), 0);
+ kmsan_mark(tf, sizeof(*tf), KMSAN_STATE_INITED);
VM_CNT_INC(v_intr);
critical_enter();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 22, 12:54 PM (1 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16771830
Default Alt Text
D43155.diff (3 KB)
Attached To
Mode
D43155: arm64: Make KMSAN aware of exceptions
Attached
Detach File
Event Timeline
Log In to Comment