Skip to content

Commit 707720a

Browse files
mhiramatgregkh
authored andcommitted
tracing/probes: Avoid temporary buffer truncation in trace_probe_match_command_args()
commit 15f1978 upstream. 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. Link: https://lore.kernel.org/all/178454233010.290363.10428767141343428804.stgit@devnote2/ Fixes: eb5bf81 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0825925 commit 707720a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

kernel/trace/trace_probe.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,16 +2105,17 @@ int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b)
21052105
bool trace_probe_match_command_args(struct trace_probe *tp,
21062106
int argc, const char **argv)
21072107
{
2108-
char buf[MAX_ARGSTR_LEN + 1];
21092108
int i;
21102109

21112110
if (tp->nr_args < argc)
21122111
return false;
21132112

21142113
for (i = 0; i < argc; i++) {
2115-
snprintf(buf, sizeof(buf), "%s=%s",
2116-
tp->args[i].name, tp->args[i].comm);
2117-
if (strcmp(buf, argv[i]))
2114+
int len = strlen(tp->args[i].name);
2115+
2116+
if (strncmp(argv[i], tp->args[i].name, len) ||
2117+
argv[i][len] != '=' ||
2118+
strcmp(argv[i] + len + 1, tp->args[i].comm))
21182119
return false;
21192120
}
21202121
return true;

0 commit comments

Comments
 (0)