Skip to contentSkip to conversation

tracing: check kallsyms_show_value() for numeric addresses in .function filter

PATCH In review Dominik Maier 3 participants 4 messages Nov 19 – Nov 20 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: check kallsyms_show_value() for numeric addresses in .function filter

In parse_pred(), the .function filter modifier accepts either a symbol name or a raw numeric kernel address (such as 0xffffffff81000000) and resolves it through kallsyms_lookup_size_offset().

While tracefs defaults to mode 0700, task-scoped counting tracepoint events can be opened via perf_event_open() under default perf_event_paranoid = 2 and configured via PERF_EVENT_IOC_SET_FILTER. Allowing raw numeric addresses in .function predicates without checking kallsyms_show_value(current_cred()) lets callers without kallsyms address visibility test whether candidate kernel addresses fall within a valid symbol despite kptr_restrict.

Gate raw numeric address parsing in the .function branch of parse_pred() on kallsyms_show_value(current_cred()), matching other tracing paths such as trace_kprobe and bpf_trace while keeping symbol-name filtering unchanged.

This issue was discovered with an AI-assisted code review tool (ARTIST) and reproduced in QEMU/KVM on an unmodified v7.4-rc3 kernel without kernel modifications or error injection. The fix was verified against the reproducer in QEMU/KVM, compile-tested with -Werror, and checked with checkpatch.pl --strict.

Fixes e6745a4da964 ("tracing: Add a way to filter function addresses to function names")
---
 kernel/trace/trace_events_filter.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/trace/trace_events_filter.c +5 -0
index c10951b..9192f3e 100644
@@ -8,6 +8,7 @@
 #include <linux/uaccess.h>
 #include <linux/module.h>
 #include <linux/ctype.h>
+#include <linux/kallsyms.h>
 #include <linux/mutex.h>
 #include <linux/perf_event.h>
 #include <linux/slab.h>
@@ -1760,6 +1761,10 @@ static int parse_pred(const char *str, void *data,
 		}
 
 		if (isdigit(str[i])) {
+			if (!kallsyms_show_value(current_cred())) {
+				parse_error(pe, FILT_ERR_INVALID_VALUE, pos + i);
+				goto err_free;
+			}
 			/* We allow 0xDEADBEEF */
 			while (isalnum(str[i]))
 				i++;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
maintainer
#1 lore raw
Quoted 11 lines · On Thu, 19 Nov 2026 20:22:33 +0100 Dominik Maier <[email protected]> wrote:

In parse_pred(), the .function filter modifier accepts either a symbol name or a raw numeric kernel address (such as 0xffffffff81000000) and resolves it through kallsyms_lookup_size_offset().

While tracefs defaults to mode 0700, task-scoped counting tracepoint events can be opened via perf_event_open() under default perf_event_paranoid = 2 and configured via PERF_EVENT_IOC_SET_FILTER. Allowing raw numeric addresses in .function predicates without checking kallsyms_show_value(current_cred()) lets callers without kallsyms address visibility test whether candidate kernel addresses fall within a valid symbol despite kptr_restrict.

God I HATE AI!!!

This is a perf bug, it needs to be solved in the perf code. How many times do I need to keep telling people with AI bots this! I think you are the third person to send the same patch.

The filter logic can expose kernel addresses. If perf isn't allowed to have access to that, then it shouldn't be allowed to filter.

-- Steve

maintainer
#2 lore raw
Quoted 15 lines · On Thu, 19 Nov 2026 15:19:01 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 11 lines · On Thu, 19 Nov 2026 20:22:33 +0100 Dominik Maier <[email protected]> wrote:

In parse_pred(), the .function filter modifier accepts either a symbol name or a raw numeric kernel address (such as 0xffffffff81000000) and resolves it through kallsyms_lookup_size_offset().

While tracefs defaults to mode 0700, task-scoped counting tracepoint events can be opened via perf_event_open() under default perf_event_paranoid = 2 and configured via PERF_EVENT_IOC_SET_FILTER. Allowing raw numeric addresses in .function predicates without checking kallsyms_show_value(current_cred()) lets callers without kallsyms address visibility test whether candidate kernel addresses fall within a valid symbol despite kptr_restrict.

Quoted 8 lines

God I HATE AI!!!

This is a perf bug, it needs to be solved in the perf code. How many times do I need to keep telling people with AI bots this! I think you are the third person to send the same patch.

The filter logic can expose kernel addresses. If perf isn't allowed to have access to that, then it shouldn't be allowed to filter.

I also want to point out that if you do filter by function name, the address of the function is what is recorded in the perf ring buffer that user space has access to. So all this change is doing is giving a false sense of security.

Another reason to not allow trace filtering (or tracing for that matter) if you do not want to expose kernel addresses.

-- Steve

maintainer Reviewed-by
#3 lore raw
In reply to Steven Rostedt
Quoted 15 lines · Steven Rostedt
Quoted 11 lines · On Thu, 19 Nov 2026 20:22:33 +0100 Dominik Maier <[email protected]> wrote:

In parse_pred(), the .function filter modifier accepts either a symbol name or a raw numeric kernel address (such as 0xffffffff81000000) and resolves it through kallsyms_lookup_size_offset().

While tracefs defaults to mode 0700, task-scoped counting tracepoint events can be opened via perf_event_open() under default perf_event_paranoid = 2 and configured via PERF_EVENT_IOC_SET_FILTER. Allowing raw numeric addresses in .function predicates without checking kallsyms_show_value(current_cred()) lets callers without kallsyms address visibility test whether candidate kernel addresses fall within a valid symbol despite kptr_restrict.

Quoted 8 lines

God I HATE AI!!!

This is a perf bug, it needs to be solved in the perf code. How many times do I need to keep telling people with AI bots this! I think you are the third person to send the same patch.

The filter logic can expose kernel addresses. If perf isn't allowed to have access to that, then it shouldn't be allowed to filter.

Yeah, I agree that this is perf's issue. It should add perf_event_paranoid = 3 to prohibit PERF_EVENT_IOC_SET_FILTER. But anyway, this fix itself looks good to me.

Thanks,

Quoted 4 lines

-- Steve

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>