* [PATCH] tracing: Require kallsyms permission for the .function filter modifier
@ 2026-11-19 2:59 JunYoung Lee
2026-11-19 13:56 ` Steven Rostedt
0 siblings, 1 reply; 2+ messages in thread
From: JunYoung Lee @ 2026-11-19 2:59 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu
Cc: Mathieu Desnoyers, Peter Zijlstra, linux-trace-kernel,
linux-perf-users, linux-kernel
Hi Steven, Masami,
An unprivileged user can locate the kernel image (KASLR bypass) with
PERF_EVENT_IOC_SET_FILTER at the default perf_event_paranoid=2.
parse_pred() accepts "<field>.function == <addr>" only if the address
resolves in kallsyms, and the perf path has no permission check, so the
ioctl result tells whether an address is kernel text. The details and
the fix are in the patch below.
Affected (reproduced as uid 65534, KASLR on), since e6745a4da964 (v6.3):
- mainline 4405c18c95d2 (v7.4-rc3-230)
- stable 6.12.118
Example on mainline: a counting event on ftrace:print (field "ip") and
561 probes return image_start=0xffffffffa1000000 and
image_end=0xffffffffaae30000. These equal _stext and _end in
/proc/kallsyms as read by root; the same user sees zeros there. No
tracefs and no capabilities are needed. Not affected:
perf_event_paranoid > 2, or perf_event_open blocked.
A C reproducer is available privately on request.
Testing of the patch on mainline with KASAN: for an unprivileged user
every .function form now fails with -EINVAL, and ordinary filters still
work. Root keeps .function via perf and tracefs (it is refused under
kptr_restrict=2, like kallsyms values). ftrace selftests test.d/filter
pass 4/4. checkpatch --strict and W=1 are clean. A 6.12.y backport is
available.
A separate issue seen while testing: as root, a .function filter on the
perf function event (ftrace:function) crashes the kernel with a NULL
dereference in ftrace_function_set_filter_pred(), because pred->regex
is not set on the .function path. It needs CAP_PERFMON. I can send
details if useful.
Found with AI-assisted code analysis. All results come from test runs.
Thanks,
JunYoung Lee
-- >8 --
"<field>.function == <operand>" resolves the operand to a kernel symbol
range. parse_pred() accepts the predicate only if
kallsyms_lookup_size_offset() succeeds, so the result of setting the
filter tells whether an address lies inside the kernel image (or a
module).
perf_event_open() allows any user to open a tracepoint event for
counting at the default perf_event_paranoid=2, and
PERF_EVENT_IOC_SET_FILTER passes the string to the same parser without
a permission check. An unprivileged user can therefore probe addresses
one ioctl at a time and recover _stext and _end exactly (about 560
ioctls on x86-64, under two seconds), while /proc/kallsyms shows that
user zeros.
Apply the rule that /proc/kallsyms uses, kallsyms_show_value() on the
current credentials, before the operand is looked at, so both the
numeric and the symbol name form are refused to callers who may not
see kernel addresses. Root and CAP_SYSLOG keep the modifier under the
default kptr_restrict. With kptr_restrict=2 it is refused to everyone,
the same as kallsyms values are hidden from everyone.
Fixes: e6745a4da964 ("tracing: Add a way to filter function addresses to function names")
Cc: stable@vger.kernel.org
Signed-off-by: JunYoung Lee <ljyoung04@gmail.com>
---
kernel/trace/trace_events_filter.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index c10951bcfc5f..895ef6d7652a 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -118,6 +118,7 @@ struct filter_pred {
C(IP_FIELD_ONLY, "Only 'ip' field is supported for function trace"), \
C(INVALID_VALUE, "Invalid value (did you forget quotes)?"), \
C(NO_FUNCTION, "Function not found"), \
+ C(FUNCTION_PERM, "Not permitted to filter on kernel addresses"), \
C(GLOB_WITHIN, "'within' filter cannot take glob expressions"), \
C(ERRNO, "Error"), \
C(NO_FILTER, "No filter found")
@@ -1743,6 +1744,16 @@ static int parse_pred(const char *str, void *data,
pred->op = op;
if (function) {
+ /*
+ * Whether the operand is accepted, and which events then
+ * match, tells where kernel text is. perf lets unprivileged
+ * users set filters, so apply the /proc/kallsyms rule.
+ */
+ if (!kallsyms_show_value(current_cred())) {
+ parse_error(pe, FILT_ERR_FUNCTION_PERM, pos + i);
+ goto err_free;
+ }
+
/* The field must be the same size as long */
if (field->size != sizeof(long)) {
parse_error(pe, FILT_ERR_ILLEGAL_FIELD_OP, pos + i);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tracing: Require kallsyms permission for the .function filter modifier
2026-11-19 2:59 [PATCH] tracing: Require kallsyms permission for the .function filter modifier JunYoung Lee
@ 2026-11-19 13:56 ` Steven Rostedt
0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2026-11-19 13:56 UTC (permalink / raw)
To: JunYoung Lee
Cc: Masami Hiramatsu, Mathieu Desnoyers, Peter Zijlstra,
linux-trace-kernel, linux-perf-users, linux-kernel
On Thu, 19 Nov 2026 11:59:41 +0900
JunYoung Lee <ljyoung04@gmail.com> wrote:
> Hi Steven, Masami,
>
> An unprivileged user can locate the kernel image (KASLR bypass) with
> PERF_EVENT_IOC_SET_FILTER at the default perf_event_paranoid=2.
> parse_pred() accepts "<field>.function == <addr>" only if the address
> resolves in kallsyms, and the perf path has no permission check, so the
> ioctl result tells whether an address is kernel text. The details and
> the fix are in the patch below.
>
> Affected (reproduced as uid 65534, KASLR on), since e6745a4da964 (v6.3):
> - mainline 4405c18c95d2 (v7.4-rc3-230)
> - stable 6.12.118
>
> Example on mainline: a counting event on ftrace:print (field "ip") and
> 561 probes return image_start=0xffffffffa1000000 and
> image_end=0xffffffffaae30000. These equal _stext and _end in
> /proc/kallsyms as read by root; the same user sees zeros there. No
> tracefs and no capabilities are needed. Not affected:
> perf_event_paranoid > 2, or perf_event_open blocked.
>
> A C reproducer is available privately on request.
>
> Testing of the patch on mainline with KASAN: for an unprivileged user
> every .function form now fails with -EINVAL, and ordinary filters still
> work. Root keeps .function via perf and tracefs (it is refused under
> kptr_restrict=2, like kallsyms values). ftrace selftests test.d/filter
> pass 4/4. checkpatch --strict and W=1 are clean. A 6.12.y backport is
> available.
>
> A separate issue seen while testing: as root, a .function filter on the
> perf function event (ftrace:function) crashes the kernel with a NULL
> dereference in ftrace_function_set_filter_pred(), because pred->regex
> is not set on the .function path. It needs CAP_PERFMON. I can send
> details if useful.
>
The code in kernel/trace are all privileged commands. If perf is the one
allowing unprivileged users access to these commands then the checks need
to be done in the perf code. It's not up to the trace code to handle perf
permissions.
This fix should not touch any code in kernel/trace/*
So NAK on this approach.
-- Steve
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 13:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 2:59 [PATCH] tracing: Require kallsyms permission for the .function filter modifier JunYoung Lee
2026-11-19 13:56 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®