All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] tracing/probes: Fixes several bugs
@ 2026-07-20 10:12 Masami Hiramatsu (Google)
  2026-07-20 10:12 ` [PATCH 1/4] tracing/probes: Avoid temporary buffer truncation in trace_probe_match_command_args() Masami Hiramatsu (Google)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-07-20 10:12 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers
  Cc: linux-kernel, linux-trace-kernel

Hi,

Here are a patches to fix some bugs in the probe events and eprobe.
These are found during cleaning up the code. I made these as a split
series because those could be backported. Let me send another
series for cleaning up probe event code.

Thank you,

---

Masami Hiramatsu (Google) (4):
      tracing/probes: Avoid temporary buffer truncation in trace_probe_match_command_args()
      tracing/probes: Prevent out-of-bounds write in __trace_probe_log_err()
      tracing/probes: Fix potential underflow in LEN_OR_ZERO macro
      tracing/eprobe: Fix exact system name matching in eprobe_dyn_event_match()


 kernel/trace/trace_eprobe.c |    3 ++-
 kernel/trace/trace_probe.c  |   13 +++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

--
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] tracing/probes: Avoid temporary buffer truncation in trace_probe_match_command_args()
  2026-07-20 10:12 [PATCH 0/4] tracing/probes: Fixes several bugs Masami Hiramatsu (Google)
@ 2026-07-20 10:12 ` Masami Hiramatsu (Google)
  2026-07-20 10:12 ` [PATCH 2/4] tracing/probes: Prevent out-of-bounds write in __trace_probe_log_err() Masami Hiramatsu (Google)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-07-20 10:12 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers
  Cc: linux-kernel, linux-trace-kernel

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

In trace_probe_match_command_args(), a stack buffer buf[MAX_ARGSTR_LEN + 1]
(256 bytes) is used to format "<name>=<comm>". However, since name can
be up to 32 bytes (MAX_ARG_NAME_LEN) and comm up to 255 bytes
(MAX_ARGSTR_LEN), the formatted string can exceed 256 bytes and get
truncated by snprintf(), causing spurious argument matching failures.

Instead of formatting into a temporary buffer on stack, compare the
argument name, the '=' delimiter, and the comm expression directly.

Fixes: eb5bf81330a7 ("tracing/kprobe: Add per-probe delete from event")
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/trace_probe.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index d17cfee77d9c..95e3d072321f 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -2338,16 +2338,17 @@ int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b)
 bool trace_probe_match_command_args(struct trace_probe *tp,
 				    int argc, const char **argv)
 {
-	char buf[MAX_ARGSTR_LEN + 1];
 	int i;
 
 	if (tp->nr_args < argc)
 		return false;
 
 	for (i = 0; i < argc; i++) {
-		snprintf(buf, sizeof(buf), "%s=%s",
-			 tp->args[i].name, tp->args[i].comm);
-		if (strcmp(buf, argv[i]))
+		int len = strlen(tp->args[i].name);
+
+		if (strncmp(argv[i], tp->args[i].name, len) ||
+		    argv[i][len] != '=' ||
+		    strcmp(argv[i] + len + 1, tp->args[i].comm))
 			return false;
 	}
 	return true;


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] tracing/probes: Prevent out-of-bounds write in __trace_probe_log_err()
  2026-07-20 10:12 [PATCH 0/4] tracing/probes: Fixes several bugs Masami Hiramatsu (Google)
  2026-07-20 10:12 ` [PATCH 1/4] tracing/probes: Avoid temporary buffer truncation in trace_probe_match_command_args() Masami Hiramatsu (Google)
