From nobody Mon Jun 15 06:28:11 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFD7D26ED33 for ; Wed, 8 Apr 2026 12:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775652105; cv=none; b=mbfiacuHJV619yZseli39C5qRUPtjL8D2xa0MkfjPf2cBkTacZQLBdvAkt3fqJpt29+8vjKghmSQKdAV/6VGINSETWnz7egLEwciE/sSd16DApFptGjjYgp7lQ/YHHN7ARupq6CQgvJffU9Vtm0PxvCN1h/IKcd8HINAC1mkEcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775652105; c=relaxed/simple; bh=Iwt4Tb6hOZuRBYvyF+IF0ofToj5rdqJvUvflMnV6VU0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=TSwEtGclPj5M13OKyqNsF6artskwMro1dAP0iw9lERI91C2+l5ZbHhYGLwytgf2cvpqTVDXYjgJGNNV393WtCFsA6AiLGNIyRrxstHPIgs5k1QIUfG0xdtA5YU5hF2UnOryY65bKHQxeH3waxXiA0LJm1E7GMFRgB7Wsl5wYRu4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NJQXLb+Q; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NJQXLb+Q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775652102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fmfA0Hm9tvRCD5nJvyEjImPcNYwXbm+DPWKpmcQx18A=; b=NJQXLb+Q2b1GQoVraLxAJvxeTBmrnO9mjY/twJhuE+1/mGUBwL57rMqu1+pH3HjGz6USUh bErRps7xCya0XajnLzW/ohnfk1TZ20TeNH3ULuvu6s9jH3s8KDQ2r02o8akI9H+7KkDj77 AwhZLhrYphnrgYKBHuQdi4MuV3w5rTs= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-30-13Naxm8CPQSPorcNcMyAHw-1; Wed, 08 Apr 2026 08:41:37 -0400 X-MC-Unique: 13Naxm8CPQSPorcNcMyAHw-1 X-Mimecast-MFC-AGG-ID: 13Naxm8CPQSPorcNcMyAHw_1775652095 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 34C4119560A7; Wed, 8 Apr 2026 12:41:34 +0000 (UTC) Received: from ashelat-thinkpadp1gen5.boston.csb (unknown [10.74.80.247]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8E59C300019F; Wed, 8 Apr 2026 12:41:25 +0000 (UTC) From: Anubhav Shelat To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Anubhav Shelat Subject: [PATCH] perf: enable unprivileged syscall tracing with perf trace Date: Wed, 8 Apr 2026 08:39:47 -0400 Message-ID: <20260408123947.23779-2-ashelat@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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 =E2=89=A4 1 ev= en 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 priviliges for all events with exclude_kernel=3D0. This allows perf_event_open() to bypass the paranoid check for task-attached tracepoint events. 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. 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 --- kernel/events/core.c | 2 +- kernel/trace/trace_events.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 89b40e439717..71d99ea4bea4 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -13833,7 +13833,7 @@ SYSCALL_DEFINE5(perf_event_open, if (err) return err; =20 - if (!attr.exclude_kernel) { + if (!attr.exclude_kernel && !(attr.type =3D=3D PERF_TYPE_TRACEPOINT && pi= d !=3D -1)) { err =3D perf_allow_kernel(); if (err) return err; diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 249d1cba72c0..6250b2529376 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -3051,7 +3051,9 @@ static int event_callback(const char *name, umode_t *= mode, void **data, struct trace_event_call *call =3D file->event_call; =20 if (strcmp(name, "format") =3D=3D 0) { - *mode =3D TRACE_MODE_READ; + *mode =3D (call->flags & TRACE_EVENT_FL_CAP_ANY) ? + (TRACE_MODE_READ | 0004) : + TRACE_MODE_READ; *fops =3D &ftrace_event_format_fops; return 1; } @@ -3087,7 +3089,9 @@ static int event_callback(const char *name, umode_t *= mode, void **data, #ifdef CONFIG_PERF_EVENTS if (call->event.type && call->class->reg && strcmp(name, "id") =3D=3D 0) { - *mode =3D TRACE_MODE_READ; + *mode =3D (call->flags & TRACE_EVENT_FL_CAP_ANY) ? + (TRACE_MODE_READ | 0004) : + TRACE_MODE_READ; *data =3D (void *)(long)call->event.type; *fops =3D &ftrace_event_id_fops; return 1; --=20 2.53.0