Enable users to use perf-trace to trace their own processes, like strace
but without the overhead of ptrace(). Ensure that users cannot access
other users' or systemwide tracing data.
Changes in v4:
- Preserve security_perf_event_open(PERF_SECURITY_KERNEL) LSM hook in
the tp_bypass path.
- Lift the PERF_SAMPLE_IP check out of the tp_bypass path above the
PERF_SAMPLE_RAW branch so it applies to counting and sampling. This
also allows us to ensure PERF_SAMPLE_IP is set for uprobes.
- Block counting path for TRACE_EVENT_FL_CAP_ANY for unprivileged users
with sysctl_perf_event_paranoid > 1.
Changes in v3:
- Don't set PERF_SAMPLE_IP for unprivileged tracepoints. This allows us
to exclude PERF_SAMPLE_IP from kaddr_leak without weakening KASLR.
- Mount tracefs as world-traversable so users can access eventfs
directories.
Anubhav Shelat (3):
perf evsel: don't set PERF_SAMPLE_IP for unprivileged tracepoints
perf: enable unprivileged syscall tracing with perf trace
tracefs: make root directory world-traversable
fs/tracefs/inode.c | 2 +-
kernel/events/core.c | 28 +++++++++++++++++++++++++---
kernel/trace/trace_event_perf.c | 21 ++++++++++++++++++++-
kernel/trace/trace_events.c | 16 ++++++++++++++--
tools/perf/util/evsel.c | 14 +++++++++++++-
5 files changed, 73 insertions(+), 8 deletions(-)
--
2.54.0
For tracepoint events the IP is a static kernel address.
It doesn't vary by sample and provides no useful information for
unprivileged users. Skipping setting PERF_SAMPLE_IP for unprivileged
tracepoints avoids exposing a kernel address that reveals the KASLR base
offset.
Make an exception for uprobes, which are registered as
PERF_TYPE_TRACEPOINT, because the IP is important for their
functionality and is a safe userspace address. Detect them with
__probe_ip (entry) and __probe_ret_ip (return) using evsel__field().
Assisted-by: Claude:claude-sonnet-4.5
Signed-off-by: Anubhav Shelat <redacted>
---
tools/perf/util/evsel.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
Change the default tracefs mount mode from 0700 to 0755. This allows
unprivileged users to access the eventfs directories underneath which
already use 0755.
Tracing data files use mode 0440 and 0640 so they are not exposed by
this change. Only the format and id files, which have been marked as
work-readable, become accessible.
Directory listings of kprobes and uprobes, which contain functions or
binaries, become visible to unprivileged users but do not contain kernel
addresses. Admins using probes can restore the previous behavior with
chmod or mount -o mode=700.
Signed-off-by: Anubhav Shelat <redacted>
---
fs/tracefs/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Allow unprivileged users to trace their own processes' syscalls using
perf trace, similar to strace without the intrusive overhead of ptrace().
Currently, perf trace requires CAP_PERFMON or paranoid level ≤ 1 even
though the kernel has existing infrastructure (TRACE_EVENT_FL_CAP_ANY)
specifically designed to mark syscall tracepoints as safe for
unprivileged access. To fix this:
1. Loosen the condition in perf_event_open() which requires privileges
for all events with exclude_kernel=0. This allows perf_event_open() to
bypass the paranoid check for task-attached tracepoint events. Ensure
that sample types which can expose kernel addresses to unprivileged
users are blocked. Ensure the PERF_SECURITY_KERNEL LSM hook is
preserved.
2. Make the format and id tracefs files world-readable only for tracepoints
with TRACE_EVENT_FL_CAP_ANY, allowing unprivileged users to see syscall
tracepoint ids without exposing sensitive information.
3. Add a check to perf_trace_event_perm() to block PERF_SAMPLE_IP on
kernel tracepoints for unprivileged users to prevent KASLR bypass. We do
this here rather than in kaddr_leak because perf_trace_event_perm() can
distinguish between kernel tracepoints and uprobe tracepoints, where the
IP is a safe user space address and is necessary for uprobe
functionality.
4. Restrict pure counting events (no PERF_SAMPLE_RAW) to
TRACE_EVENT_FL_CAP_ANY tracepoints preventing unprivileged users from
counting internal kernel tracepoints while preserving current
behavior for exclude_kernel=1 events.
Example usage after this change:
$ perf trace ls # works as unprivileged user
$ perf trace # system-wide, still requires privileges
$ perf trace -p 1234 # requires ptrace permission on pid 1234
Assisted-by: Claude:claude-sonnet-4.5
Signed-off-by: Anubhav Shelat <redacted>
---
kernel/events/core.c | 28 +++++++++++++++++++++++++---
kernel/trace/trace_event_perf.c | 21 ++++++++++++++++++++-
kernel/trace/trace_events.c | 16 ++++++++++++++--
3 files changed, 59 insertions(+), 6 deletions(-)
@@ -72,9 +72,28 @@ static int perf_trace_event_perm(struct trace_event_call *tp_event,return-EINVAL;}+/*+*PERF_SAMPLE_IPonkerneltracepointsexposesakerneltext+*address,weakeningKASLR.Blockforunprivilegedusersunless+*thetracepointisauprobe(userspaceIP,safetoexpose).+*/+if((p_event->attr.sample_type&PERF_SAMPLE_IP)&&+!p_event->attr.exclude_kernel&&+!(tp_event->flags&TRACE_EVENT_FL_UPROBE)&&+sysctl_perf_event_paranoid>1&&!perfmon_capable())+return-EACCES;+/* No tracing, just counting, so no obvious leak */-if(!(p_event->attr.sample_type&PERF_SAMPLE_RAW))+if(!(p_event->attr.sample_type&PERF_SAMPLE_RAW)){+/* Prevent unprivileged users from counting kernel tracepoints */+if(!p_event->attr.exclude_kernel&&+sysctl_perf_event_paranoid>1&&!perfmon_capable()){+if(!(p_event->attach_state==PERF_ATTACH_TASK&&+(tp_event->flags&TRACE_EVENT_FL_CAP_ANY)))+return-EACCES;+}return0;+}/* Some events are ok to be traced by non-root users... */if(p_event->attach_state==PERF_ATTACH_TASK){
From: Steven Rostedt <rostedt@goodmis.org> Date: 2026-05-15 23:16:38
On Fri, 15 May 2026 15:40:07 -0400
Anubhav Shelat [off-list ref] wrote:
Change the default tracefs mount mode from 0700 to 0755. This allows
unprivileged users to access the eventfs directories underneath which
already use 0755.
Tracing data files use mode 0440 and 0640 so they are not exposed by
this change. Only the format and id files, which have been marked as
work-readable, become accessible.
Directory listings of kprobes and uprobes, which contain functions or
binaries, become visible to unprivileged users but do not contain kernel
addresses. Admins using probes can restore the previous behavior with
chmod or mount -o mode=700.
I've been thinking about this and I believe a better approach is to
make a eventfs that is mounted at:
/sys/kernel/events
and be the same directory structure as /sys/kernel/tracing/events but
only contain read only files like "id" and "format". This directory
would be mounted as 555 and readable by all.
-- Steve
From: Peter Zijlstra <peterz@infradead.org> Date: 2026-05-18 21:41:45
On Fri, May 15, 2026 at 03:40:06PM -0400, Anubhav Shelat wrote:
Allow unprivileged users to trace their own processes' syscalls using
perf trace, similar to strace without the intrusive overhead of ptrace().
Currently, perf trace requires CAP_PERFMON or paranoid level ≤ 1 even
though the kernel has existing infrastructure (TRACE_EVENT_FL_CAP_ANY)
specifically designed to mark syscall tracepoints as safe for
unprivileged access. To fix this:
1. Loosen the condition in perf_event_open() which requires privileges
for all events with exclude_kernel=0. This allows perf_event_open() to
bypass the paranoid check for task-attached tracepoint events. Ensure
that sample types which can expose kernel addresses to unprivileged
users are blocked. Ensure the PERF_SECURITY_KERNEL LSM hook is
preserved.
2. Make the format and id tracefs files world-readable only for tracepoints
with TRACE_EVENT_FL_CAP_ANY, allowing unprivileged users to see syscall
tracepoint ids without exposing sensitive information.
3. Add a check to perf_trace_event_perm() to block PERF_SAMPLE_IP on
kernel tracepoints for unprivileged users to prevent KASLR bypass. We do
this here rather than in kaddr_leak because perf_trace_event_perm() can
distinguish between kernel tracepoints and uprobe tracepoints, where the
IP is a safe user space address and is necessary for uprobe
functionality.
4. Restrict pure counting events (no PERF_SAMPLE_RAW) to
TRACE_EVENT_FL_CAP_ANY tracepoints preventing unprivileged users from
counting internal kernel tracepoints while preserving current
behavior for exclude_kernel=1 events.
Typically patches are supposed to a single thing, you're listing 4
things. What gives?
quoted hunk
Example usage after this change:
$ perf trace ls # works as unprivileged user
$ perf trace # system-wide, still requires privileges
$ perf trace -p 1234 # requires ptrace permission on pid 1234
Assisted-by: Claude:claude-sonnet-4.5
Signed-off-by: Anubhav Shelat <redacted>
---
kernel/events/core.c | 28 +++++++++++++++++++++++++---
kernel/trace/trace_event_perf.c | 21 ++++++++++++++++++++-
kernel/trace/trace_events.c | 16 ++++++++++++++--
3 files changed, 59 insertions(+), 6 deletions(-)
PERF_SAMPLE_IP should be here too, no?
And I'm not sure if tracepoints can trigger it, but PHYS_ADDR also seems
something we shouldn't allow.
And we're sure RAW doesn't include pointers?
@@ -72,9 +72,28 @@ static int perf_trace_event_perm(struct trace_event_call *tp_event,return-EINVAL;}+/*+*PERF_SAMPLE_IPonkerneltracepointsexposesakerneltext+*address,weakeningKASLR.Blockforunprivilegedusersunless+*thetracepointisauprobe(userspaceIP,safetoexpose).+*/+if((p_event->attr.sample_type&PERF_SAMPLE_IP)&&+!p_event->attr.exclude_kernel&&+!(tp_event->flags&TRACE_EVENT_FL_UPROBE)&&+sysctl_perf_event_paranoid>1&&!perfmon_capable())+return-EACCES;+/* No tracing, just counting, so no obvious leak */-if(!(p_event->attr.sample_type&PERF_SAMPLE_RAW))+if(!(p_event->attr.sample_type&PERF_SAMPLE_RAW)){+/* Prevent unprivileged users from counting kernel tracepoints */+if(!p_event->attr.exclude_kernel&&+sysctl_perf_event_paranoid>1&&!perfmon_capable()){+if(!(p_event->attach_state==PERF_ATTACH_TASK&&+(tp_event->flags&TRACE_EVENT_FL_CAP_ANY)))+return-EACCES;+}return0;+}
Maybe use less AI and try and type this yourself. I think you'll find
that repeating the same clauses over and over gets tiresome. IIRC they
invented something for that in the 60s or so :/
quoted hunk
/* Some events are ok to be traced by non-root users... */
if (p_event->attach_state == PERF_ATTACH_TASK) {
Again, you're doing the same thing in multiple places. If only there was
something to re-use a previous expression.
None of this gives me warm and fuzzy feelings.
On Mon, May 18, 2026 at 5:41 PM Peter Zijlstra [off-list ref] wrote:
Typically patches are supposed to a single thing, you're listing 4
things. What gives?
All four changes need to be made together to work properly. The second
point could be pulled out as a separate patch, but will be replaced
with the eventfs that Steve suggested. The other three points
represent a single logical change: selectively loosening the
perf_event_open() restrictions without exposing kernel data or
breaking uprobe functionality.
PERF_SAMPLE_IP should be here too, no?
If PERF_SAMPLE_IP is added to the kaddr_leak mask it blocks uprobes,
so the PERF_SAMPLE_IP check is in the trace_event_perf.c changes where
I can exempt uprobes:
+ if ((p_event->attr.sample_type & PERF_SAMPLE_IP) &&
+ !p_event->attr.exclude_kernel &&
+ !(tp_event->flags & TRACE_EVENT_FL_UPROBE) &&
+ sysctl_perf_event_paranoid > 1 && !perfmon_capable())
+ return -EACCES;
And I'm not sure if tracepoints can trigger it, but PHYS_ADDR also seems
something we shouldn't allow.
There's a check for unprivileged access to PHYS_ADDR at core.c:13917
so I didn't add it to kaddr_leak.
And we're sure RAW doesn't include pointers
PERF_SAMPLE_RAW for TRACE_EVENT_FL_CAP_ANY tracepoints doesn't include
kernel pointers.
Again, you're doing the same thing in multiple places. If only there was
something to re-use a previous expression.
None of this gives me warm and fuzzy feelings.
You're right. I'll factor the checks out for the next version.
Anubhav