Skip to contentSkip to conversation

FAILED: patch "[PATCH] netfilter: nf_log: unregister loggers before per-net teardown" failed to apply to 5.10-stable tree

PATCH New [email protected] 2 participants 5 messages Sep 16 – Sep 17

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 2c018cc4842c33f0c732962e2ab58635e8ae5823
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026091608-unstaffed-playpen-7696@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 2c018cc4842c33f0c732962e2ab58635e8ae5823 Mon Sep 17 00:00:00 2001
From: Chengfeng Ye <[email protected]>
Date: Mon, 24 Aug 2026 01:05:38 +0800
Subject: [PATCH] netfilter: nf_log: unregister loggers before per-net teardown

nf_log_syslog and nfnetlink_log unregister their per-network namespace operations before unregistering their global logger backends. This leaves a window where a sysctl or netlink writer can rebind the still- registered logger after the per-net pre-exit callback cleared the old selection.

The race looks like this:

CPU 0 CPU 1
---- ----
unregister_pernet_subsys()

    nf_log_unset(net, logger)
      net->nf.nf_loggers[pf] = NULL

                                        lock nf_log_mutex
                                        find logger in loggers[][]
                                        net->nf.nf_loggers[pf] = logger
                                        unlock nf_log_mutex

nf_log_unregister(logger)
lock nf_log_mutex
loggers[pf][type] = NULL
unlock nf_log_mutex
synchronize_rcu()
module exit returns
module core frees backend memory

Later, a sysctl read or packet logging operation can dereference the stale per-net logger pointer.

Fix this by unregistering the global logger backends before tearing down per-net state. Once the global registrations are gone, later writers can no longer rebind the logger. unregister_pernet_subsys() already waits for an RCU grace period after the pre-exit callback clears the per-net selection, while nf_log_unregister() continues to cover readers of the global logger table.

Apply this ordering fix to both nf_log backends that combine per-net teardown with global logger registration.

Fixes 5b023fc8d8e0 ("netfilter: enable per netns support for nf_loggers")
net/netfilter/nf_log_syslog.c +1 -1
index f24288088c0d..c3fd398ffcd7 100644
@@ -1073,12 +1073,12 @@ static int __init nf_log_syslog_init(void)
 
 static void __exit nf_log_syslog_exit(void)
 {
-	unregister_pernet_subsys(&nf_log_syslog_net_ops);
 	nf_log_unregister(&nf_ip_logger);
 	nf_log_unregister(&nf_arp_logger);
 	nf_log_unregister(&nf_ip6_logger);
 	nf_log_unregister(&nf_netdev_logger);
 	nf_log_unregister(&nf_bridge_logger);
+	unregister_pernet_subsys(&nf_log_syslog_net_ops);
 }
 
 module_init(nf_log_syslog_init);
net/netfilter/nfnetlink_log.c +1 -1
index 6c7fa2ed34f5..9d7fec570abe 100644
@@ -1233,8 +1233,8 @@ static void __exit nfnetlink_log_fini(void)
 {
 	nfnetlink_subsys_unregister(&nfulnl_subsys);
 	netlink_unregister_notifier(&nfulnl_rtnl_notifier);
-	unregister_pernet_subsys(&nfnl_log_net_ops);
 	nf_log_unregister(&nfulnl_logger);
+	unregister_pernet_subsys(&nfnl_log_net_ops);
 }
 
 MODULE_DESCRIPTION("netfilter userspace logging");
maintainer
#1 lore raw

PATCH 1/4 netfilter: nf_log_ipv4: rename to nf_log_syslog

From: Florian Westphal <[email protected]>

[ Upstream commit db3187ae21bb0cff44430a7510cf2d2b23e41cd8 ]

Netfilter has multiple log modules:
nf_log_arp
nf_log_bridge
nf_log_ipv4
nf_log_ipv6
nf_log_netdev
nfnetlink_log
nf_log_common

With the exception of nfnetlink_log (packet is sent to userspace for dissection/logging), all of them log to the kernel ringbuffer.

This is the first part of a series to merge all modules except nfnetlink_log into a single module: nf_log_syslog.

This allows to reduce code. After the series, only two log modules remain:
nfnetlink_log and nf_log_syslog. The latter provides the same functionality as the old per-af log modules.

