Re: [PATCH v6 0/3] Harden spectrev2 userspace-userspace protection

From: Peter Zijlstra
Date: Sat Sep 22 2018 - 10:38:41 EST


On Sat, Sep 22, 2018 at 03:30:07PM +0200, Thomas Gleixner wrote:
> On Sat, 22 Sep 2018, Thomas Gleixner wrote:
> > On Sat, 22 Sep 2018, Peter Zijlstra wrote:
> > > This has some unfortunate duplication.
> > >
> > > Lets go with it for now, but I'll see if I can do something about that
> > > later.
> >
> > Yes, I know. I tried to make the duplication smaller, but all attempts
> > ended up being a convoluted mess. I'll try again after applying more
> > coffee.
>
> Lunch and coffee indeed made brain work better. The simple solution was way
> too obvious.
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c
> @@ -261,6 +261,9 @@ static int ptrace_check_attach(struct ta
>
> static int ptrace_has_cap(struct user_namespace *ns, unsigned int mode)
> {
> + if (mode & PTRACE_MODE_SCHED)
> + return false;
> +
> if (mode & PTRACE_MODE_NOAUDIT)
> return has_ns_capability_noaudit(current, ns, CAP_SYS_PTRACE);
> else
> @@ -328,9 +331,16 @@ static int __ptrace_may_access(struct ta
> !ptrace_has_cap(mm->user_ns, mode)))
> return -EPERM;
>
> + if (mode & PTRACE_MODE_SCHED)
> + return 0;
> return security_ptrace_access_check(task, mode);
> }
>
> +bool ptrace_may_access_sched(struct task_struct *task, unsigned int mode)
> +{
> + return __ptrace_may_access(task, mode | PTRACE_MODE_SCHED);
> +}

Ha!, much nicer. Thanks!