All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Nickolai Zeldovich <nickolai@csail.mit.edu>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Christian Brauner <brauner@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] signal: fix endless loop in complete_signal() during a non-leader exec
Date: Thu, 29 Oct 2026 13:28:41 +0100	[thread overview]
Message-ID: <auM7-dpXdaNZQFFc@redhat.com> (raw)
In-Reply-To: <CADGQE7EusFrrSoBnhXhdE20tZJrp1EDe=2623mS8vEMY9hn53A@mail.gmail.com>

On 10/28, Nickolai Zeldovich wrote:
>
> On Wed, Oct 28, 2026 at 10:29 AM Oleg Nesterov <oleg@redhat.com> wrote:
> >
> > I think we should fix (and simplify) next_thread() instead. How about
> >
> >         --- a/include/linux/sched/signal.h
> >         +++ b/include/linux/sched/signal.h
> >         @@ -764,7 +764,7 @@ static inline struct task_struct *__next_thread(struct task_struct *p)
> >
> >          static inline struct task_struct *next_thread(struct task_struct *p)
> >          {
> >         -       return __next_thread(p) ?: p->group_leader;
> >         +       return list_next_entry_circular(p, &p->thread_node, thread_node);
> >          }
> >
> > ?
>
> This seems plausible (presumably with &p->signal->thread_head as the
> head),

Yes sure, I obviously meant head == &p->signal->thread_head ;)

> One thing that would break is cgroup_attach_task() and
> cgroup_migrate(): they call while_each_thread() while holding
> css_set_lock but not tasklist_lock or siglock.  If cgroup.procs is
> written with the pid of a zombie leader that its parent meanwhile
> reaps, the walk starts at a task that is already off thread_head,
> which is now empty, and next_thread() returns the list head as a task.

Yes, thanks...

> or convert the cgroup walks to for_each_thread().

(perhaps this makes sense regardless, but we should not delay your fix)

> Also, since check_unsafe_exec() walks under rcu_read_lock() alone,
> should next_thread() keep a single READ_ONCE() of ->next, as
> __next_thread() does, instead of list_next_entry_circular()'s two
> plain loads?

IOW, we need list_next_entry_circular_rcu() we do not have yet.

Thanks Nickolai, I am starting to agree with your fix, we can do cleanups
later.


But, unless I missed something again, complete_signal() can safely use
list_next_entry_circular(). And to me

		while (!wants_signal(sig, t)) {
			t = list_next_entry_circular(t, ...);

certainly looks more simple/clean than __next_thread() + list_first_entry().

If you agree and see nothing wrong, can you send V2 please?

Oleg.


  reply	other threads:[~2026-10-29 12:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27  2:50 [PATCH v1] signal: fix endless loop in complete_signal() during a non-leader exec Nickolai Zeldovich
2026-10-27 11:17 ` Oleg Nesterov
2026-10-28 14:29 ` Oleg Nesterov
2026-10-28 17:46   ` Nickolai Zeldovich
2026-10-29 12:28     ` Oleg Nesterov [this message]
2026-10-30 16:29       ` Christian Brauner
2026-10-31 13:46         ` [PATCH] signal: fix lockup in complete_signal() racing with mt exec Oleg Nesterov
2026-10-31 15:37           ` Nickolai Zeldovich

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=auM7-dpXdaNZQFFc@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nickolai@csail.mit.edu \
    --cc=tglx@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.