mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Christian Brauner <brauner@kernel.org>,
	Nickolai Zeldovich <nickolai@csail.mit.edu>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@kernel.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] signal: fix lockup in complete_signal() racing with mt exec
Date: Sat, 31 Oct 2026 14:46:57 +0100	[thread overview]
Message-ID: <auXxUSMHCh4vA3yV@redhat.com> (raw)
In-Reply-To: <20261030-specht-grinsen-vererben-aedb50f4c96c@brauner>

Nickolai Zeldovich says:

    kill(2) of a process while a non-leader thread of it is in execve()
    can lock up the machine: complete_signal() loops forever with siglock
    held and interrupts off, and de_thread() then spins on siglock in
    release_task() with tasklist_lock held.

    The curr_target walk uses next_thread(), which wraps from the last
    thread to ->group_leader on the assumption that the leader is first
    on signal->thread_head. de_thread() makes the exec'ing thread, the
    last one, the leader before release_task() unlinks the old leader,
    so a walk that starts at the old leader stays on the new one if
    that thread blocks the signal, and never gets back to curr_target.

Change complete_signal() to use list_next_entry_circular() instead
of next_thread().

Other users of next_thread/while_each_thread/for_other_threads look safe,
so this patch only changes complete_signal() to make a simple fix for
-stable. However, in the longer term we should update next_thread()
or add another helper, but this needs more work; next_thread() should
work even when signal->thread_head is empty.

Fixes: d639cf4abb4d ("change next_thread() to use __next_thread() ?: group_leader")
Reported-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
Link: https://lore.kernel.org/all/CADGQE7EusFrrSoBnhXhdE20tZJrp1EDe=2623mS8vEMY9hn53A@mail.gmail.com/
Originally-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/signal.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index 2474507ac92b..bf5518be67a2 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -987,7 +987,8 @@ static void complete_signal(int sig, struct task_struct *p, enum pid_type type)
 		 */
 		t = signal->curr_target;
 		while (!wants_signal(sig, t)) {
-			t = next_thread(t);
+			t = list_next_entry_circular(t, &signal->thread_head,
+							thread_node);
 			if (t == signal->curr_target)
 				/*
 				 * No thread needs to be woken.
-- 
2.55.0



  reply	other threads:[~2026-10-31 13:47 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
2026-10-30 16:29       ` Christian Brauner
2026-10-31 13:46         ` Oleg Nesterov [this message]
2026-10-31 15:37           ` [PATCH] signal: fix lockup in complete_signal() racing with mt exec 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=auXxUSMHCh4vA3yV@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 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®