Linux Perf Users
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Dominik Maier <dmnk@google.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	linux-perf-users@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org, dmnk+artist@google.com
Subject: Re: [PATCH v2] perf/core: check perf_allow_kernel() in PERF_EVENT_IOC_SET_FILTER
Date: Thu, 26 Nov 2026 16:40:41 +0100	[thread overview]
Message-ID: <20261126154041.GJ49833@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20261124180611.75836-1-dmnk@google.com>

On Tue, Nov 24, 2026 at 06:06:11PM +0000, Dominik Maier wrote:
> Under perf_event_paranoid = 2, an unprivileged caller can open a
> task-scoped counting trace event (including tracepoints and tracefs
> uprobes) with attr.exclude_kernel = 1 and attach trace event filters via
> PERF_EVENT_IOC_SET_FILTER without passing perf_allow_kernel(). Trace
> event filter predicates are parsed by create_filter() and support kernel
> symbol and address matching (such as the .function modifier), exposing
> kernel address information to callers that are not allowed kernel
> profiling.
> 
> Require perf_allow_kernel() before applying trace event filters in
> perf_event_set_filter().
> 
> Suggested-by: Steven Rostedt <rostedt@goodmis.org>
> Signed-off-by: Dominik Maier <dmnk@google.com>
> ---
> v2:
> - Gate trace event filtering in perf_event_set_filter() with
>   perf_allow_kernel() instead of only checking kallsyms_show_value() on
>   numeric .function predicates in trace_events_filter.c (Steven Rostedt).
> - v1: https://lore.kernel.org/linux-trace-kernel/20261119192233.2664654-1-dmnk@google.com/
> 
> Found with AI-assisted code review; tested in QEMU across root and
> unprivileged callers at perf_event_paranoid = 1 and 2, and build-tested
> with CONFIG_EVENT_TRACING both enabled and disabled.

Does this want a Fixes tag? Or should I stick this in perf/core for the
next cycle?

>  kernel/events/core.c | 36 +++++++++++++++++++++---------------
>  1 file changed, 21 insertions(+), 15 deletions(-)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index e870f12c3ad8..e053de4c164c 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -12371,22 +12371,28 @@ static int perf_event_set_filter(struct perf_event *event, void __user *arg)
>  
>  #ifdef CONFIG_EVENT_TRACING
>  	if (perf_event_is_tracing(event)) {
> -		struct perf_event_context *ctx = event->ctx;
> +		ret = perf_allow_kernel();
> +		if (!ret) {
> +			struct perf_event_context *ctx = event->ctx;
>  
> -		/*
> -		 * Beware, here be dragons!!
> -		 *
> -		 * the tracepoint muck will deadlock against ctx->mutex, but
> -		 * the tracepoint stuff does not actually need it. So
> -		 * temporarily drop ctx->mutex. As per perf_event_ctx_lock() we
> -		 * already have a reference on ctx.
> -		 *
> -		 * This can result in event getting moved to a different ctx,
> -		 * but that does not affect the tracepoint state.
> -		 */
> -		mutex_unlock(&ctx->mutex);
> -		ret = ftrace_profile_set_filter(event, event->attr.config, filter_str);
> -		mutex_lock(&ctx->mutex);
> +			/*
> +			 * Beware, here be dragons!!
> +			 *
> +			 * the tracepoint muck will deadlock against ctx->mutex,
> +			 * but the tracepoint stuff does not actually need it.
> +			 * So temporarily drop ctx->mutex. As per
> +			 * perf_event_ctx_lock() we already have a reference on
> +			 * ctx.
> +			 *
> +			 * This can result in event getting moved to a different
> +			 * ctx, but that does not affect the tracepoint state.
> +			 */
> +			mutex_unlock(&ctx->mutex);
> +			ret = ftrace_profile_set_filter(event,
> +							event->attr.config,
> +							filter_str);
> +			mutex_lock(&ctx->mutex);
> +		}
>  	} else
>  #endif
>  	if (has_addr_filter(event))
> -- 
> 2.56.1.831.g720f3f5937-goog
> 

      parent reply	other threads:[~2026-11-26 15:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 18:06 [PATCH v2] perf/core: check perf_allow_kernel() in PERF_EVENT_IOC_SET_FILTER Dominik Maier
2026-11-24 18:11 ` sashiko-bot
2026-11-26 15:40 ` Peter Zijlstra [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126154041.GJ49833@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=dmnk+artist@google.com \
    --cc=dmnk@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox