mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: David Laight <david.laight.linux@gmail.com>,
	Mingyu Wang <25181214217@stu.xidian.edu.cn>
Cc: Babanpreet Singh <bbnpreetsingh@gmail.com>,
	Christian Brauner <brauner@kernel.org>,
	Pavel Tikhomirov <ptikhomirov@virtuozzo.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	syzbot+c382ee653fd70f5cf1bb@syzkaller.appspotmail.com
Subject: Re: [PATCH] pid: use READ_ONCE() in pid_alive()
Date: Sun, 4 Oct 2026 13:11:43 +0200	[thread overview]
Message-ID: <asI0b1_kZ7lei1kx@redhat.com> (raw)
In-Reply-To: <asIwpkNr9bF6gk6Q@redhat.com>

Hmm. grep finds send_sigio() and send_sigurg() which use do_each_pid_task()
without tasklist.

00633c4683828acd ("fs/fcntl: fix SOFTIRQ-unsafe lock order in fasync signaling")
is wrong.

I'll send email in reply to that patch, I wasn't CC'ed...

Oleg.

On 10/04, Oleg Nesterov wrote:
>
> On 10/03, David Laight wrote:
> >
> > On Fri,  2 Oct 2026 01:21:41 +0000
> > Babanpreet Singh <bbnpreetsingh@gmail.com> wrote:
> >
> > > KCSAN reports pid_alive() reading task->thread_pid while it gets cleared
> > > under tasklist_lock. The check only cares about NULL, so READ_ONCE() and
> > > WRITE_ONCE() are enough.
> >
> > I just looked at change_pid() - isn't it completely broken?
>
> No, but...
>
> > __change_pid() uses hlist_del_rcu() to remove the item from a list.
> > IIUC this leaves the 'next' pointer valid to allow for concurrent readers.
> > I thought that had to stay valid until the end of the rcu period.
> > But the following attach_pid() adds the item to another list.
>
> Yep. That is why do_each_pid_task() needs tasklist_lock.
>
> This is the known fact, let me quote the part of my old email
> https://lore.kernel.org/all/20200512150936.GA28621@redhat.com/
>
> 	> Currently the tasklist_lock is shared mainly in order to observe
> 	> the list atomically for the PRIO_PGRP and PRIO_USER cases, as
> 	> the actual lookups are already rcu-safe,
>
> 	not really...
>
> 	do_each_pid_task(PIDTYPE_PGID) can race with change_pid(PIDTYPE_PGID)
> 	which moves the task from one hlist to another. Yes, it is safe in
> 	that task_struct can't go away. But still this is not right because
> 	do_each_pid_task() can scan the wrong (2nd) hlist.
>
> Somehow I thought this was documented, but it isn't. And this is not obvious.
> I think this deserves a comment above do_each_pid_task(), will send the patch.
>
> Oleg.


  reply	other threads:[~2026-10-04 11:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02  1:21 Babanpreet Singh
2026-10-02  6:33 ` Bradley Morgan
2026-10-02 11:59 ` Oleg Nesterov
2026-10-03 17:22 ` David Laight
2026-10-04 10:55   ` Oleg Nesterov
2026-10-04 11:11     ` Oleg Nesterov [this message]
2026-10-04 11:51     ` David Laight
2026-10-04 13:14       ` Oleg Nesterov
2026-10-04 13:31         ` David Laight

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=asI0b1_kZ7lei1kx@redhat.com \
    --to=oleg@redhat.com \
    --cc=25181214217@stu.xidian.edu.cn \
    --cc=akpm@linux-foundation.org \
    --cc=bbnpreetsingh@gmail.com \
    --cc=brauner@kernel.org \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=syzbot+c382ee653fd70f5cf1bb@syzkaller.appspotmail.com \
    /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

all inboxes | Powered by JetHome®