The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Jiayuan Chen <jiayuan.chen@linux.dev>
Cc: linux-kernel@vger.kernel.org, mrpre@163.com, mkoutny@suse.com,
	syzbot+adcaa842b762a1762e7d@syzkaller.appspotmail.com,
	syzbot+fab52e3459fa2f95df57@syzkaller.appspotmail.com,
	syzbot+0718f65353d72efaac1e@syzkaller.appspotmail.com,
	Andrew Morton <akpm@linux-foundation.org>,
	Christian Brauner <brauner@kernel.org>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	"Liam R. Howlett" <Liam.Howlett@Oracle.com>,
	Suren Baghdasaryan <surenb@google.com>,
	Wei Yang <richard.weiyang@gmail.com>,
	David Hildenbrand <david@redhat.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Mateusz Guzik <mjguzik@gmail.com>,
	Joel Granados <joel.granados@kernel.org>,
	Bill O'Donnell <bodonnel@redhat.com>,
	"Darrick J. Wong" <djwong@kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>
Subject: Re: [PATCH v2] pid: annotate data-races around pid_ns->pid_allocated
Date: Fri, 25 Apr 2025 12:07:07 +0200	[thread overview]
Message-ID: <20250425100707.GA8093@redhat.com> (raw)
In-Reply-To: <20250425055824.6930-1-jiayuan.chen@linux.dev>

On 04/25, Jiayuan Chen wrote:
>
> @@ -2584,7 +2584,7 @@ __latent_entropy struct task_struct *copy_process(
>  	rseq_fork(p, clone_flags);
>
>  	/* Don't start children in a dying pid namespace */
> -	if (unlikely(!(ns_of_pid(pid)->pid_allocated & PIDNS_ADDING))) {
> +	if (unlikely(!(data_race(ns_of_pid(pid)->pid_allocated & PIDNS_ADDING)))) {

Well. data_race() just hides the potential problem. READ_ONCE() makes more
sense imo, even if I think there are no real problems with the current code.

Either way,

> @@ -271,13 +271,13 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
>  	upid = pid->numbers + ns->level;
>  	idr_preload(GFP_KERNEL);
>  	spin_lock(&pidmap_lock);
> -	if (!(ns->pid_allocated & PIDNS_ADDING))
> +	if (!(data_race(ns->pid_allocated & PIDNS_ADDING)))

again, you do not need data_race() or READ_ONCE() if you read the
data protected by pidmap_lock. But you still need WRITE_ONCE() when
->pid_allocated is modified.

Oleg.


      parent reply	other threads:[~2025-04-25 10:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-25  5:58 [PATCH v2] pid: annotate data-races around pid_ns->pid_allocated Jiayuan Chen
2025-04-25  9:25 ` Michal Koutný
2025-04-28  8:30   ` Jiayuan Chen
2025-04-25 10:07 ` Oleg Nesterov [this message]

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=20250425100707.GA8093@redhat.com \
    --to=oleg@redhat.com \
    --cc=Liam.Howlett@Oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=bodonnel@redhat.com \
    --cc=brauner@kernel.org \
    --cc=david@redhat.com \
    --cc=djwong@kernel.org \
    --cc=frederic@kernel.org \
    --cc=jiayuan.chen@linux.dev \
    --cc=joel.granados@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mjguzik@gmail.com \
    --cc=mkoutny@suse.com \
    --cc=mrpre@163.com \
    --cc=richard.weiyang@gmail.com \
    --cc=surenb@google.com \
    --cc=syzbot+0718f65353d72efaac1e@syzkaller.appspotmail.com \
    --cc=syzbot+adcaa842b762a1762e7d@syzkaller.appspotmail.com \
    --cc=syzbot+fab52e3459fa2f95df57@syzkaller.appspotmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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