linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: hannes@cmpxchg.org, torvalds@linux-foundation.org, tj@kernel.org,
	lizefan.x@bytedance.com, mingo@redhat.com, peterz@infradead.org,
	juri.lelli@redhat.com, vincent.guittot@linaro.org,
	dietmar.eggemann@arm.com, rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, bristot@redhat.com,
	corbet@lwn.net, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
	stable@vger.kernel.org, kernel-team@android.com,
	syzbot+cdb5dd11c97cc532efad@syzkaller.appspotmail.com
Subject: Re: [PATCH v2 1/1] psi: Fix uaf issue when psi trigger is destroyed while being polled
Date: Tue, 11 Jan 2022 10:48:42 -0800	[thread overview]
Message-ID: <Yd3RClhoz24rrU04@sol.localdomain> (raw)
In-Reply-To: <20220111071212.1210124-1-surenb@google.com>

On Mon, Jan 10, 2022 at 11:12:12PM -0800, Suren Baghdasaryan wrote:
> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> index cafb8c114a21..93b51a2104f7 100644
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -3642,6 +3642,12 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf,
>  	cgroup_get(cgrp);
>  	cgroup_kn_unlock(of->kn);
>  
> +	/* Allow only one trigger per file descriptor */
> +	if (ctx->psi.trigger) {
> +		cgroup_put(cgrp);
> +		return -EBUSY;
> +	}
> +
>  	psi = cgroup_ino(cgrp) == 1 ? &psi_system : &cgrp->psi;
>  	new = psi_trigger_create(psi, buf, nbytes, res);
>  	if (IS_ERR(new)) {
> @@ -3649,8 +3655,7 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf,
>  		return PTR_ERR(new);
>  	}
>  
> -	psi_trigger_replace(&ctx->psi.trigger, new);
> -
> +	ctx->psi.trigger = new;
>  	cgroup_put(cgrp);

The write here needs to use smp_store_release(), since it is paired with the
concurrent READ_ONCE() in psi_trigger_poll().

> @@ -1305,14 +1287,24 @@ static ssize_t psi_write(struct file *file, const char __user *user_buf,
>  
>  	buf[buf_size - 1] = '\0';
>  
> -	new = psi_trigger_create(&psi_system, buf, nbytes, res);
> -	if (IS_ERR(new))
> -		return PTR_ERR(new);
> -
>  	seq = file->private_data;
> +
>  	/* Take seq->lock to protect seq->private from concurrent writes */
>  	mutex_lock(&seq->lock);
> -	psi_trigger_replace(&seq->private, new);
> +
> +	/* Allow only one trigger per file descriptor */
> +	if (seq->private) {
> +		mutex_unlock(&seq->lock);
> +		return -EBUSY;
> +	}
> +
> +	new = psi_trigger_create(&psi_system, buf, nbytes, res);
> +	if (IS_ERR(new)) {
> +		mutex_unlock(&seq->lock);
> +		return PTR_ERR(new);
> +	}
> +
> +	seq->private = new;

Likewise here.

- Eric

  reply	other threads:[~2022-01-11 18:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11  7:12 [PATCH v2 1/1] psi: Fix uaf issue when psi trigger is destroyed while being polled Suren Baghdasaryan
2022-01-11 18:48 ` Eric Biggers [this message]
2022-01-11 19:11   ` Linus Torvalds
2022-01-11 19:26     ` Suren Baghdasaryan
2022-01-11 19:34       ` Linus Torvalds
2022-01-11 19:41     ` Eric Biggers
2022-01-11 19:45       ` Suren Baghdasaryan
2022-01-11 20:14       ` Linus Torvalds
2022-01-11 23:37         ` Suren Baghdasaryan
2022-01-12 11:06     ` Peter Zijlstra
2022-01-18  6:58     ` Herbert Xu
2022-01-12 14:37 ` 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=Yd3RClhoz24rrU04@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=cgroups@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=dietmar.eggemann@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=juri.lelli@redhat.com \
    --cc=kernel-team@android.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=syzbot+cdb5dd11c97cc532efad@syzkaller.appspotmail.com \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vincent.guittot@linaro.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;
as well as URLs for NNTP newsgroup(s).