mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tracing/fprobe: Do not let KASAN check the $stackN read
@ 2026-11-18  0:32 Yifan Feng
  0 siblings, 0 replies; only message in thread
From: Yifan Feng @ 2026-11-18  0:32 UTC (permalink / raw)
  To: Masami Hiramatsu, Steven Rostedt
  Cc: Mark Rutland, linux-trace-kernel, linux-kernel, Yifan Feng

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@gmail.com>
---
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)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-18  0:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18  0:32 [PATCH] tracing/fprobe: Do not let KASAN check the $stackN read Yifan Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®