From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796047871; b=o12VjtdNfl9McfC9DKEq2iJi4xCahegN6z7jbsPKAoQgMZElJjQkIfNA/PXzJlle9jYG 8ojAc//0meKTLYMwozwjbBDrIFR+FNj6JjGC3Q+R3EZ6nTEUNlwjmqyJC21wWkUaWqVS7 o7NRuJahGzXI8+DK7uF3Vr2MQkzLZAerYUOqxyaSSgZBb7hIo4ApvGuonVR2Sgywvt7kY saUnmKFpKQU5fosDvasgXj8k47jfIKHHxN3fwam94rqN95ZATxA4bCIvdGG+neS7FOHQR leUxMSXZMSBTzrQjkjZ3hdXBnvsGBaPkQoZ4kJZrZ2W2G/Y02KSxyxW/SYVjUO6+cLg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796047871; h=DMARC-Filter:Date:DKIM-Signature:DKIM-Signature:From:Sender:Reply-to: To:Subject:Cc:In-Reply-To:References:MIME-Version:Message-ID:Robot-ID: Robot-Unsubscribe:Precedence:Content-Type:Content-Transfer-Encoding; bh=GAq7SQQsNo6G6KQWkWISwaI0eDA7msAou1Sd2KcA5Q0=; b=BC6ws4imNuONcBrJyTLT+blXVgCujLzexSLGLgiY2LOV7MAKlErD1AGQyaXYDI+FrkSp xTHBghLsIG1Pa8s5X0S/+N29iaCAAPbQ902KNytMP6F/xIRD4Hu11FOp8gbNgTqF0UIUQ 21yJprMj2xlph27AvIi7XkkQKiwlx90L6l6mmFu2ONTf8R+hADjmf66ZZ/OvfTO9svqu0 1/kENRBX/I5gXL9pcE4/D6aDL/pXL5hM6h8sP5Xx7tKdOd4849PnUWnzQI5a1i4DzuTqW aZNxIR3pAktnAK5v5jHk5OirwQUqEW1ZLrjA/hs7ULKE0iIwyOII6U5eBc2J19UAQZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=t7rmAaQy; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b="FJOL/STh"; arc=none smtp.remote-ip=193.142.43.55 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9A91606A31C; Mon, 30 Nov 2026 14:11:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C9A91606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=t7rmAaQy; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=FJOL/STh Date: Mon, 30 Nov 2026 14:11:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1796047863; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GAq7SQQsNo6G6KQWkWISwaI0eDA7msAou1Sd2KcA5Q0=; b=t7rmAaQyhjBICgHRFsST/FP6amyIMldesr5RzTdCgtn+r4xD6W5UwiqG8yJNqNuwn77F3p kxrkWtjbbwPe5DcqlMcJyEyvfC06WZ2XBdPjN8R9jElcoAFKQbjSQJvB+Y3uyX5qq2Cejk mQR5aclAb7o9YcaTozT5FSfwtSXahnG045pncvKbMRPjToOYR7MNo+HGDRYlNbvuljO07y kZc8EtGw58WFqvLiFUp8tVQ52k341T9E8Wb9zxOFXmB1DF22zGH4rwYN5nJ+jJK3PnH4hy L4qEFAqPTzXxwJmeS4BRFOOTF8hZCeiqaxrxZUp6+nhDhft1ISUAJCo2pwFi1Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1796047863; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GAq7SQQsNo6G6KQWkWISwaI0eDA7msAou1Sd2KcA5Q0=; b=FJOL/SThRN9RHymXl9jBp5Po05Acb/31TXjTdWmMTkWGuJi4p4fSF8Gsl6rpFnqIHiSb0c 9LT+x7aAIDIoelDg== From: "tip-bot2 for Jiwoo Kim" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/urgent] futex: Don't check lock_ptr of an unqueued requeue-PI waiter Cc: Jiwoo Kim , Thomas Gleixner , stable@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20261117152428.1477-1-arpe1618@gmail.com> References: <20261117152428.1477-1-arpe1618@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-ID: <179604786129.1190409.2821351370808451003.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the locking/urgent branch of tip: Commit-ID: 8c85b034ff02a8fa6ec0111c68a049e992ca29ef Gitweb: https://git.kernel.org/tip/8c85b034ff02a8fa6ec0111c68a049e992c= a29ef Author: Jiwoo Kim AuthorDate: Wed, 18 Nov 2026 00:24:28 +09:00 Committer: Thomas Gleixner CommitterDate: Mon, 30 Nov 2026 15:07:33 +01:00 futex: Don't check lock_ptr of an unqueued requeue-PI waiter Since commit bc7304f3ae20 ("futex: Prevent lockup in requeue-PI during signal/ timeout wakeup"), futex_proxy_trylock_atomic() unqueues a top waiter in Q_REQUEUE_PI_IGNORE state from hb1 itself, and handle_early_requeue_pi_wakeup() only unqueues the futex_q when it is still queued. A futex_q unqueued this way keeps q->lock_ptr pointing to the lock of its hash bucket. futex_rehash_private() only moves futex_qs which are on a hash bucket chain, so a resize of the private hash before the waiter gets to handle_early_requeue_pi_wakeup() leaves q->lock_ptr pointing into the old hash: Task A (waiter) Task B (requeue), Task C (resize) futex_wait_requeue_pi() times out, requeue_state =3D Q_REQUEUE_PI_IGNORE B: futex_proxy_trylock_atomic() unqueues A from hb1 C: futex_rehash_private() does not move A locks its hash bucket in the new hash handle_early_requeue_pi_wakeup() WARN_ON_ONCE(&hb->lock !=3D q->lock_ptr) The warning triggers, although the futex_q is not queued anymore and q->lock_ptr is not used. Besides PR_FUTEX_HASH_SET_SLOTS, the private hash is also resized when threads are created, see futex_hash_allocate_default(). This was observed as an unprivileged user in a QEMU guest, with threads of one process doing FUTEX_WAIT_REQUEUE_PI with short timeouts, FUTEX_CMP_REQUEUE_PI and PR_FUTEX_HASH_SET_SLOTS at the same time: WARNING: kernel/futex/requeue.c:734 at futex_wait_requeue_pi+0x67a/0x6f0 It did not trigger with the requeue or the resize left out. Only check q->lock_ptr while the futex_q is queued. This was found with an AI coding assistant, which also drafted this patch and its changelog. The problem was reproduced in a QEMU guest, and the fix was tested there. Fixes: bc7304f3ae20 ("futex: Prevent lockup in requeue-PI during signal/ time= out wakeup") Signed-off-by: Jiwoo Kim Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261117152428.1477-1-arpe1618@gmail.com --- kernel/futex/requeue.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/futex/requeue.c b/kernel/futex/requeue.c index 842d852..150517b 100644 --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -730,14 +730,17 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bu= cket *hb, * wakeup code can't change q.key from uaddr to uaddr2 if we hold hb. * It can't be requeued from uaddr2 to something else since we don't * support a PI aware source futex for requeue. - */ - WARN_ON_ONCE(&hb->lock !=3D q->lock_ptr); - - /* + * * We were woken prior to requeue by a timeout or a signal. * Conditionally unqueue the futex_q and determine which it was. + * + * If futex_proxy_trylock_atomic() unqueued the futex_q already, a + * resize of the private hash since then did not move it, so + * q->lock_ptr can still point into the old hash, which may have + * been freed. */ if (!plist_node_empty(&q->list)) { + WARN_ON_ONCE(&hb->lock !=3D q->lock_ptr); plist_del(&q->list, &hb->chain); futex_hb_waiters_dec(hb); }