[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202104010039.A134EC56@keescook>
Date: Thu, 1 Apr 2021 00:50:57 -0700
From: Kees Cook <keescook@...omium.org>
To: "Eric W. Biederman" <ebiederm@...ssion.com>
Cc: Josh Hunt <johunt@...mai.com>, Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] psi: allow unprivileged users with CAP_SYS_RESOURCE to
write psi files
On Wed, Mar 31, 2021 at 11:36:28PM -0500, Eric W. Biederman wrote:
> Josh Hunt <johunt@...mai.com> writes:
>
> > Currently only root can write files under /proc/pressure. Relax this to
> > allow tasks running as unprivileged users with CAP_SYS_RESOURCE to be
> > able to write to these files.
>
> The test for CAP_SYS_RESOURCE really needs to be in open rather
> than in write.
>
> Otherwise a suid root executable could have stdout redirected
> into these files.
Right. Or check against f_cred. (See uses of kallsyms_show_value())
https://www.kernel.org/doc/html/latest/security/credentials.html#open-file-credentials
-Kees
>
> Eric
>
>
> > Signed-off-by: Josh Hunt <johunt@...mai.com>
> > ---
> > kernel/sched/psi.c | 9 ++++++---
> > 1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> > index b1b00e9bd7ed..98ff7baf1ba8 100644
> > --- a/kernel/sched/psi.c
> > +++ b/kernel/sched/psi.c
> > @@ -1270,6 +1270,9 @@ static ssize_t psi_write(struct file *file, const char __user *user_buf,
> > if (!nbytes)
> > return -EINVAL;
> >
> > + if (!capable(CAP_SYS_RESOURCE))
> > + return -EPERM;
> > +
> > buf_size = min(nbytes, sizeof(buf));
> > if (copy_from_user(buf, user_buf, buf_size))
> > return -EFAULT;
> > @@ -1353,9 +1356,9 @@ static int __init psi_proc_init(void)
> > {
> > if (psi_enable) {
> > proc_mkdir("pressure", NULL);
> > - proc_create("pressure/io", 0, NULL, &psi_io_proc_ops);
> > - proc_create("pressure/memory", 0, NULL, &psi_memory_proc_ops);
> > - proc_create("pressure/cpu", 0, NULL, &psi_cpu_proc_ops);
> > + proc_create("pressure/io", 0666, NULL, &psi_io_proc_ops);
> > + proc_create("pressure/memory", 0666, NULL, &psi_memory_proc_ops);
> > + proc_create("pressure/cpu", 0666, NULL, &psi_cpu_proc_ops);
> > }
> > return 0;
> > }
--
Kees Cook
Powered by blists - more mailing lists