lkml.org 
[lkml]   [2022]   [Sep]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] perf: Allow restricted kernel breakpoints on user addresses
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()?

> +
> + /*
> + * 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.

> + return -EACCES;
> +
> + return security_perf_event_open(attr, PERF_SECURITY_KERNEL);
> +}


\
 
 \ /
  Last update: 2022-09-07 14:39    [W:0.070 / U:0.980 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site