[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CANpmjNPwtmRbj3zRTWS9hL0wawuSQV_2SL0fvnb5e0J43MaNag@mail.gmail.com>
Date: Thu, 8 Sep 2022 09:58:42 +0200
From: Marco Elver <elver@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
kasan-dev@...glegroups.com, Dmitry Vyukov <dvyukov@...gle.com>,
Jann Horn <jannh@...gle.com>,
Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH] perf: Allow restricted kernel breakpoints on user addresses
On Wed, 7 Sept 2022 at 14:39, Peter Zijlstra <peterz@...radead.org> wrote:
>
> On Fri, Sep 02, 2022 at 12:00:57PM +0200, Marco Elver wrote:
>
> > +/*
> > + * Check if unprivileged users are allowed to set up breakpoints on user
> > + * addresses that also count when the kernel accesses them.
> > + */
> > +static bool perf_allow_kernel_breakpoint(struct perf_event_attr *attr)
> > +{
> > + if (attr->type != PERF_TYPE_BREAKPOINT)
> > + return false;
> > +
> > + /*
> > + * The sample may contain IPs, registers, or other information that may
> > + * disclose kernel addresses or timing information. Disallow any kind of
> > + * additional sample information.
> > + */
> > + if (attr->sample_type)
> > + return false;
>
> This feels a bit weird; should that perhaps be is_sampling_event()?
is_sampling_event() just checks for sample_period. In fact, we still
want to set sample_period to get overflow events. That in itself is
not dangerous.
What's problematic is if the samples contain additional information,
which can be specified in sample_type. For example if PERF_SAMPLE_IP
is set, it might leak kernel IPs, and that's bad. Since it's safest to
disallow any kind of extra information, we just check if sample_type
is zero.
> > +
> > + /*
> > + * Only allow kernel breakpoints on user addresses.
> > + */
> > + return access_ok((void __user *)(unsigned long)attr->bp_addr, attr->bp_len);
> > +}
> > +
> > +int perf_allow_kernel(struct perf_event_attr *attr)
> > +{
> > + if (sysctl_perf_event_paranoid > 1 && !perfmon_capable() &&
> > + !perf_allow_kernel_breakpoint(attr))
>
> I'm on the fence about this; one the one hand it feels weird to have a
> breakpoint exception here and not a pmu specific callback for instance;
> OTOH, leaving security policy like that up to pmu drivers sounds like a
> really bad idea too.
>
> Keep it as is I suppose, just me thinking out loud or so.
Ack. I also think this should stay in core, as it's also easier to audit.
Powered by blists - more mailing lists