@ 2026-07-20 10:12 ` Masami Hiramatsu (Google)
  2026-07-20 10:12 ` [PATCH 3/4] tracing/probes: Fix potential underflow in LEN_OR_ZERO macro Masami Hiramatsu (Google)
  2026-07-20 10:12 ` [PATCH 4/4] tracing/eprobe: Fix exact system name matching in eprobe_dyn_event_match() Masami Hiramatsu (Google)
  3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-07-20 10:12 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers
  Cc: linux-kernel, linux-trace-kernel

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

If trace_probe_log.argc is 0 in __trace_probe_log_err(), the loop
constructing the command string will not execute and p will remain equal to
command. Writing to *(p - 1) will cause an out-of-bounds access before
command. This should not happen, but better to be treated.

Reject if trace_probe_log.argc is 0.

Fixes: ab105a4fb894 ("tracing: Use tracing error_log with probe events")
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/trace_probe.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 95e3d072321f..49daa3cc2a45 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -188,7 +188,7 @@ void __trace_probe_log_err(int offset, int err_type)
 
 	lockdep_assert_held(&dyn_event_ops_mutex);
 
-	if (!trace_probe_log.argv)
+	if (!trace_probe_log.argv || !trace_probe_log.argc)
 		return;
 
 	/* Recalculate the length and allocate buffer */


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] tracing/probes: Fix potential underflow in LEN_OR_ZERO macro
  2026-07-20 10:12 [PATCH 0/4] tracing/probes: Fixes several bugs Masami Hiramatsu (Google)
  2026-07-20 10:12 ` [PATCH 1/4] tracing/probes: Avoid temporary buffer truncation in trace_probe_match_command_args() Masami Hiramatsu (Google)
  2026-07-20 10:12 ` [PATCH 2/4] tracing/probes: Prevent out-of-bounds write in __trace_probe_log_err() Masami Hiramatsu (Google)
@ 2026-07-20 10:12 ` Masami Hiramatsu (Google)
  2026-07-20 10:12 ` [PATCH 4/4] tracing/eprobe: Fix exact system name matching in eprobe_dyn_event_match() Masami Hiramatsu (Google)
  3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-07-20 10:12 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers
  Cc: linux-kernel, linux-trace-kernel

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

In __set_print_fmt(), LEN_OR_ZERO is defined as (len ? len - pos : 0).
If len is non-zero but smaller than pos, len - pos evaluates to a negative
integer. When passed as a size argument to snprintf(), this negative value
is cast to a large unsigned size_t, bypassing buffer size limits.

Ensure len > pos before subtracting to avoid integer underflow.

Fixes: 5bf652aaf46c ("tracing/probes: Integrate duplicate set_print_fmt()")
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/trace_probe.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 49daa3cc2a45..506e6037e163 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -2013,7 +2013,7 @@ int traceprobe_update_arg(struct probe_arg *arg)
 }
 
 /* When len=0, we just calculate the needed length */
-#define LEN_OR_ZERO (len ? len - pos : 0)
+#define LEN_OR_ZERO (len > pos ? len - pos : 0)
 static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,
 			   enum probe_print_type ptype)
 {


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] tracing/eprobe: Fix exact system name matching in eprobe_dyn_event_match()
  2026-07-20 10:12 [PATCH 0/4] tracing/probes: Fixes several bugs Masami Hiramatsu (Google)
                   ` (2 preceding siblings ...)
  2026-07-20 10:12 ` [PATCH 3/4] tracing/probes: Fix potential underflow in LEN_OR_ZERO macro Masami Hiramatsu (Google)
@ 2026-07-20 10:12 ` Masami Hiramatsu (Google)
  3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-07-20 10:12 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers
  Cc: linux-kernel, linux-trace-kernel

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

eprobe_dyn_event_match() checks if the target event system in argv[0]
matches ep->event_system using strncmp(ep->event_system, argv[0], len).
However, if ep->event_system is longer than len (e.g. "eprobes" vs
"ep/event"), strncmp() still returns 0 because the first len characters
match.

Check that ep->event_system[len] is '\0' to ensure exact system name
matching.

Fixes: 7d5fda1c841f ("tracing: Fix event probe removal from dynamic events")
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/trace_eprobe.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c
index 50518b071414..bcd97cb24ac9 100644
--- a/kernel/trace/trace_eprobe.c
+++ b/kernel/trace/trace_eprobe.c
@@ -172,7 +172,8 @@ static bool eprobe_dyn_event_match(const char *system, const char *event,
 	if (!slash)
 		return false;
 
-	if (strncmp(ep->event_system, argv[0], slash - argv[0]))
+	if (strncmp(ep->event_system, argv[0], slash - argv[0]) ||
+	    ep->event_system[slash - argv[0]] != '\0')
 		return false;
 	if (strcmp(ep->event_name, slash + 1))
 		return false;


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-20 10:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 10:12 [PATCH 0/4] tracing/probes: Fixes several bugs Masami Hiramatsu (Google)
2026-07-20 10:12 ` [PATCH 1/4] tracing/probes: Avoid temporary buffer truncation in trace_probe_match_command_args() Masami Hiramatsu (Google)
2026-07-20 10:12 ` [PATCH 2/4] tracing/probes: Prevent out-of-bounds write in __trace_probe_log_err() Masami Hiramatsu (Google)
2026-07-20 10:12 ` [PATCH 3/4] tracing/probes: Fix potential underflow in LEN_OR_ZERO macro Masami Hiramatsu (Google)
2026-07-20 10:12 ` [PATCH 4/4] tracing/eprobe: Fix exact system name matching in eprobe_dyn_event_match() Masami Hiramatsu (Google)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.