Linux Trace Kernel
 help / color / mirror / Atom feed
From: Yifan Feng <evanfengff@gmail.com>
To: Masami Hiramatsu <mhiramat@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yifan Feng <evanfengff@gmail.com>
Subject: [PATCH] tracing/fprobe: Do not let KASAN check the $stackN read
Date: Tue, 17 Nov 2026 16:32:05 -0800	[thread overview]
Message-ID: <20261118003205.59804-1-evanfengff@gmail.com> (raw)

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)


                 reply	other threads:[~2026-11-18  0:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118003205.59804-1-evanfengff@gmail.com \
    --to=evanfengff@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox