[PATCH] tracing/fprobe: Do not let KASAN check the $stackN read

From: Yifan Feng

Date: Tue Nov 17 2026 - 19:33:26 EST


ftrace_regs_get_kernel_stack_nth() reads the Nth entry of the kernel
stack for the $stackN argument of fprobe and tracepoint probe events.
That entry can be in the redzone of another stack frame, so with
CONFIG_KASAN_STACK every hit of such an event is reported:

# echo 'f:fp_read vfs_read $stack10' >> dynamic_events
# echo 1 > events/fprobes/fp_read/enable
BUG: KASAN: stack-out-of-bounds in process_fetch_insn+0xac9/0xcb0

Use READ_ONCE_NOCHECK(), as arm64 does in regs_get_kernel_stack_nth()
for kprobe events.

Fixes: 0566cefe73b9 ("tracing/fprobe: Enable fprobe events with CONFIG_DYNAMIC_FTRACE_WITH_ARGS")
Signed-off-by: Yifan Feng <evanfengff@xxxxxxxxx>
---
Tested on v7.4-rc3 in QEMU with KASAN: 6 reports before, 0 after.
Found and written with the help of an AI coding assistant.

include/linux/ftrace.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 1c2056a1a68b..bdb6ee6bc3b9 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -270,7 +270,7 @@ ftrace_regs_get_kernel_stack_nth(struct ftrace_regs *fregs, unsigned int nth)
stackp = (unsigned long *)ftrace_regs_get_stack_pointer(fregs);
if (((unsigned long)(stackp + nth) & ~(THREAD_SIZE - 1)) ==
((unsigned long)stackp & ~(THREAD_SIZE - 1)))
- return *(stackp + nth);
+ return READ_ONCE_NOCHECK(*(stackp + nth));

return 0;
}

base-commit: 63fdb511c27afcebce797e3db580b3534ddfa639
--
2.39.3 (Apple Git-146)