[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YNxmyRYcs/R/8zry@elver.google.com>
Date: Wed, 30 Jun 2021 14:42:49 +0200
From: Marco Elver <elver@...gle.com>
To: Ondrej Mosnacek <omosnace@...hat.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...nel.org>, kasan-dev@...glegroups.com,
Linux kernel mailing list <linux-kernel@...r.kernel.org>,
"Serge E. Hallyn" <serge@...lyn.com>,
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@...hat.com>,
Namhyung Kim <namhyung@...nel.org>,
Linux Security Module list
<linux-security-module@...r.kernel.org>,
linux-perf-users@...r.kernel.org,
Eric Biederman <ebiederm@...ssion.com>,
Dmitry Vyukov <dvyukov@...gle.com>
Subject: Re: [PATCH] perf: Require CAP_KILL if sigtrap is requested
On Wed, Jun 30, 2021 at 01:13PM +0200, Ondrej Mosnacek wrote:
> On Wed, Jun 30, 2021 at 11:38 AM Marco Elver <elver@...gle.com> wrote:
[...]
> > +static inline bool kill_capable(void)
> > +{
> > + return capable(CAP_KILL) || capable(CAP_SYS_ADMIN);
>
> Is it really necessary to fall back to CAP_SYS_ADMIN here? CAP_PERFMON
> and CAP_BPF have been split off from CAP_SYS_ADMIN recently, so they
> have it for backwards compatibility. You are adding a new restriction
> for a very specific action, so I don't think the fallback is needed.
That means someone having CAP_SYS_ADMIN, but not CAP_KILL, can't perform
the desired action. Is this what you'd like?
If so, I'll just remove the wrapper, and call capable(CAP_KILL)
directly.
> > diff --git a/kernel/events/core.c b/kernel/events/core.c
> > index fe88d6eea3c2..1ab4bc867531 100644
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -12152,10 +12152,21 @@ SYSCALL_DEFINE5(perf_event_open,
> > }
> >
> > if (task) {
> > + bool is_capable;
> > +
> > err = down_read_interruptible(&task->signal->exec_update_lock);
> > if (err)
> > goto err_file;
> >
> > + is_capable = perfmon_capable();
> > + if (attr.sigtrap) {
> > + /*
> > + * perf_event_attr::sigtrap sends signals to the other
> > + * task. Require the current task to have CAP_KILL.
> > + */
> > + is_capable &= kill_capable();
>
> Is it necessary to do all this dance just to call perfmon_capable()
> first? Couldn't this be simply:
>
> err = -EPERM;
> if (attr.sigtrap && !capable(CAP_KILL))
> goto err_cred;
Not so much about perfmon_capable() but about the ptrace_may_access()
check. The condition here is supposed to be:
want CAP_PERFMON and (CAP_KILL if sigtrap)
OR
want ptrace access (which includes a check for same thread-group and uid)
If we did what you propose, then the ptrace check is effectively ignored
if attr.sigtrap, and that's not what we want.
There are lots of other ways of writing the same thing, but it should
also remain readable and sticking it all into the same condition is not
readable.
> Also, looking at kill_ok_by_cred() in kernel/signal.c, would it
> perhaps be more appropriate to do
> ns_capable(__task_cred(task)->user_ns, CAP_KILL) instead? (There might
> also need to be some careful locking around getting the target task's
> creds - I'm not sure...)
That might make sense. AFAIK, the locking is already in place via
exec_update_lock. Let me investigate.
> > + }
> > +
> > /*
> > * Preserve ptrace permission check for backwards compatibility.
> > *
> > @@ -12165,7 +12176,7 @@ SYSCALL_DEFINE5(perf_event_open,
> > * perf_event_exit_task() that could imply).
> > */
> > err = -EACCES;
>
> BTW, shouldn't this (and several other such cases in this file...)
> actually be EPERM, as is the norm for capability checks?
I'm not a perf maintainer, so I can't give you a definitive answer.
But, this would change the ABI, so I don't think it's realistic to
request this change at this point unfortunately.
Thanks.
Powered by blists - more mailing lists