tracing/probes: Fix MAX_TRACE_ARGS limit handling
[ Upstream commit 73f35080477e893aa6f4c8d388352b871b288fbc ] When creating a trace_probe we would set nr_args prior to truncating the arguments to MAX_TRACE_ARGS. However, we would only initialize arguments up to the limit. This caused invalid memory access when attempting to set up probes with more than 128 fetchargs. BUG: kernel NULL pointer dereference, address: 0000000000000020 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: Oops: 0000 [#1] PREEMPT SMP PTI CPU: 0 UID: 0 PID: 1769 Comm: cat Not tainted 6.11.0-rc7+ #8 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-1.fc39 04/01/2014 RIP: 0010:__set_print_fmt+0x134/0x330 Resolve the issue by applying the MAX_TRACE_ARGS limit earlier. Return an error when there are too many arguments instead of silently truncating. Link: https://lore.kernel.org/all/20240930202656.292869-1-mikel@mikelr.com/ Fixes: 035ba76014c0 ("tracing/probes: cleanup: Set trace_probe::nr_args at trace_probe_init") Signed-off-by: Mikel Rychliski <mikel@mikelr.com> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
f475d8a0cc
commit
6bc24db74f
|
@ -915,6 +915,11 @@ static int __trace_eprobe_create(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc - 2 > MAX_TRACE_ARGS) {
|
||||||
|
ret = -E2BIG;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
mutex_lock(&event_mutex);
|
mutex_lock(&event_mutex);
|
||||||
event_call = find_and_get_event(sys_name, sys_event);
|
event_call = find_and_get_event(sys_name, sys_event);
|
||||||
ep = alloc_event_probe(group, event, event_call, argc - 2);
|
ep = alloc_event_probe(group, event, event_call, argc - 2);
|
||||||
|
@ -940,7 +945,7 @@ static int __trace_eprobe_create(int argc, const char *argv[])
|
||||||
|
|
||||||
argc -= 2; argv += 2;
|
argc -= 2; argv += 2;
|
||||||
/* parse arguments */
|
/* parse arguments */
|
||||||
for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
trace_probe_log_set_index(i + 2);
|
trace_probe_log_set_index(i + 2);
|
||||||
ret = trace_eprobe_tp_update_arg(ep, argv, i);
|
ret = trace_eprobe_tp_update_arg(ep, argv, i);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|
|
@ -1103,6 +1103,10 @@ static int __trace_fprobe_create(int argc, const char *argv[])
|
||||||
argc = new_argc;
|
argc = new_argc;
|
||||||
argv = new_argv;
|
argv = new_argv;
|
||||||
}
|
}
|
||||||
|
if (argc > MAX_TRACE_ARGS) {
|
||||||
|
ret = -E2BIG;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/* setup a probe */
|
/* setup a probe */
|
||||||
tf = alloc_trace_fprobe(group, event, symbol, tpoint, maxactive,
|
tf = alloc_trace_fprobe(group, event, symbol, tpoint, maxactive,
|
||||||
|
@ -1119,7 +1123,7 @@ static int __trace_fprobe_create(int argc, const char *argv[])
|
||||||
(unsigned long)tf->tpoint->probestub);
|
(unsigned long)tf->tpoint->probestub);
|
||||||
|
|
||||||
/* parse arguments */
|
/* parse arguments */
|
||||||
for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
trace_probe_log_set_index(i + 2);
|
trace_probe_log_set_index(i + 2);
|
||||||
ctx.offset = 0;
|
ctx.offset = 0;
|
||||||
ret = traceprobe_parse_probe_arg(&tf->tp, i, argv[i], &ctx);
|
ret = traceprobe_parse_probe_arg(&tf->tp, i, argv[i], &ctx);
|
||||||
|
|
|
@ -932,6 +932,10 @@ static int __trace_kprobe_create(int argc, const char *argv[])
|
||||||
argc = new_argc;
|
argc = new_argc;
|
||||||
argv = new_argv;
|
argv = new_argv;
|
||||||
}
|
}
|
||||||
|
if (argc > MAX_TRACE_ARGS) {
|
||||||
|
ret = -E2BIG;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/* setup a probe */
|
/* setup a probe */
|
||||||
tk = alloc_trace_kprobe(group, event, addr, symbol, offset, maxactive,
|
tk = alloc_trace_kprobe(group, event, addr, symbol, offset, maxactive,
|
||||||
|
@ -944,7 +948,7 @@ static int __trace_kprobe_create(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse arguments */
|
/* parse arguments */
|
||||||
for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
trace_probe_log_set_index(i + 2);
|
trace_probe_log_set_index(i + 2);
|
||||||
ctx.offset = 0;
|
ctx.offset = 0;
|
||||||
ret = traceprobe_parse_probe_arg(&tk->tp, i, argv[i], &ctx);
|
ret = traceprobe_parse_probe_arg(&tk->tp, i, argv[i], &ctx);
|
||||||
|
|
|
@ -556,6 +556,8 @@ static int __trace_uprobe_create(int argc, const char **argv)
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
return -ECANCELED;
|
return -ECANCELED;
|
||||||
|
if (argc - 2 > MAX_TRACE_ARGS)
|
||||||
|
return -E2BIG;
|
||||||
|
|
||||||
if (argv[0][1] == ':')
|
if (argv[0][1] == ':')
|
||||||
event = &argv[0][2];
|
event = &argv[0][2];
|
||||||
|
@ -681,7 +683,7 @@ static int __trace_uprobe_create(int argc, const char **argv)
|
||||||
tu->filename = filename;
|
tu->filename = filename;
|
||||||
|
|
||||||
/* parse arguments */
|
/* parse arguments */
|
||||||
for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
struct traceprobe_parse_context ctx = {
|
struct traceprobe_parse_context ctx = {
|
||||||
.flags = (is_return ? TPARG_FL_RETURN : 0) | TPARG_FL_USER,
|
.flags = (is_return ? TPARG_FL_RETURN : 0) | TPARG_FL_USER,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue