* [PATCH] tracing: Require kallsyms permission for the .function filter modifier
@ 2026-11-19 2:59 JunYoung Lee
2026-11-19 3:12 ` sashiko-bot
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 related [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 3:12 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19 3:12 UTC (permalink / raw)
To: JunYoung Lee; +Cc: linux-trace-kernel, linux-perf-users
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] tracing: unstripped cover letter and scissors line in commit
message
--
commit 8240d9570c52f6cf2edfd9796cbc32ecb0f181af
Author: JunYoung Lee <ljyoung04@gmail.com>
> tracing: Require kallsyms permission for the .function filter modifier
>
> 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>
[Severity: Low]
This isn't a bug, but the commit message retains the email greeting, notes
for the maintainers, and the "-- >8 --" scissors line above the actual
changelog. Transient commentary intended for maintainers belongs below the
"---" separator after the Signed-off-by trailer (or should be stripped with
"git am --scissors") so it does not end up in permanent git history.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119025941.87102-1-ljyoung04@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 3:12 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 3:12 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox