Skip to content

Commit 4ed3968

Browse files
mhiramatgregkh
authored andcommitted
tracing/probes: Fix potential underflow in LEN_OR_ZERO macro
commit 8ce20bf upstream. 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: 5bf652a ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 37a228f commit 4ed3968

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

kernel/trace/trace_probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ int traceprobe_update_arg(struct probe_arg *arg)
18861886
}
18871887

18881888
/* When len=0, we just calculate the needed length */
1889-
#define LEN_OR_ZERO (len ? len - pos : 0)
1889+
#define LEN_OR_ZERO (len > pos ? len - pos : 0)
18901890
static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,
18911891
enum probe_print_type ptype)
18921892
{

0 commit comments

Comments
 (0)