This renames nf_log_ipv4 to nf_log_syslog.

Stable-dep-of: 2c018cc4842c ("netfilter: nf_log: unregister loggers before per-net teardown")

---
 net/ipv4/netfilter/Kconfig                    |   5 +-
 net/ipv4/netfilter/Makefile                   |   1 -
 net/netfilter/Kconfig                         |  14 +-
 net/netfilter/Makefile                        |   1 +
 .../nf_log_syslog.c}                          | 120 +++++++++---------
 5 files changed, 76 insertions(+), 65 deletions(-)
 rename net/{ipv4/netfilter/nf_log_ipv4.c => netfilter/nf_log_syslog.c} (79%)
net/ipv4/netfilter/Kconfig +4 -1
index a2f4f894be2be..aadb98e43fb19 100644
@@ -81,7 +81,10 @@ config NF_LOG_ARP
 config NF_LOG_IPV4
 	tristate "IPv4 packet logging"
 	default m if NETFILTER_ADVANCED=n
-	select NF_LOG_COMMON
+	select NF_LOG_SYSLOG
+	help
+	This is a backwards-compat option for the user's convenience
+	(e.g. when running oldconfig). It selects CONFIG_NF_LOG_SYSLOG.
 
 config NF_REJECT_IPV4
 	tristate "IPv4 packet rejection"
net/ipv4/netfilter/Makefile +0 -1
index 7c497c78105f7..abd133048b42e 100644
@@ -11,7 +11,6 @@ obj-$(CONFIG_NF_TPROXY_IPV4) += nf_tproxy_ipv4.o
 
 # logging
 obj-$(CONFIG_NF_LOG_ARP) += nf_log_arp.o
-obj-$(CONFIG_NF_LOG_IPV4) += nf_log_ipv4.o
 
 # reject
 obj-$(CONFIG_NF_REJECT_IPV4) += nf_reject_ipv4.o
net/netfilter/Kconfig +13 -1
index 09ab1328e838c..1d18e46875c65 100644
@@ -78,6 +78,18 @@ config NF_LOG_NETDEV
 	tristate "Netdev packet logging"
 	select NF_LOG_COMMON
 
+config NF_LOG_SYSLOG
+	tristate "Syslog packet logging"
+	default m if NETFILTER_ADVANCED=n
+	select NF_LOG_COMMON
+	help
+	  This option enable support for packet logging via syslog.
+	  It supports IPv4 and common transport protocols such as TCP and UDP.
+	  This is a simpler but less flexible logging method compared to
+	  CONFIG_NETFILTER_NETLINK_LOG.
+	  If both are enabled the backend to use can be configured at run-time
+	  by means of per-address-family sysctl tunables.
+
 if NF_CONNTRACK
 config NETFILTER_CONNCOUNT
 	tristate
@@ -912,7 +924,7 @@ config NETFILTER_XT_TARGET_LED
 config NETFILTER_XT_TARGET_LOG
 	tristate "LOG target support"
 	select NF_LOG_COMMON
-	select NF_LOG_IPV4
+	select NF_LOG_SYSLOG
 	select NF_LOG_IPV6 if IP6_NF_IPTABLES
 	default m if NETFILTER_ADVANCED=n
 	help
net/netfilter/Makefile +1 -0
index 0e0ded87e27b3..093147f19d0b2 100644
@@ -50,6 +50,7 @@ nf_nat-y	:= nf_nat_core.o nf_nat_proto.o nf_nat_helper.o
 
 # generic transport layer logging
 obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o
+obj-$(CONFIG_NF_LOG_SYSLOG) += nf_log_syslog.o
 
 # packet logging for netdev family
 obj-$(CONFIG_NF_LOG_NETDEV) += nf_log_netdev.o
net/netfilter/nf_log_syslog.c renamed from net/ipv4/netfilter/nf_log_ipv4.c +58 -62

265 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#2 lore raw

PATCH 2/4 netfilter: nf_log_arp: merge with nf_log_syslog

From: Florian Westphal <[email protected]>

[ Upstream commit f11d61e7957d9dd54c4d87bb59da83fa949c15cb ]

