public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Josh Hunt <johunt@akamai.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] psi: allow unprivileged users with CAP_SYS_RESOURCE to write psi files
Date: Wed, 31 Mar 2021 23:36:28 -0500	[thread overview]
Message-ID: <m15z16r583.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <20210401033156.7262-1-johunt@akamai.com> (Josh Hunt's message of "Wed, 31 Mar 2021 23:31:56 -0400")

Josh Hunt <johunt@akamai.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.

Eric


> Signed-off-by: Josh Hunt <johunt@akamai.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;
>  }

  reply	other threads:[~2021-04-01  4:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01  3:31 [PATCH] psi: allow unprivileged users with CAP_SYS_RESOURCE to write psi files Josh Hunt
2021-04-01  4:36 ` Eric W. Biederman [this message]
2021-04-01  7:50   ` Kees Cook
2021-04-01 17:47     ` Eric W. Biederman
2021-04-01 18:10       ` Josh Hunt
2021-04-01  6:47 ` Peter Zijlstra
2021-04-01 19:47   ` Johannes Weiner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m15z16r583.fsf@fess.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=johunt@akamai.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox