All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>, Jann Horn <jannh@google.com>
Cc: "Hyunwoo Kim" <imv4bel@gmail.com>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"André Almeida" <andrealmeid@igalia.com>,
	"kernel list" <linux-kernel@vger.kernel.org>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>
Subject: Re: [BUG] futex: scheduling-while-atomic because nested vfork can break guard(private_hash)
Date: Fri, 11 Sep 2026 13:51:32 +0200	[thread overview]
Message-ID: <87cxukypiz.ffs@fw13> (raw)
In-Reply-To: <20260911090447.GT788244@noisy.programming.kicks-ass.net>

On Fri, Sep 11 2026 at 11:04, Peter Zijlstra wrote:

CC: +bigeasy

> On Fri, Sep 11, 2026 at 10:36:39AM +0200, Peter Zijlstra wrote:
>> On Thu, Sep 10, 2026 at 05:27:54PM +0200, Jann Horn wrote:
>
>> > Impact, related issues
>> > ==========
>> > futex_wait_multiple_setup() follows the same pattern of using
>> > guard(private_hash)(current->mm) to ensure that a later CLASS(hbr,
>> > hbr)(&q->key) won't sleep and is probably affected by the same issue.
>> > 
>> > __futex_unlock_pi() and requeue_pi_wake_futex() also use
>> > futex_private_hash(), but there the race seems benign.
>> > 
>> > This issue also means that different futex users could disagree about
>> > the hash bucket that a private futex belongs in (older futex_hash()
>> > calls returning a pointer into the global hash, newer futex_hash()
>> > calls returning a pointer into the private hash).
>> 
>> Right, that transition is not supposed to be possible. Notably a single
>> thread cannot have (private) futex waiters, and we allocate the private
>> hash on cloning the second thread.
>> 
>> > Sidenote
>> > ========
>> > Maybe we should block CLONE_VFORK when current->vfork_done!=NULL ? It
>> > is clearly bad to allow nested vfork() such that a SIGKILL can cause
>> > two threads to run concurrently on the same userspace stack.
>> > 
>> > But I'm not sure if that's a good fix for these futex issues - a fix
>> > that doesn't rely on such distant assumptions might be nicer...
>> 
>> So need_futex_hash_allocate_default() is explicitly excluding vfork from
>> causing a private hash to be allocated. Perhaps we should fix that.
>> 
>> I need more thinking (and wake-up juice) to see if that might perhaps
>> bring other problems with it.
>
> So I can confirm that the below does in fact cure your testcase.
>
> Per commit: ee9dce44362b ("futex: Drop CLONE_THREAD requirement for private default hash alloc")
> the reason for excluding vfork() was performance and thinking this
> would/could not matter, which you've proven to be clearly false.
>
> Thomas?

I don't remember why we excluded VFORK in the first place. Sebastian?

> ---
>  kernel/fork.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 416758c8a3d4..bc32ea19099e 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1996,9 +1996,9 @@ static bool need_futex_hash_allocate_default(u64 clone_flags)
>  {
>  	/*
>  	 * Allocate a default futex hash for any sibling that will
> -	 * share the parent's mm, except vfork.
> +	 * share the parent's mm.
>  	 */
> -	return (clone_flags & (CLONE_VM | CLONE_VFORK)) == CLONE_VM;
> +	return clone_flags & CLONE_VM;
>  }
>  
>  /*

  reply	other threads:[~2026-09-11 11:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 15:27 [BUG] futex: scheduling-while-atomic because nested vfork can break guard(private_hash) Jann Horn
2026-09-11  8:36 ` Peter Zijlstra
2026-09-11  9:04   ` Peter Zijlstra
2026-09-11 11:51     ` Thomas Gleixner [this message]
2026-09-11 15:28       ` Jann Horn
2026-09-11 17:51         ` Davidlohr Bueso
2026-09-15 11:06     ` Sebastian Andrzej Siewior
2026-09-15 11:37       ` Peter Zijlstra
2026-09-16 12:23     ` [tip: locking/urgent] futex: Also allocate private hash on vfork() tip-bot2 for Peter Zijlstra
2026-09-11 15:31   ` [BUG] futex: scheduling-while-atomic because nested vfork can break guard(private_hash) Jann Horn

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=87cxukypiz.ffs@fw13 \
    --to=tglx@kernel.org \
    --cc=andrealmeid@igalia.com \
    --cc=bigeasy@linutronix.de \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=imv4bel@gmail.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.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.