From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Zhan Xusheng <zhanxusheng1024@gmail.com>
Subject: [PATCH] tracing/probes: Treating longer symbol name on event comparation
Date: Tue, 28 Jul 2026 13:40:11 +0900 [thread overview]
Message-ID: <178521361102.34226.9650586522488974115.stgit@devnote2> (raw)
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
MAX_COMMON_HEAD_LEN (63) was used to allocate a temporary buffer for
formatting command heads in trace_kprobe_match_command_head() and
trace_uprobe_match_command_head(). However, the buffer size is too
short for some longer symbols. Especially, with rust code, the symbol
can be mangled and become very long.
Refactor trace_kprobe_match_command_head() to perform direct string
comparisons using strcmp() and strncmp(), eliminating the need for a
temporary buffer and removing the MAX_COMMON_HEAD_LEN string length
restriction on probe symbol names.
For trace_uprobe_match_command_head(), since tu->filename is already
matched via strncmp(), use a fixed 64-byte stack buffer solely for
formatting offset and ref_ctr_offset (which requires at most 39 bytes).
With all users converted, remove the MAX_COMMON_HEAD_LEN definition from
trace_probe.h.
Reported-by: Zhan Xusheng <zhanxusheng1024@gmail.com>
Link: https://lore.kernel.org/all/20260724023317.624074-1-zhanxusheng@xiaomi.com/
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
base-commit: 5be3a9db600853578559681b2dd20a9bc7dd4fc5
---
kernel/trace/trace_kprobe.c | 24 ++++++++++++++++--------
kernel/trace/trace_probe.h | 1 -
kernel/trace/trace_uprobe.c | 2 +-
3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index c25f902aa1a6..e41a7c113646 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -149,20 +149,28 @@ static bool trace_kprobe_is_busy(struct dyn_event *ev)
static bool trace_kprobe_match_command_head(struct trace_kprobe *tk,
int argc, const char **argv)
{
- char buf[MAX_COMMON_HEAD_LEN + 1];
+ char buf[32];
+ int len;
if (!argc)
return true;
- if (!tk->symbol)
+ if (!tk->symbol) {
snprintf(buf, sizeof(buf), "0x%p", tk->rp.kp.addr);
- else if (tk->rp.kp.offset)
- snprintf(buf, sizeof(buf), "%s+%u",
- trace_kprobe_symbol(tk), tk->rp.kp.offset);
- else
- snprintf(buf, sizeof(buf), "%s", trace_kprobe_symbol(tk));
- if (strcmp(buf, argv[0]))
+ if (strcmp(buf, argv[0]))
+ return false;
+ } else if (tk->rp.kp.offset) {
+ len = strlen(trace_kprobe_symbol(tk));
+ if (strncmp(trace_kprobe_symbol(tk), argv[0], len) ||
+ argv[0][len] != '+')
+ return false;
+
+ snprintf(buf, sizeof(buf), "%u", tk->rp.kp.offset);
+ if (strcmp(buf, &argv[0][len + 1]))
+ return false;
+ } else if (strcmp(trace_kprobe_symbol(tk), argv[0]))
return false;
+
argc--; argv++;
return trace_probe_match_command_args(&tk->tp, argc, argv);
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index c0f05763811c..fba1af092a9b 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -33,7 +33,6 @@
#define MAX_TRACE_ARGS 128
#define MAX_ARGSTR_LEN 255
-#define MAX_COMMON_HEAD_LEN 63
#define MAX_ARRAY_LEN 64
#define MAX_ARG_NAME_LEN 32
#define MAX_BTF_ARGS_LEN 128
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 67bd8fd91e3e..861d857adadb 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -281,7 +281,7 @@ static bool trace_uprobe_is_busy(struct dyn_event *ev)
static bool trace_uprobe_match_command_head(struct trace_uprobe *tu,
int argc, const char **argv)
{
- char buf[MAX_COMMON_HEAD_LEN + 1];
+ char buf[64];
int len;
if (!argc)
reply other threads:[~2026-07-28 4:40 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=178521361102.34226.9650586522488974115.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=rostedt@goodmis.org \
--cc=zhanxusheng1024@gmail.com \
/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
all inboxes | Powered by JetHome®