From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Jann Horn <jannh@google.com>, Josef Bacik <josef@toxicpanda.com>,
Chris Mason <mason@kernel.org>, Jeff Layton <jlayton@kernel.org>,
NeilBrown <neil@brown.name>, Eric Dumazet <edumazet@kernel.org>,
Thomas Gleixner <tglx@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Jonathan Corbet <corbet@lwn.net>, Christoph Hellwig <hch@lst.de>,
Greg Kroah-Hartman <gregkh@suse.de>,
Joel Granados <joel.granados@kernel.org>,
Kees Cook <kees@kernel.org>, Jan Kara <jack@suse.cz>,
Jan Kara <jack@suse.com>,
linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org,
linux-acpi@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-um@lists.infradead.org, linux-wireless@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org,
ntfs3@lists.linux.dev, platform-driver-x86@vger.kernel.org,
coreteam@netfilter.org, kexec@lists.infradead.org,
linux-pci@vger.kernel.org, linux-sound@vger.kernel.org,
netfilter-devel@vger.kernel.org, dri-devel@lists.freedesktop.org,
ibm-acpi-devel@lists.sourceforge.net,
jfs-discussion@lists.sourceforge.net,
linux-alpha@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-cifs@vger.kernel.org,
linux-fbdev@vger.kernel.org, linux-hwmon@vger.kernel.org,
linux-mm@kvack.org, linux-sh@vger.kernel.org,
linux-usb@vger.kernel.org, samba-technical@lists.samba.org,
sparclinux@vger.kernel.org, linux-m68k@lists.linux-m68k.org,
linux-doc@vger.kernel.org, linux-serial@vger.kernel.org,
linux-atm-general@lists.sourceforge.net,
Takashi Iwai <tiwai@suse.de>,
linux-input@vger.kernel.org, linux-raid@vger.kernel.org,
linux-ext4@vger.kernel.org, linux-modules@vger.kernel.org,
linux-debuggers@vger.kernel.org,
"Christian Brauner (Amutable)" <brauner@kernel.org>,
Chuck Lever <cel@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH RESEND v2 40/51] sunrpc: make queue_wait a global wait queue again
Date: Wed, 4 Nov 2026 20:25:47 +0100 [thread overview]
Message-ID: <20261104-work-procfs-bugfixes-v2-40-021c84d852e0@kernel.org> (raw)
In-Reply-To: <20261104-work-procfs-bugfixes-v2-0-021c84d852e0@kernel.org>
Since commit 552d0e17ea04 ("sunrpc: convert queue_wait from global to
per-cache-detail waitqueue") poll() and epoll queue their waiters for a
channel file on the queue_wait head in struct cache_detail. But the
cache_detail can be freed while its channel file is still open and
waited on.
The procfs channel files of a network namespace are removed when the
namespace goes away. Removing a procfs file waits for the callers that
are in one of its methods right now and then calls ->release on every
file that is still open (cf. close_pdeo()). The waiters that poll() and
epoll left on the head stay queued until their file is really closed.
So:
sunrpc_exit_net()
-> ip_map_cache_destroy()
-> cache_unregister_net()
-> remove_cache_proc_entries()
-> proc_remove() // ->release, the waiters stay queued
-> cache_destroy_net() // kfree(cd)
and when poll() returns remove_wait_queue() writes to the freed
cache_detail:
BUG: KASAN: slab-use-after-free in _raw_spin_lock_irqsave+0x4b/0xa0
Read of size 1 at addr ff110001131bb570 by task sunrpc-poll-uaf/242
Call Trace:
remove_wait_queue+0x22/0x1c0
poll_freewait+0xc2/0x230
do_sys_poll+0x9ba/0xd50
__x64_sys_poll+0x165/0x470
Freed by task 12:
kfree+0x267/0x620
sunrpc_exit_net+0x34/0x80
ops_undo_list+0x271/0x8d0
cleanup_net+0x3f3/0x860
Closing an epoll instance that watches the file gets there through
ep_unregister_pollwait() instead.
The channel files of a network namespace belong to the root of its
user namespace and cache_open() doesn't check for a capability. So an
unprivileged user can open the channel file of a namespace of its own
from the outside, poll it and let the namespace die.
Go back to a single static wait queue that never goes away. A wakeup
for one cache wakes the waiters of all caches again but cache_poll()
reports per cache_detail so that's just a spurious wakeup. procfs
should really own the wait queue of its files like kernfs does but
that's nothing for stable.
Reported-by: Chris Mason <mason@kernel.org>
Fixes: 552d0e17ea04 ("sunrpc: convert queue_wait from global to per-cache-detail waitqueue")
Acked-by: Chuck Lever <cel@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
include/linux/sunrpc/cache.h | 1 -
net/sunrpc/cache.c | 12 +++++++++---
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 2735c332ddb7..bf4fc543e1e5 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -119,7 +119,6 @@ struct cache_detail {
struct list_head requests;
struct list_head readers;
spinlock_t queue_lock;
- wait_queue_head_t queue_wait;
u64 next_seqno;
atomic_t writers; /* how many time is /channel open */
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 1bc04109d213..1ceaea7e01b9 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -404,7 +404,6 @@ void sunrpc_init_cache_detail(struct cache_detail *cd)
INIT_LIST_HEAD(&cd->requests);
INIT_LIST_HEAD(&cd->readers);
spin_lock_init(&cd->queue_lock);
- init_waitqueue_head(&cd->queue_wait);
cd->next_seqno = 1;
spin_lock(&cache_list_lock);
cd->nextcheck = 0;
@@ -965,13 +964,20 @@ out:
return ret;
}
+/*
+ * Not in struct cache_detail: poll and epoll waiters stay queued until
+ * their file is closed, but a channel file in procfs can stay open after
+ * the cache_detail of its dying network namespace has been freed.
+ */
+static DECLARE_WAIT_QUEUE_HEAD(queue_wait);
+
static __poll_t cache_poll(struct file *filp, poll_table *wait,
struct cache_detail *cd)
{
__poll_t mask;
struct cache_reader *rp = filp->private_data;
- poll_wait(filp, &cd->queue_wait, wait);
+ poll_wait(filp, &queue_wait, wait);
/* alway allow write */
mask = EPOLLOUT | EPOLLWRNORM;
@@ -1236,7 +1242,7 @@ static int cache_do_upcall(struct cache_detail *detail, struct cache_head *h)
spin_unlock(&detail->queue_lock);
if (ret != -EAGAIN && detail->cache_notify)
detail->cache_notify(detail, h);
- wake_up(&detail->queue_wait);
+ wake_up(&queue_wait);
if (ret == -EAGAIN) {
kfree(buf);
kfree(crq);
--
2.53.0
next prev parent reply other threads:[~2026-11-04 19:26 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261104-work-procfs-v2-0-b45cd5789ac5@brauner>
2026-11-04 19:05 ` [PATCH RESEND v2 00/51] proc: fix a few old bugs in /proc handlers (Part 1/7) Christian Brauner
2026-11-04 19:06 ` [PATCH RESEND v2 01/51] alloc_tag: don't remove /proc/allocinfo under the codetag module lock Christian Brauner
2026-11-05 2:15 ` Hao Ge
2026-11-04 19:16 ` [PATCH RESEND v2 02/51] scsi: esas2r: don't copy kernel pointers out in EXPRESS_IOCTL_GET_MOD_INFO Christian Brauner
2026-11-04 19:16 ` [PATCH RESEND v2 03/51] ALSA: cs46xx: hand the region to the region proc files Christian Brauner
2026-11-07 9:00 ` Takashi Iwai
2026-11-04 19:16 ` [PATCH RESEND v2 04/51] PNP: isapnp: don't go on when isapnp_cfg_begin() fails Christian Brauner
2026-11-04 19:17 ` [PATCH RESEND v2 05/51] xtensa: simdisk: remove the proc entry before the disk Christian Brauner
2026-11-04 19:17 ` [PATCH RESEND v2 08/51] powerpc/pseries/lparcfg: don't drop the last byte of a write Christian Brauner
2026-11-04 19:19 ` [PATCH RESEND v2 13/51] sched/psi: don't drop the last byte of a trigger write Christian Brauner
2026-11-04 19:19 ` [PATCH RESEND v2 14/51] proc: sysctl: don't stop readdir at an entry that is being unregistered Christian Brauner
2026-11-04 19:19 ` [PATCH RESEND v2 15/51] PCI/proc: don't truncate the position of config space accesses Christian Brauner
2026-11-04 19:19 ` [PATCH RESEND v2 16/51] PNP: isapnp: don't read past the end of the buffer on a large pread() Christian Brauner
2026-11-04 19:20 ` [PATCH RESEND v2 17/51] s390/dasd: don't look in front of the buffer on an empty write Christian Brauner
2026-11-04 19:20 ` [PATCH RESEND v2 18/51] platform/x86: toshiba_acpi: reject malformed brightness and fan writes Christian Brauner
2026-11-04 19:20 ` [PATCH RESEND v2 19/51] xtensa: simdisk: don't read the file name without the lock Christian Brauner
2026-11-04 19:20 ` [PATCH RESEND v2 20/51] powerpc/rtas_flash: don't read past the validate message Christian Brauner
2026-11-04 19:21 ` [PATCH RESEND v2 21/51] powerpc/rtasd: zero the error log buffer Christian Brauner
2026-11-04 19:21 ` [PATCH RESEND v2 22/51] ALSA: info: don't write past the end of a data entry Christian Brauner
2026-11-04 19:22 ` [PATCH RESEND v2 26/51] scsi: core: NUL-terminate what is written to the host proc files Christian Brauner
2026-11-04 19:22 ` [PATCH RESEND v2 27/51] um: NUL-terminate what is written to /proc/exitcode Christian Brauner
2026-11-04 19:22 ` [PATCH RESEND v2 28/51] ntfs3: don't warn when a huge label is written Christian Brauner
2026-11-04 19:23 ` [PATCH RESEND v2 29/51] proc: don't walk through a non-directory when resolving a name Christian Brauner
2026-11-04 19:23 ` [PATCH RESEND v2 30/51] net: pktgen: reject device names with a '/' Christian Brauner
2026-11-04 19:23 ` [PATCH RESEND v2 31/51] proc: don't WARN about a name that is already registered Christian Brauner
2026-11-04 19:23 ` [PATCH RESEND v2 32/51] proc: resume readdir after the last name it returned Christian Brauner
2026-11-04 19:24 ` [PATCH RESEND v2 36/51] proc: don't let NOMMU map procfs files Christian Brauner
2026-11-04 19:25 ` [PATCH RESEND v2 37/51] proc/vmcore: don't let vmcore_cleanup() run twice at once Christian Brauner
2026-11-04 19:25 ` [PATCH RESEND v2 38/51] powerpc/crash_dump: check ioremap_cache() in copy_oldmem_page() Christian Brauner
2026-11-04 19:25 ` [PATCH RESEND v2 39/51] powerpc/crash_dump: recover from a machine check " Christian Brauner
2026-11-04 19:25 ` Christian Brauner [this message]
2026-11-04 19:26 ` [PATCH RESEND v2 41/51] scsi: esas2r: bound the lengths of the HBA, SMP and firmware ioctls Christian Brauner
2026-11-04 19:26 ` [PATCH RESEND v2 42/51] powerpc/pseries: bound the lengths in the ofdt property parser Christian Brauner
2026-11-04 19:26 ` [PATCH RESEND v2 43/51] powerpc/pseries/lparcfg: return h_get_ppp()'s status as a long Christian Brauner
2026-11-04 19:26 ` [PATCH RESEND v2 44/51] proc: sysctl: resume readdir after the last name it returned Christian Brauner
2026-11-05 0:08 ` Jann Horn
2026-11-05 8:43 ` Christian Brauner
2026-11-05 16:26 ` Jann Horn
2026-11-04 19:27 ` [PATCH RESEND v2 46/51] proc: sysctl: copy to and from userspace without holding the table Christian Brauner
2026-11-04 19:27 ` [PATCH RESEND v2 48/51] proc: sysctl: don't hold the tables while readdir copies to userspace Christian Brauner
2026-11-04 19:28 ` [PATCH RESEND v2 50/51] proc: don't pin a symlink's entry while readlink() copies it out Christian Brauner
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=20261104-work-procfs-bugfixes-v2-40-021c84d852e0@kernel.org \
--to=brauner@kernel.org \
--cc=cel@kernel.org \
--cc=corbet@lwn.net \
--cc=coreteam@netfilter.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=edumazet@kernel.org \
--cc=gregkh@suse.de \
--cc=hch@lst.de \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=jack@suse.com \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=jlayton@kernel.org \
--cc=joel.granados@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kees@kernel.org \
--cc=kexec@lists.infradead.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-atm-general@lists.sourceforge.net \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-debuggers@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-mm@kvack.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mason@kernel.org \
--cc=neil@brown.name \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
--cc=platform-driver-x86@vger.kernel.org \
--cc=samba-technical@lists.samba.org \
--cc=sparclinux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=tiwai@suse.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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