similar to previous change: nf_log_syslog now covers ARP logging as well, the old nf_log_arp module is removed.

Stable-dep-of: 2c018cc4842c ("netfilter: nf_log: unregister loggers before per-net teardown")

---
 net/ipv4/netfilter/Kconfig      |   5 +-
 net/ipv4/netfilter/Makefile     |   3 -
 net/ipv4/netfilter/nf_log_arp.c | 172 --------------------------------
 net/netfilter/nf_log_syslog.c   | 113 ++++++++++++++++++++-
 4 files changed, 115 insertions(+), 178 deletions(-)
 delete mode 100644 net/ipv4/netfilter/nf_log_arp.c
net/ipv4/netfilter/Kconfig +4 -1
index aadb98e43fb19..63cb953bd0196 100644
@@ -76,7 +76,10 @@ config NF_DUP_IPV4
 config NF_LOG_ARP
 	tristate "ARP packet logging"
 	default m if NETFILTER_ADVANCED=n
-	select NF_LOG_COMMON
+	select NF_LOG_SYSLOG
+	help
+	This is a backwards-compat option for the user's convenience
+	(e.g. when running oldconfig). It selects CONFIG_NF_LOG_SYSLOG.
 
 config NF_LOG_IPV4
 	tristate "IPv4 packet logging"
net/ipv4/netfilter/Makefile +0 -3
index abd133048b42e..f38fb1368ddb2 100644
@@ -9,9 +9,6 @@ obj-$(CONFIG_NF_DEFRAG_IPV4) += nf_defrag_ipv4.o
 obj-$(CONFIG_NF_SOCKET_IPV4) += nf_socket_ipv4.o
 obj-$(CONFIG_NF_TPROXY_IPV4) += nf_tproxy_ipv4.o
 
-# logging
-obj-$(CONFIG_NF_LOG_ARP) += nf_log_arp.o
-
 # reject
 obj-$(CONFIG_NF_REJECT_IPV4) += nf_reject_ipv4.o
 
net/ipv4/netfilter/nf_log_arp.c deleted +0 -172

172 lines not on this page · raw message

net/netfilter/nf_log_syslog.c +111 -2

149 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#3 lore raw

PATCH 3/4 netfilter: nf_log_ipv6: merge with nf_log_syslog

In reply to Sasha Levin

From: Florian Westphal <[email protected]>

[ Upstream commit f5466caab9a8d2f363d2e0730a99f5916df892f5 ]

This removes the nf_log_ipv6 module, the functionality is now provided by nf_log_syslog.

Stable dependency adaptation for 2c018cc4842c:

Preserve the 5.10 MAC-header validation from 2e96e1bc9b4d when moving the IPv6 logger into nf_log_syslog; deleting the old file must not drop the skb_mac_header_was_set() and skb_mac_header_len() checks.

Also consolidate the existing netdev and bridge loggers so the target's five-logger exit hunk applies without modification. Move their packet callbacks unchanged, merge registration and error unwinding into the existing syslog callbacks, and retain compatibility Kconfig selections and module aliases. No new functions are introduced.

Unset all five syslog loggers in the existing per-net callback and use it as pre_exit, so namespace teardown waits for RCU readers. The 5.10 nfnetlink logger has no separate pre_exit callback; wait for RCU readers in its existing exit callback after unsetting the logger, without adding a function. These preserve the teardown guarantees needed by the target while leaving its global-unregistration ordering change unapplied.

Stable-dep-of: 2c018cc4842c ("netfilter: nf_log: unregister loggers before per-net teardown")

---
 net/bridge/netfilter/Kconfig         |   5 +-
 net/bridge/netfilter/Makefile        |   3 -
 net/bridge/netfilter/nf_log_bridge.c |  79 -----
 net/ipv6/netfilter/Kconfig           |   5 +-
 net/ipv6/netfilter/Makefile          |   3 -
 net/ipv6/netfilter/nf_log_ipv6.c     | 427 --------------------------
 net/netfilter/Kconfig                |   5 +-
 net/netfilter/Makefile               |   3 -
 net/netfilter/nf_log_netdev.c        |  78 -----
 net/netfilter/nf_log_syslog.c        | 431 ++++++++++++++++++++++++++-
 net/netfilter/nfnetlink_log.c        |   2 +
 11 files changed, 442 insertions(+), 599 deletions(-)
 delete mode 100644 net/bridge/netfilter/nf_log_bridge.c
 delete mode 100644 net/ipv6/netfilter/nf_log_ipv6.c
 delete mode 100644 net/netfilter/nf_log_netdev.c
