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=1796073952; b=jcgROH7c/xB3qVut00P77OYKIXSuaMDCh1oGO3gzNuSXMfXOuA2/J1S7X/SgCUz3moif ksHrfEwtytlxkDMs2aFA5ZWLxhFxKeZev0I4gk2QBT+8DQaSv8ah5QHtuBjPSyZ/O1o0G 75yDTdCYg7EERXFEQ9quufiNFXY3jsnWPA+/yKczuf8LpqcawEDZtM5CB2LslrhcTTlEi vvhIEGMoYznZIs6updd5ao3eNt2Gp9EQluLWcHj4C+kl3bQwcn6dDgPhrrcY8c/493ZQA 9kS0KZiRJ6XBj90gijhx4Elxj2ENQJ8NA6SH3NFPwcarjwv0ypRWTrQyORc9nGwTT1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073952; 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=tZfQIu9jznMqicexxLbxozvEsFtKTGoIZqpfz9Cw35w=; b=GdsEIumE5+D0+fJoVIW/g4G2tiSB8dy8HGxCqYXQvw4Aa8nQIXbP2uxXAhFhZzE9RJgJ RKKt/kJ5B7g5hVdIAMjLvR6KyA6ODuDkdBNcAlS4XpaxayiSLyjEsDMuTTqBTAZpeAeKf CF1WZRN54R0XMP+7ck9owV0SuQoGSibO8pxM3jFXcBM2nGJLGmMxS8ncNbkqEct4PVpPX 1zAVE5loYB+GN2IfVp3sbIctIS4Wlblkb1uPfuhlJShEyHPGqQhw+zcvUbzVs2e5oZLxI vTprTFQFWPFH5aPpbyYL/M1vcE4Z13kLrALvcGdcTbSDnUZqcsNS+3gTf1ArdiKDakg== 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=CH5CdiGi; 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 D27BC606A327 for ; Mon, 30 Nov 2026 21:25:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D27BC606A327 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=CH5CdiGi DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org; s=2025; t=1796073950; bh=tZfQIu9jznMqicexxLbxozvEsFtKTGoIZqpfz9Cw35w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CH5CdiGir4616pwj/sT1bdvn4cF8A/s1Up56iKKzwHW3DYIya+w4kcnpY16gDItAI PQErRCsoRz1ImapM4xtq+fPsFmlh28I0CRojmc6NTONm1++KF7e9hUlW+JROGxq/4l 3PeGHJaHq9/DT8/bUHvXrwrCeKCXuftLv+k2l2SsRhRZEcIcciSuIVNUjP+/q9zkok EuchnPEihP123YgSo+UGNhPU36TbWPjhxyMiUGuC+DM9bgES8YejbPqYYQTVRZmvWW gv3LDMW0Jmc9KIUNtTHpQfoy1JGX+zvxt7ND+nbQzUYEZwEQUOgRzCqdWYJk5bC/Ip jK7TyDGFBLuwQ== Received: from localhost.localdomain (mail-agni [217.70.190.124]) by mail.netfilter.org (Postfix) with ESMTPSA id 2768660088 for ; Mon, 30 Nov 2026 22:25:50 +0100 (CET) From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Subject: [PATCH net 07/10] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack Date: Mon, 30 Nov 2026 22:25:36 +0100 Message-ID: <20261130212539.992130-8-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: Yiran Qiu ct_seq_show() takes a reference on a conntrack it found by a lockless walk of the hash table, but never checks that the conntrack is confirmed. nf_conntrack is SLAB_TYPESAFE_BY_RCU, so between ct_get_next() and refcount_inc_not_zero() the entry can be freed and its slot reused by init_conntrack() for a new, unconfirmed conntrack. The increment then succeeds and the dump prints a conntrack that is not in any table. nf_ct_key_equal(), gc_worker_skip_ct() and early_drop() reject unconfirmed entries for this reason. Since commit 2ad9d7747c10 ("netfilter: conntrack: free extension area immediately") this is also a use-after-free. An unconfirmed conntrack can still grow its extension area, for example when an nft ct helper object attaches a helper, and nf_ct_ext_add() then frees the old ct->ext through krealloc(). seq_print_acct() and ct_show_delta_time() read ct->ext without a lock, so the dump can read the freed buffer and print what it finds there as counters or a time delta. Skip entries that are not confirmed. Found with afb-afl, an LLM-driven kernel audit/repro pipeline; the fix and this changelog were also drafted with LLM assistance. Reproduced on a KASAN build of mainline (v7.4-rc3+) that carried timing counters in ct_seq_show() (two ktime_get() per entry) but no added delay: an unprivileged user in its own user and network namespace churns UDP flows through an nft ct helper object while reading /proc/net/nf_conntrack, and KASAN reported a slab-use-after-free in ct_seq_show() after 9 and 41 minutes in two runs. The same build with this patch ran the reproducer for 60 minutes with no report. With only this patch applied to a KASAN build, the conntrack_resize.sh selftest, which compares /proc/net/nf_conntrack with ctnetlink dumps, passed in three runs. Fixes: ea781f197d6a ("netfilter: nf_conntrack: use SLAB_DESTROY_BY_RCU and get rid of call_rcu()") Cc: stable@vger.kernel.org Signed-off-by: Yiran Qiu Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_standalone.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c index d88a10230862..299691d7ac1e 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -314,6 +314,9 @@ static int ct_seq_show(struct seq_file *s, void *v) /* load ->status after refcount increase */ smp_acquire__after_ctrl_dep(); + if (!nf_ct_is_confirmed(ct)) + goto release; + if (nf_ct_should_gc(ct)) { struct ct_iter_state *st = s->private; -- 2.47.3