From mboxrd@z Thu Jan 1 00:00:00 1970 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=1795910857; b=NpV9Y2VtfrM4TQqkM79NMXZzr5GXdAdXcR1zp07xohmXTQCOGVhdvU/EFDPT3E5zUwC9 B2IDLg4wyci+ABDh83YbsnmxgJjstBpB8FBLKyuCOoqPVaElC1oZNgjvKMYB9cMdz7UJ5 iJ3EWuaCNnTrnkn+XYP3TAciyHUJ+hBHPtmvjCSgerVjsvMkythB9DjB/U8YE5JS1z0se ysYCn+uRFd6FClZp+p6Bxrl7CrpfJlK4IfyZQIzVS/GIhGqN8LjDcEzNJZymKnaJRsVel Ur3/LfuWskcBkEsqNReCiiKuXrA4nFaDFfFki5UIMPq3oyyWFsfNreLLOdMEsosU3Ow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795910857; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc: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=4xl+ZJpadx0yMTBW1HFCHIjC8vI8Imt6P3T/mQOig+Bn0BEhdpeonGx0SKKrpiNwIJZc z2r70CvQhowVqhKLODj8GhFMKmdFSemR1HJpgmoWCbWrgAN9Lh7lbyd0FTVgz5lbIZvyU Np3DPMXQCXYaSQI54S9rYvBeY95wmYHIBrPteQEFSAKJJYagooZVr7i3WXiewfeu8TtPg QhNTdURVaxHFNkJ/uXVgeMgMDx199fIE/X/deUhixCqSjvJBpnp4SIvnnS/bFR7ZpydNQ T7m3EnzM5Xv/FM699RlHcUt22n/RGXDNZW5R7KT4eTgw3Oqk5424Z3PMsxycMpTAqgA== 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=cAFoaaUX; 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 06A8D606A336; Sun, 29 Nov 2026 00:07:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 06A8D606A336 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=cAFoaaUX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org; s=2025; t=1795910855; bh=xZ3eqTZp6NQwb56oG2R4X/2aLhW4tkf227FdSJvTBLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cAFoaaUXQCsIbsoHw0V+RLWtkOswXDBrA3GpXMpDVYKXCAfB8bJM6Yr4GVokFbmmE gPI7D0c/LwCxjdD8yCDuuCH0KWFjGQaC6/Y54YtMTDg6WTbkX4Dv6u29M1NZoeO+IJ 1rUOXQdHoIL7QlyJEBQ8IVOsHC4OCxdCv0EYa3QCDO8uQRaqDOsd85QMfFYFTjjAVo rJ0htS/EPHPy2Bt27F32mgwvkcCyLv1YavtrQUDuu878PORUYnkrH4QpS7oEivRn/f aJZlmSsjIIsrf56etekHbGCQkTWSPAHYnr1kcMN/HPE+cfsRxCenV3Mbkqtr5qC/lq EPgjhWBrJbDMw== Received: from localhost.localdomain (mail-agni [217.70.190.124]) by mail.netfilter.org (Postfix) with ESMTPSA id BF35E601B7; Sun, 29 Nov 2026 01:07:34 +0100 (CET) From: Pablo Neira Ayuso 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/14] netfilter: conntrack: wait for RCU readers before freeing the hash Date: Sun, 29 Nov 2026 01:07:14 +0100 Message-ID: <20261129000724.797425-5-pablo@netfilter.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261129000724.797425-1-pablo@netfilter.org> References: <20261129000724.797425-1-pablo@netfilter.org> X-Mailing-List: netdev@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