net/bridge/netfilter/Kconfig +4 -1
index 5040fe43f4b42..12549a1517059 100644
@@ -23,7 +23,10 @@ config NFT_BRIDGE_REJECT
 
 config NF_LOG_BRIDGE
 	tristate "Bridge packet logging"
-	select NF_LOG_COMMON
+	select NF_LOG_SYSLOG
+	help
+	  This is a backwards-compat option for the user's convenience
+	  (e.g. when running oldconfig). It selects CONFIG_NF_LOG_SYSLOG.
 
 endif # NF_TABLES_BRIDGE
 
net/bridge/netfilter/Makefile +0 -3
index 8e2c5759d964e..1c9ce49ab6513 100644
@@ -9,9 +9,6 @@ obj-$(CONFIG_NFT_BRIDGE_REJECT)  += nft_reject_bridge.o
 # connection tracking
 obj-$(CONFIG_NF_CONNTRACK_BRIDGE) += nf_conntrack_bridge.o
 
-# packet logging
-obj-$(CONFIG_NF_LOG_BRIDGE) += nf_log_bridge.o
-
 obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
 
 # tables
net/bridge/netfilter/nf_log_bridge.c deleted +0 -79

79 lines not on this page · raw message

net/ipv6/netfilter/Kconfig +4 -1
index 262bb51a2d996..f22233e44ee97 100644
@@ -69,7 +69,10 @@ config NF_REJECT_IPV6
 config NF_LOG_IPV6
 	tristate "IPv6 packet logging"
 	default m if NETFILTER_ADVANCED=n
-	select NF_LOG_COMMON
+	select NF_LOG_SYSLOG
+	help
+	  This is a backwards-compat option for the user's convenience
+	  (e.g. when running oldconfig). It selects CONFIG_NF_LOG_SYSLOG.
 
 config IP6_NF_IPTABLES
 	tristate "IP6 tables support (required for filtering)"
net/ipv6/netfilter/Makefile +0 -3
index 731a74c60dca3..b85383606df71 100644
@@ -18,9 +18,6 @@ obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o
 obj-$(CONFIG_NF_SOCKET_IPV6) += nf_socket_ipv6.o
 obj-$(CONFIG_NF_TPROXY_IPV6) += nf_tproxy_ipv6.o
 
-# logging
-obj-$(CONFIG_NF_LOG_IPV6) += nf_log_ipv6.o
-
 # reject
 obj-$(CONFIG_NF_REJECT_IPV6) += nf_reject_ipv6.o
 
net/ipv6/netfilter/nf_log_ipv6.c deleted +0 -427

427 lines not on this page · raw message

net/netfilter/Kconfig +4 -1
index 1d18e46875c65..488e39241cc74 100644
@@ -76,7 +76,10 @@ config NF_LOG_COMMON
 
 config NF_LOG_NETDEV
 	tristate "Netdev packet logging"
-	select NF_LOG_COMMON
+	select NF_LOG_SYSLOG
+	help
+	  This is a backwards-compat option for the user's convenience
+	  (e.g. when running oldconfig). It selects CONFIG_NF_LOG_SYSLOG.
 
 config NF_LOG_SYSLOG
 	tristate "Syslog packet logging"
net/netfilter/Makefile +0 -3
index 093147f19d0b2..de8ccb50b4349 100644
@@ -52,9 +52,6 @@ nf_nat-y	:= nf_nat_core.o nf_nat_proto.o nf_nat_helper.o
 obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o
 obj-$(CONFIG_NF_LOG_SYSLOG) += nf_log_syslog.o
 
-# packet logging for netdev family
-obj-$(CONFIG_NF_LOG_NETDEV) += nf_log_netdev.o
-
 obj-$(CONFIG_NF_NAT) += nf_nat.o
 nf_nat-$(CONFIG_NF_NAT_REDIRECT) += nf_nat_redirect.o
 nf_nat-$(CONFIG_NF_NAT_MASQUERADE) += nf_nat_masquerade.o
