Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.70.190.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073949; b=WoLkl8DM8ujmo3fsT35I1K5e6hVbnXuJCmOlaTWMzOohO0sL2mop0U7PN7EUmY141fgB F/9uBGcUzV7k648rZnCTb26AXXmzdDkWAxVO6kJWT0ds5HryqfDEwgzq3dCLsmFYh0YDo 2/HdFVLev1sqn6cn0wVhmA7Cq4cgSSHbpyhJHNvvb/rzGUR91ApC4EzhjL2Bu4tUR2aNI lvqPox3IHk1+GKMOtHfBgJHp78g4NQznHjEUBikROe8LfHb9ubNOH/p8Nhk2fQYgsXIDA DGXq39AEqHo+lJfieEY2fiiKFBTyGYMBCGk5ALHhRhbEJKvw8Vwrd5oqg9wXbkaIkYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073949; h=DMARC-Filter:DKIM-Signature:Received:From:To:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Spam-Status:X-Spam-Checker-Version; bh=xZ3eqTZp6NQwb56oG2R4X/2aLhW4tkf227FdSJvTBLY=; b=guj+tRnN7OxESJv8xQDBoB+6P3DL+avaDNMutrQWRQlCJ0rnsMU2jYQukMytE4IpSGyV RWix8jkYc0isGSr4IGBSx47ZyXBCfy8p0wjtkX4i8cZL9KUpXVg1Y5RWds2VKx27ylomg 8hoHj4WvLnSs//vHt9d4XT8y59z2wDqMfsEoMHVf0H93BthJag653e32eQyEJ+9h5uyb8 +LQ38QDopkiJDgRAA1fEpVJwhxeyC/PDLaimfnv0rxeGvQEvR8ajhsZuBoiGZiOeeWmaz Nn7FY4vh9fWaNtNJEHzqvYdPLRkqD1y+dclt1pByzZXIQqUE8oSMiLJ+SHZdtF6NBdA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=netfilter.org; spf=pass smtp.mailfrom=netfilter.org; dkim=pass header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=lXvSAaAx; arc=none smtp.remote-ip=217.70.190.124 Received: from mail.netfilter.org (mail.netfilter.org [217.70.190.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32A40606A31A for ; Mon, 30 Nov 2026 21:25:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 32A40606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netfilter.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=lXvSAaAx DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org; s=2025; t=1796073947; bh=xZ3eqTZp6NQwb56oG2R4X/2aLhW4tkf227FdSJvTBLY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lXvSAaAxtJrFjSCrJIdEwVaLHddLlnoJmoEPcS3etBPesS9bc7xnM8+pY/DhH19qp HbryVJnCBDqpKMIVsSK+stHsVqRV559W2zLafzgejQq0fXFgWN7P/kcw13AKEfqAp+ WzMjAumrOi/0y9Lqa/5C6jqxwCDI3a70D+f3NZd6FIVZ0BOmi7DJHh8ujnL0PSkDKk 3QwPtp5c7Y9qcp6B8SySoZ6AZPMRZPQIXrEjY/B0PoAyL+z2CKiks72qtoNF+H5hFZ Pv/7mX53QHQoLNZ4HiyNCfhesKYkRFABn5hhw3o4suQ8II6Mkbo8AA0TPG8MFDESnj oD+/HAvq/i4OQ== Received: from localhost.localdomain (mail-agni [217.70.190.124]) by mail.netfilter.org (Postfix) with ESMTPSA id 20DEF60088 for ; Mon, 30 Nov 2026 22:25:47 +0100 (CET) From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Subject: [PATCH net 04/10] netfilter: conntrack: wait for RCU readers before freeing the hash Date: Mon, 30 Nov 2026 22:25:33 +0100 Message-ID: <20261130212539.992130-5-pablo@netfilter.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130212539.992130-1-pablo@netfilter.org> References: <20261130212539.992130-1-pablo@netfilter.org> X-Mailing-List: netfilter-devel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chengfeng Ye 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 Signed-off-by: Pablo Neira Ayuso --- 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