From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org,
pabeni@redhat.com, edumazet@kernel.org, horms@kernel.org,
fw@strlen.de, ja@ssi.bg
Subject: [PATCH net 04/10] netfilter: conntrack: wait for RCU readers before freeing the hash
Date: Mon, 30 Nov 2026 22:51:35 +0100 [thread overview]
Message-ID: <20261130215141.1009148-5-pablo@netfilter.org> (raw)
In-Reply-To: <20261130215141.1009148-1-pablo@netfilter.org>
From: Chengfeng Ye <nicoyip.dev@gmail.com>
nf_ct_get_tuple_skb() calls into conntrack under rcu_read_lock() without
holding a module reference. CAKE can use this hook to look up a packet
without an attached conntrack, even during nf_conntrack module teardown.
nf_conntrack_cleanup_end() clears nf_ct_hook but frees nf_conntrack_hash
without waiting for existing readers. The grace period in per-net cleanup
runs while the hook is still published, so a later reader can race as
follows:
CPU 0 (packet path) CPU 1 (module teardown)
rcu_read_lock()
ct_hook = rcu_dereference(nf_ct_hook)
RCU_INIT_POINTER(nf_ct_hook, NULL)
kvfree(nf_conntrack_hash)
ct_hook->get_tuple_skb()
nf_conntrack_find_get()
access freed hash bucket
rcu_read_unlock()
The same missing grace period affects initialization failure after
nf_conntrack_init_end() publishes the hook. During module teardown,
KASAN reported:
BUG: KASAN: vmalloc-out-of-bounds in __nf_conntrack_find_get.isra.0
Read of size 8 at addr ffffc900012e2ae0 by task poc/90
Call Trace:
__nf_conntrack_find_get.isra.0+0xf87/0x10c0 [nf_conntrack]
nf_conntrack_get_tuple_skb+0x255/0x400 [nf_conntrack]
nf_ct_get_tuple_skb+0x75/0xb0
cake_hash+0xfdb/0x1e10
cake_enqueue+0x5cd/0x36e0
dev_qdisc_enqueue+0x40/0x170
__dev_queue_xmit+0x1e90/0x3110
Wait for an RCU grace period after clearing nf_ct_hook, before releasing
the hash table and the remaining conntrack resources.
Fixes: b60a60405fb9 ("netfilter: Add nf_ct_get_tuple_skb global lookup function")
Cc: stable@vger.kernel.org
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_conntrack_core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 931b76aacd93..0cb5320883bd 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2454,6 +2454,7 @@ void nf_conntrack_cleanup_start(void)
void nf_conntrack_cleanup_end(void)
{
RCU_INIT_POINTER(nf_ct_hook, NULL);
+ synchronize_rcu();
cancel_delayed_work_sync(&conntrack_gc_work.dwork);
kvfree(nf_conntrack_hash);
--
2.47.3
next prev parent reply other threads:[~2026-11-30 21:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 21:51 [PATCH net,v2 RESEND 00/10] Netfilter fixes for net Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 01/10] netfilter: conntrack: prevent helper extension relocation Pablo Neira Ayuso
2026-11-30 21:54 ` netdev-bot+sinfo
2026-11-30 21:56 ` Pablo Neira Ayuso
2026-12-01 22:10 ` patchwork-bot+netdevbpf
2026-12-01 22:45 ` netdev-bot+sashiko
2026-11-30 21:51 ` [PATCH net 02/10] netfilter: xt_IDLETIMER: restrict to init_net Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 03/10] netfilter: synproxy: prevent unbounded recursion in transmit path Pablo Neira Ayuso
2026-11-30 21:51 ` Pablo Neira Ayuso [this message]
2026-11-30 21:51 ` [PATCH net 05/10] netfilter: nft_synproxy: only handle pure SYN and ACK packets Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 06/10] netfilter: conntrack: limit master chain depth Pablo Neira Ayuso
2026-12-01 22:45 ` netdev-bot+sashiko
2026-11-30 21:51 ` [PATCH net 07/10] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 08/10] netfilter: bridge: detach conntrack template on invalid IP frames Pablo Neira Ayuso
2026-12-01 22:45 ` netdev-bot+sashiko
2026-11-30 21:51 ` [PATCH net 09/10] netfilter: synproxy: fix double tsoff application in server ACK TSecr Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 10/10] netfilter: nf_tables: only disable tables on a dormant transition Pablo Neira Ayuso
-- strict thread matches above, loose matches on Subject: below --
2026-11-30 21:25 [PATCH net,v2 00/10] Netfilter fixes for net Pablo Neira Ayuso
2026-11-30 21:25 ` [PATCH net 04/10] netfilter: conntrack: wait for RCU readers before freeing the hash Pablo Neira Ayuso
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=20261130215141.1009148-5-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.