net/netfilter/nf_log_netdev.c deleted +0 -78

78 lines not on this page · raw message

net/netfilter/nf_log_syslog.c +428 -3

486 lines not on this page · raw message

net/netfilter/nfnetlink_log.c +2 -0
index 8c967bd772ec3..dbb226aa4c0ea 100644
@@ -1128,6 +1128,8 @@ static void __net_exit nfnl_log_net_exit(struct net *net)
 	remove_proc_entry("nfnetlink_log", net->nf.proc_netfilter);
 #endif
 	nf_log_unset(net, &nfulnl_logger);
+	/* Wait for packet loggers before freeing per-net state. */
+	synchronize_rcu();
 	for (i = 0; i < INSTANCE_BUCKETS; i++)
 		WARN_ON_ONCE(!hlist_empty(&log->instance_table[i]));
 }
Signature · 1 line
2.53.0
maintainer
#4 lore raw

PATCH 4/4 netfilter: nf_log: unregister loggers before per-net teardown

In reply to Sasha Levin

From: Chengfeng Ye <[email protected]>

[ Upstream commit 2c018cc4842c33f0c732962e2ab58635e8ae5823 ]

nf_log_syslog and nfnetlink_log unregister their per-network namespace operations before unregistering their global logger backends. This leaves a window where a sysctl or netlink writer can rebind the still- registered logger after the per-net pre-exit callback cleared the old selection.

The race looks like this:

CPU 0 CPU 1
---- ----
unregister_pernet_subsys()

    nf_log_unset(net, logger)
      net->nf.nf_loggers[pf] = NULL

                                        lock nf_log_mutex
                                        find logger in loggers[][]
                                        net->nf.nf_loggers[pf] = logger
                                        unlock nf_log_mutex

nf_log_unregister(logger)
lock nf_log_mutex
loggers[pf][type] = NULL
unlock nf_log_mutex
synchronize_rcu()
module exit returns
module core frees backend memory

Later, a sysctl read or packet logging operation can dereference the stale per-net logger pointer.

Fix this by unregistering the global logger backends before tearing down per-net state. Once the global registrations are gone, later writers can no longer rebind the logger. unregister_pernet_subsys() already waits for an RCU grace period after the pre-exit callback clears the per-net selection, while nf_log_unregister() continues to cover readers of the global logger table.

Apply this ordering fix to both nf_log backends that combine per-net teardown with global logger registration.

Fixes 5b023fc8d8e0 ("netfilter: enable per netns support for nf_loggers")
---
 net/netfilter/nf_log_syslog.c | 2 +-
 net/netfilter/nfnetlink_log.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_log_syslog.c +1 -1
index cce8f282b0eda..bf902b1fe2aac 100644
@@ -899,12 +899,12 @@ static int __init nf_log_syslog_init(void)
 
 static void __exit nf_log_syslog_exit(void)
 {
-	unregister_pernet_subsys(&nf_log_syslog_net_ops);
 	nf_log_unregister(&nf_ip_logger);
 	nf_log_unregister(&nf_arp_logger);
 	nf_log_unregister(&nf_ip6_logger);
 	nf_log_unregister(&nf_netdev_logger);
 	nf_log_unregister(&nf_bridge_logger);
+	unregister_pernet_subsys(&nf_log_syslog_net_ops);
 }
 
 module_init(nf_log_syslog_init);
net/netfilter/nfnetlink_log.c +1 -1
index dbb226aa4c0ea..e576c5417433d 100644
@@ -1179,8 +1179,8 @@ static void __exit nfnetlink_log_fini(void)
 {
 	nfnetlink_subsys_unregister(&nfulnl_subsys);
 	netlink_unregister_notifier(&nfulnl_rtnl_notifier);
-	unregister_pernet_subsys(&nfnl_log_net_ops);
 	nf_log_unregister(&nfulnl_logger);
+	unregister_pernet_subsys(&nfnl_log_net_ops);
 }
 
 MODULE_DESCRIPTION("netfilter userspace logging");
Signature · 1 line
2.53.0