Archive-only list for patches
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev,
	syzbot+350a93852ac854927f45@syzkaller.appspotmail.com,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Thomas Gleixner <tglx@kernel.org>
Subject: [PATCH 6.18 79/94] futex: Fix might_sleep() warning in futex_pivot_pending()
Date: Tue, 25 Aug 2026 15:26:15 +0200	[thread overview]
Message-ID: <20260825132544.965702385@linuxfoundation.org> (raw)
In-Reply-To: <20260825132541.887883084@linuxfoundation.org>

6.18-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Peter Zijlstra <peterz@infradead.org>

commit d8aa5dd97944a72d4a9e3cc79bb80fcac7d6e829 upstream.

A younger me put a WARN in might_sleep() to warn about nested sleep loops. This
younger me also build a wait-loop variant that can deal with it. This wait-loop
variant doesn't have all the fancy wrappers, since it isn't used much. It also
lacks wait-bit support.

Add the wait-bit support and use it to fix the nested wait issue.

Fixes: 8e7ff730dd96 ("futex: Fix race in futex_pivot_pending() during private hash resize")
Reported-by: syzbot+350a93852ac854927f45@syzkaller.appspotmail.com
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260820074927.GH1246887@noisy.programming.kicks-ass.net
Closes: https://syzkaller.appspot.com/bug?extid=350a93852ac854927f45
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 include/linux/wait.h     |    1 +
 include/linux/wait_bit.h |    1 +
 kernel/futex/core.c      |   27 ++++++++++++++++++++++++++-
 kernel/sched/wait.c      |   15 +++++++++++++++
 kernel/sched/wait_bit.c  |   14 +++++++++++---
 5 files changed, 54 insertions(+), 4 deletions(-)
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -1213,6 +1213,7 @@ long prepare_to_wait_event(struct wait_q
 void finish_wait(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry);
 long wait_woken(struct wait_queue_entry *wq_entry, unsigned mode, long timeout);
 int woken_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
+int woken_wake_bit_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
 int autoremove_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
 
 #define DEFINE_WAIT_FUNC(name, function)					\
--- a/include/linux/wait_bit.h
+++ b/include/linux/wait_bit.h
@@ -32,6 +32,7 @@ int out_of_line_wait_on_bit_timeout(unsi
 int out_of_line_wait_on_bit_lock(unsigned long *word, int, wait_bit_action_f *action, unsigned int mode);
 struct wait_queue_head *bit_waitqueue(unsigned long *word, int bit);
 extern void __init wait_bit_init(void);
+extern struct wait_bit_key *__var_wake_key(struct wait_queue_entry *wq_entry, void *arg);
 
 int wake_bit_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
 
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -44,6 +44,7 @@
 #include <linux/prctl.h>
 #include <linux/mempolicy.h>
 #include <linux/mmap_lock.h>
+#include <linux/wait_bit.h>
 
 #include "futex.h"
 #include "../locking/rtmutex_common.h"
@@ -1866,11 +1867,35 @@ static int futex_hash_allocate(unsigned
 		futex_hash_bucket_init(&fph->queues[i], fph);
 
 	if (custom) {
+		struct wait_bit_queue_entry __wbq_entry;
+		struct wait_queue_head *__wq_head;
+
 		/*
 		 * Only let prctl() wait / retry; don't unduly delay clone().
 		 */
 again:
-		wait_var_event(mm, futex_pivot_pending(mm));
+		__wq_head = __var_waitqueue(mm);
+		init_wait_var_entry(&__wbq_entry, mm, 0);
+		__wbq_entry.wq_entry.func = woken_wake_bit_function;
+		add_wait_queue(__wq_head, &__wbq_entry.wq_entry);
+
+		/*
+		 * add_wait_queue()		futex_ref_put()
+		 * MB (this)			MB (implied)
+		 * futex_pivot_pending()	wake_up_var()
+		 *                                waitqueue_active()
+		 *
+		 * Notably, it must not be possible to see
+		 * !futex_pivot_pending() && !waitqueue_active().
+		 */
+		smp_mb();
+
+		while (!futex_pivot_pending(mm) &&
+		       wait_woken(&__wbq_entry.wq_entry, TASK_UNINTERRUPTIBLE,
+				  MAX_SCHEDULE_TIMEOUT))
+			/* empty */;
+
+		remove_wait_queue(__wq_head, &__wbq_entry.wq_entry);
 	}
 
 	scoped_guard(mutex, &mm->futex_hash_lock) {
--- a/kernel/sched/wait.c
+++ b/kernel/sched/wait.c
@@ -5,6 +5,7 @@
  * (C) 2004 Nadia Yvette Chambers, Oracle
  */
 #include "sched.h"
+#include <linux/wait_bit.h>
 
 void __init_waitqueue_head(struct wait_queue_head *wq_head, const char *name, struct lock_class_key *key)
 {
@@ -463,3 +464,17 @@ int woken_wake_function(struct wait_queu
 	return default_wake_function(wq_entry, mode, sync, key);
 }
 EXPORT_SYMBOL(woken_wake_function);
+
+int woken_wake_bit_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *arg)
+{
+	struct wait_bit_key *key = __var_wake_key(wq_entry, arg);
+	if (!key)
+		return 0;
+
+	/* Pairs with the smp_store_mb() in wait_woken(). */
+	smp_mb(); /* C */
+	wq_entry->flags |= WQ_FLAG_WOKEN;
+
+	return default_wake_function(wq_entry, mode, sync, key);
+}
+EXPORT_SYMBOL(woken_wake_bit_function);
--- a/kernel/sched/wait_bit.c
+++ b/kernel/sched/wait_bit.c
@@ -167,9 +167,7 @@ wait_queue_head_t *__var_waitqueue(void
 }
 EXPORT_SYMBOL(__var_waitqueue);
 
-static int
-var_wake_function(struct wait_queue_entry *wq_entry, unsigned int mode,
-		  int sync, void *arg)
+struct wait_bit_key *__var_wake_key(struct wait_queue_entry *wq_entry, void *arg)
 {
 	struct wait_bit_key *key = arg;
 	struct wait_bit_queue_entry *wbq_entry =
@@ -177,6 +175,16 @@ var_wake_function(struct wait_queue_entr
 
 	if (wbq_entry->key.flags != key->flags ||
 	    wbq_entry->key.bit_nr != key->bit_nr)
+		return NULL;
+
+	return key;
+}
+
+static int var_wake_function(struct wait_queue_entry *wq_entry, unsigned int mode,
+			     int sync, void *arg)
+{
+	struct wait_bit_key *key = __var_wake_key(wq_entry, arg);
+	if (!key)
 		return 0;
 
 	return autoremove_wake_function(wq_entry, mode, sync, key);



  parent reply	other threads:[~2026-08-25 13:42 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25 13:24 [PATCH 6.18 00/94] 6.18.47-rc1 review Greg Kroah-Hartman
2026-08-25 13:24 ` [PATCH 6.18 01/94] serial: sc16is7xx: rename EFR mutex with generic name Greg Kroah-Hartman
2026-08-25 13:24 ` [PATCH 6.18 02/94] serial: sc16is7xx: use guards for simple mutex locks Greg Kroah-Hartman
2026-08-25 13:24 ` [PATCH 6.18 03/94] serial: sc16is7xx: enable THRI before filling TX FIFO Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 04/94] xfs: add a xchk_ip_set_corrupt helper Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 05/94] xfs: rtsummary scrub should treat rtbitmap corruption errors as an xref error Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 06/94] xfs: hoist per-bucket unlinked list check to helper Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 07/94] xfs: dont livelock in scrub on a circular unlinked list Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 08/94] PCI: host-generic: Fix NULL pointer dereference on 32-bit CAM systems Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 09/94] Bluetooth: RFCOMM: take rfcomm_mutex for the deferred setup accept Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 10/94] iommu/tegra241-cmdqv: Fix CMD_SYNC use-after-free on teardown Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 11/94] iommu/iommufd: Fix NULL pointer deref in iommufd_ioas_change_process when racing with iopt_map_file_pages Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 12/94] ALSA: FCP: Use a private URB for the notification endpoint Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 13/94] ALSA: scarlett2: " Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 14/94] rndis_host: add overflow check in rndis_rx_fixup() Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 15/94] nvmet: fix NULL pointer dereference in nvmet_execute_identify_nslist() Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 16/94] io_uring/futex: dont mark futex wake requests as inflight Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 17/94] ALSA: dummy: Check card index validity at probe Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 18/94] io_uring/cmd: fix iovec leak when the async cmd is not recycled Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 19/94] io_uring/io-wq: fix worker accounting when canceling creation callbacks Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 20/94] io_uring/rsrc: fix folio size overflow in io_vec_fill_bvec() Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 21/94] io_uring/uring_cmd: dont skip completion for a synchronous multishot cmd Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 22/94] ocfs2: fix missing metadata reservation for large xattrs Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 23/94] null_blk: fix UBSAN shift-out-of-bounds when zone_size is 0 or overflows Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 24/94] kcov: fix data corruption and race conditions on PREEMPT_RT Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 25/94] ext4: stop retrying saturated xattr cache entries Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 26/94] nilfs2: reject invalid block index in GC ioctl Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 27/94] ext4: clear error before retrying inode xattr space fallback Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 28/94] ext4: avoid tail write_begin walk for uptodate folios Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 29/94] ext4: propagate errors from fast commit range replay Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 30/94] ext4: dont enable DAX on new encrypted files Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 31/94] ext4: fix incorrect function call when initializing s_resgid Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 32/94] xfs: validate attr entry pointer before field access Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 33/94] libceph: fix OOB read in decode_watchers() via missing bounds check Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 34/94] nfc: digital: clamp SENSF_RES length to the destination buffer Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 35/94] nfc: fdp: bound the device-reported read length and fix an skb leak Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 36/94] nfc: microread: validate target discovery payload lengths Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 37/94] nfc: llcp: bound the connect_sn TLV walk to the skb Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 38/94] nfc: llcp: fix OOB read and u8 offset wrap in TLV parsers Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 39/94] nfc: llcp: reject PDUs shorter than the LLCP header Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 40/94] nfc: pn533: purge fragmented skbs during cleanup Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 41/94] nfc: st21nfca: validate ATR_REQ length against the received frame Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 42/94] nfc: nci: add data_len bound checks to activation parameter extractors Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 43/94] nfc: nci: fix out-of-bounds write in nci_target_auto_activated() Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 44/94] nfc: nci: fix uninit-value in the RF discover/activated NTF handlers Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 45/94] nfc: nci: free destination parameters when closing a connection Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 46/94] drm/xe: Fix DPT allocation paths Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 47/94] ipv4: reject undersized MTUs in ip_do_fragment() Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 48/94] ipv6: fix use-after-free in ip6_finish_output2() Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 49/94] mailbox: mchp-ipc-sbi: Add null check for devm_kasprintf() Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 50/94] dmaengine: fsl-edma: Add error handling for devm_kasprintf Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 51/94] nvmet-auth: zero the AUTH_RECEIVE response buffer Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 52/94] nvmet-fc: fix invalid free in LS IOD error path Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 53/94] nvmet-tcp: bound SGL data length before allocating command buffers Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 54/94] nvmet-tcp: Do not WARN on remotely-controlled oversized SGL allocations Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 55/94] nvmet: pci-epf: fix use-after-free in nvmet_pci_epf_exec_iod_work() Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 56/94] nvmet: pci-epf: put CQ ref on create_cq mapping failure Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 57/94] mptcp: pm: use for_each_subflow helper Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 58/94] mptcp: pm: rename add_entry structure to add_addr Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 59/94] mptcp: pm: uniform announced addresses helpers Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 60/94] mptcp: pm: fix memory leak from alloc-during-teardown race Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 61/94] selinux: use u16 for security classes Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 62/94] selinux: more strict policy parsing Greg Kroah-Hartman
2026-08-25 13:25 ` [PATCH 6.18 63/94] selinux: require a classs permission values to cover its permission count Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 64/94] ASoC: codecs: lpass-tx-macro: Fix enum kcontrol accesses Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 65/94] HID: magicmouse: fix battery reporting for Bluetooth Magic Trackpad USB-C Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 66/94] HID: magicmouse: re-enable multitouch after reset-resume Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 67/94] HID: magicmouse: do not keep a stale msc->input if no input is claimed Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 68/94] HID: magicmouse: Prevent out-of-bounds (OOB) read during DOUBLE_REPORT_ID Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 69/94] HID: core: fix OOB read of field->usage in hid_set_field() Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 70/94] HID: pidff: fix OOB write when hid->inputs is empty Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 71/94] net/ionic: avoid OOB TX partner lookup for hwstamp RXQ Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 72/94] xfrm: fix sk_dst_cache double-free in xfrm_user_policy() Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 73/94] Input: atkbd - skip deactivate for HONOR FMB-Ps internal keyboard Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 74/94] Input: atkbd - skip deactivate for HONOR ZQC-P Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 75/94] futex/pi: Reject cross-mm private futex owners Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 76/94] futex: Sanitize and document task_struct::futex::state transitions Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 77/94] futex/pi: Plug private futex exec() race Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 78/94] futex: Fix race on the initial mm->futex.phash.ref allocation Greg Kroah-Hartman
2026-08-25 13:26 ` Greg Kroah-Hartman [this message]
2026-08-25 13:26 ` [PATCH 6.18 80/94] HID: nintendo: fix out-of-bounds read in joycon_ctlr_read_handler() Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 81/94] HID: nintendo: register input device after capabilities are set Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 82/94] HID: nintendo: stop device IO before hid_hw_stop on probe failure Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 83/94] HID: core: fix number/pointer type confusion on long items Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 84/94] HID: sensor: custom: Fix use-after-free in enable_sensor Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 85/94] HID: uclogic: fix use-after-free of inrange_timer on remove Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 86/94] HID: hyperv: validate initial device info bounds Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 87/94] drm/xe: Dont hand out the flat CCS storage as usable VRAM Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 88/94] Bluetooth: hci_event: fix LE list UAF on reset Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 89/94] Bluetooth: hci_event: validate LE Set CIG Parameters response Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 90/94] Bluetooth: hci_sync: Fix accept list UAF during suspend Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 91/94] Bluetooth: ISO: do not force BT_LISTEN after a failed BIG sync Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 92/94] Bluetooth: ISO: zero the sockaddr before returning it in getname Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 93/94] Bluetooth: MGMT: reject HCI_CMD_SYNC params_len above 255 Greg Kroah-Hartman
2026-08-25 13:26 ` [PATCH 6.18 94/94] Bluetooth: hci_aml: validate firmware segment lengths Greg Kroah-Hartman
2026-08-25 19:33 ` [PATCH 6.18 00/94] 6.18.47-rc1 review Pavel Machek
2026-08-25 23:12 ` Florian Fainelli
2026-08-26  0:05 ` Shuah Khan
2026-08-26  6:09 ` Ron Economos
2026-08-26  6:28 ` Wentao Guan
2026-08-26 10:32 ` Brett A C Sheffield
2026-08-26 12:19 ` Miguel Ojeda
2026-08-26 14:14 ` Peter Schneider
2026-08-27 12:30 ` Mark Brown

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=20260825132544.965702385@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=patches@lists.linux.dev \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+350a93852ac854927f45@syzkaller.appspotmail.com \
    --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