Linux kernel -stable discussions
 help / color / mirror / Atom feed
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 RFC 03/38] netfilter: xt_recent: don't remove the proc entries under a spinlock
Date: Mon, 02 Nov 2026 15:21:18 +0100	[thread overview]
Message-ID: <20261102-work-procfs-bugfixes-v1-3-59422ed3e465@kernel.org> (raw)
In-Reply-To: <20261102-work-procfs-bugfixes-v1-0-59422ed3e465@kernel.org>

recent_proc_net_exit() removes the proc entries of all tables with
recent_lock held. remove_proc_entry() waits until nobody calls into the
entry anymore, and reading one of them takes recent_lock in
recent_seq_start() while procfs has the entry pinned. So when a reader
gets there while the network namespace goes away, the exit path sleeps
with a spinlock held and bh disabled, waiting for a reader that spins
on that very lock:

  BUG: sleeping function called from invalid context at kernel/sched/completion.c:116
  in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 12, name: kworker/u16:0
  locks held by kworker/u16:0/12: 4, last CPU#2:
   #2: (pernet_ops_rwsem){++++}-{4:4}, at: cleanup_net+0xbf/0x860
   #3: (recent_lock){+...}-{3:3}, at: recent_net_exit+0x3d/0x170 [xt_recent]
  Workqueue: netns cleanup_net
  Call Trace:
   wait_for_completion+0x8e/0x400
   proc_entry_rundown+0x1ab/0x1f0
   remove_proc_entry+0x1ab/0x530
   recent_net_exit+0x9f/0x170 [xt_recent]
   ops_undo_list+0x271/0x8d0
   cleanup_net+0x3f3/0x860
   process_one_work+0x946/0x1820
  BUG: scheduling while atomic: kworker/u16:0/12/0x00000202

  watchdog: BUG: soft lockup - CPU#0 stuck for 26s! [rloop:252]
  Call Trace:
   _raw_spin_lock_bh+0x7a/0x80
   recent_seq_start+0x86/0x1e0 [xt_recent]
   seq_read_iter+0x26d/0x1230
   seq_read+0x2a9/0x560
   proc_reg_read+0x1c2/0x3c0
   vfs_read+0x176/0xb40
   __x64_sys_pread64+0x191/0x250

Tables are added and removed with recent_mutex held and that's also
what recent_mt_destroy() looks at ->xt_recent under. Nothing that runs
with a proc entry pinned takes it. So take recent_mutex instead.

Fixes: 665e205c16c1 ("netfilter: xt_recent: fix namespace destroy path")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 net/netfilter/xt_recent.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index 55f1f2d89952..11acb9a50d4b 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -652,12 +652,12 @@ static void __net_exit recent_proc_net_exit(struct net *net)
 	 * that the parent xt_recent proc entry is empty before trying to
 	 * remove it.
 	 */
-	spin_lock_bh(&recent_lock);
+	mutex_lock(&recent_mutex);
 	list_for_each_entry(t, &recent_net->tables, list)
 	        remove_proc_entry(t->name, recent_net->xt_recent);
 
 	recent_net->xt_recent = NULL;
-	spin_unlock_bh(&recent_lock);
+	mutex_unlock(&recent_mutex);
 
 	remove_proc_entry("xt_recent", net->proc_net);
 }

-- 
2.53.0


  parent reply	other threads:[~2026-11-02 14:22 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261102-defizit-jobaussicht-kurios-7016c6e67442@brauner>
2026-11-02 14:21 ` [PATCH RFC 00/38] proc: fix a few old bugs in /proc handlers Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 01/38] PCI/proc: don't truncate the position of config space accesses Christian Brauner
2026-11-02 17:58     ` Linus Torvalds
2026-11-04  9:17       ` Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 02/38] PNP: isapnp: don't read past the end of the buffer on a large pread() Christian Brauner
2026-11-02 14:51     ` Rafael J. Wysocki (Intel)
2026-11-02 14:21   ` Christian Brauner [this message]
2026-11-02 14:41     ` [PATCH RFC 03/38] netfilter: xt_recent: don't remove the proc entries under a spinlock Florian Westphal
2026-11-04  9:15       ` Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 04/38] s390/dasd: don't look in front of the buffer on an empty write Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 05/38] platform/x86: toshiba_acpi: reject malformed brightness and fan writes Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 06/38] xtensa: simdisk: don't read the file name without the lock Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 07/38] powerpc/rtas_flash: don't read past the validate message Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 08/38] powerpc/rtasd: zero the error log buffer Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 09/38] ALSA: info: don't write past the end of a data entry Christian Brauner
2026-11-03 10:41     ` Takashi Iwai
2026-11-02 14:21   ` [PATCH RFC 13/38] scsi: core: NUL-terminate what is written to the host proc files Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 14/38] um: NUL-terminate what is written to /proc/exitcode Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 15/38] ntfs3: don't warn when a huge label is written Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 16/38] proc: don't walk through a non-directory when resolving a name Christian Brauner
2026-11-05 11:41     ` Jan Kara
2026-11-02 14:21   ` [PATCH RFC 17/38] net: pktgen: reject device names with a '/' Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 18/38] proc: don't WARN about a name that is already registered Christian Brauner
2026-11-04 18:43     ` Alexey Dobriyan
2026-11-05 21:31       ` Christian Brauner
2026-11-05 11:52     ` Jan Kara
2026-11-02 14:21   ` [PATCH RFC 19/38] proc: resume readdir after the last name it returned Christian Brauner
2026-11-05 12:00     ` Jan Kara
2026-11-05 16:44     ` Jann Horn
2026-11-06 14:22       ` Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 23/38] proc: don't let NOMMU map procfs files Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 24/38] proc/vmcore: don't let vmcore_cleanup() run twice at once Christian Brauner
2026-11-05 12:11     ` Jan Kara
2026-11-02 14:21   ` [PATCH RFC 25/38] powerpc/crash_dump: check ioremap_cache() in copy_oldmem_page() Christian Brauner
2026-11-11 11:54     ` Breno Leitao
2026-11-02 14:21   ` [PATCH RFC 26/38] powerpc/crash_dump: recover from a machine check " Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 27/38] sunrpc: make queue_wait a global wait queue again Christian Brauner
2026-11-02 15:12     ` Chuck Lever
2026-11-03 16:26       ` Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 28/38] scsi: esas2r: bound the lengths of the HBA, SMP and firmware ioctls Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 29/38] powerpc/pseries: bound the lengths in the ofdt property parser Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 30/38] powerpc/pseries/lparcfg: return h_get_ppp()'s status as a long Christian Brauner
2026-11-02 14:21   ` [PATCH RFC 31/38] proc: sysctl: resume readdir after the last name it returned Christian Brauner
2026-11-05 12:16     ` Jan Kara
2026-11-02 14:21   ` [PATCH RFC 33/38] proc: sysctl: copy to and from userspace without holding the table Christian Brauner
2026-11-05 12:21     ` Jan Kara
2026-11-02 14:21   ` [PATCH RFC 35/38] proc: sysctl: don't hold the tables while readdir copies to userspace Christian Brauner
2026-11-05 12:55     ` Jan Kara
2026-11-02 14:43   ` [PATCH RFC 37/38] proc: don't pin a symlink's entry while readlink() copies it out Christian Brauner
2026-11-05 12:36     ` Jan Kara

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=20261102-work-procfs-bugfixes-v1-3-59422ed3e465@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