]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tracing/probes: Fix potential underflow in LEN_OR_ZERO macro
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Mon, 20 Jul 2026 10:12:29 +0000 (19:12 +0900)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Tue, 21 Jul 2026 01:23:17 +0000 (10:23 +0900)
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.

Link: https://lore.kernel.org/all/178454234934.290363.15247317871499514139.stgit@devnote2/
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

index 49daa3cc2a45a990d44e3dc91aeffa89cea16e34..506e6037e16375fb3de1bc4ea28bbdf803e9d1ef 100644 (file)
@@ -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)
 {