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=1796075514; b=Je1cYwK9c0dzkyYYSWJwFPGBM7RM0O8Ix/PFDvHgk9TttOE0TijEy6TXwOXDw/OWipyD RqKENoNAjzLI8QDlZx3DCiq9IrqKuYlmhSMx8Gvd+wwOE7W9ohqmUFXFFu3SlJFIIY1vf fnqsthb2XOgsmnvYjfXwmYsNKjpMzcORIYfWORCZcj7eO+chkL/3Am5Wfh1TQF8vZI+GN 9+I/mynijDk9/6Ik1NiD+aYjGJeNQFVshBRAjo9Djpf3A1zSmwnKS0F3k+N+FuRrA8IqA ES6obEW93wXb2TP6Bx50wHz8fYp1FSzjbSjy2eNGJpfSeal9rhpK/FtfUoDMbNLyC0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796075514; 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=ug8/oMRf4g8X5fdB3RH89FiMr/lUuws9isJaJ5DnLWgmGKEBsjQjY/xJjUX7HgLFSDGe Eytf+iNIX75MyU6fRZdkea2htZ0GdzFkK0CiUttbOT4h1XCVwKcey6Hl9oa+n+di/HN8t Hslg9hHqUtqERC9AFSHz7IYpSA32VlfFlT859OLbNWlcmsnvlC/xpl4/A20AlN6WX+qyU it6AzutPzMXyKsWNnFw2XzeDx9a7M2OHdKFB1F7goq+lMRuWQUGNYubRB0C025h6UEpY0 MuIO8UA+kdIwO8Vdp2zIaaemVWWuKOc9Rk9b5aU3l5DEsVqHVZJqwPgfPAeFA/oLDag== 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=lvJ3QXFB; 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 C23DB606A680; Mon, 30 Nov 2026 21:51:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C23DB606A680 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=lvJ3QXFB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org; s=2025; t=1796075512; bh=xZ3eqTZp6NQwb56oG2R4X/2aLhW4tkf227FdSJvTBLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lvJ3QXFBuZvwKup0k8Bh4LZvXP5bgSmeCJcwzRlHUohhxN8DJvxzT6+F+ZGkgyxN8 TrtIbHNEmwSIZINV3cRtymhomP0gPjO3lKSF6E4aTveRw0sMf7Fd+zXsKCVvRO74x3 rkxQwtkYwRuPkj7hFy10l1HgNaWAYGIlFnA3YvXQ5oTekzrNHwO/tm0voFAUYLOcti /cuU3CqMlmfLvRHr1K1FFE8bcbWTqTSC8cUGYaNTuZVcunqaxf+D5Ey2MwNGwGX583 tGADficH1JGJPlMmI5DisMCDL22PbUSPU6Kc1u5D/dHxn3sB6PKg5/6GaT23vWHO2d mvTYTdpRLur9w== Received: from localhost.localdomain (mail-agni [217.70.190.124]) by mail.netfilter.org (Postfix) with ESMTPSA id 77FFA6007D; Mon, 30 Nov 2026 22:51:51 +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/10] netfilter: conntrack: wait for RCU readers before freeing the hash Date: Mon, 30 Nov 2026 22:51:35 +0100 Message-ID: <20261130215141.1009148-5-pablo@netfilter.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130215141.1009148-1-pablo@netfilter.org> References: <20261130215141.1009148-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