🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #18043

[PATCH nf] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack

#18043
From: Yiran Qiu
Date: Tue, 17 Nov 2026 18:11
108 lines
13920 bytes
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 <eritque-arcus@ikuyo.dev>
---
Tested tree: mainline 141b164bbe18 (v7.4-rc3-133-g141b164bbe18).

The reproducer fills the namespace's conntrack table so that
early_drop() recycles slots, and puts 300 non-matching rules in front
of the helper rule, which delays the helper's krealloc() by about 16us
after the new conntrack's refcount_set(); four threads read
/proc/net/nf_conntrack.  The guest had 8 vCPUs.  The build needs
CONFIG_SLUB_RCU_DEBUG=n: with it, KASAN defers the reuse of the
conntrack slot by a grace period and the race cannot happen.  The
counters saw 136 and 88 recycled unconfirmed conntracks pinned by
ct_seq_show() in the two 60-minute runs; with this patch 98 were
pinned and none reached the printer.  From the first run:

  BUG: KASAN: slab-use-after-free in ct_seq_show+0x5ea/0x830
  Read of size 1 at addr ffff8880108f0a05 by task payload/218
  CPU: 7 UID: 1000 PID: 218 Comm: payload Not tainted 7.4.0-rc3-kasan-hunt+ #16 PREEMPTLAZY
  Call Trace:
  [...]
   ct_seq_show+0x5ea/0x830
   seq_read_iter+0x600/0x7e0
   seq_read+0x203/0x2e0
   proc_reg_read+0xec/0x150
   vfs_read+0x144/0x610
  [...]
  Allocated by task 213:
  [...]
   krealloc_node_align_noprof+0x131/0x3c0
   nf_ct_ext_add+0x110/0x380
   nf_ct_ecache_ext_add+0xa9/0x150
   init_conntrack.isra.0+0x444/0xb90
   nf_conntrack_in+0x652/0xac0
  [...]
  Freed by task 213:
  [...]
   kfree+0x113/0x480
   krealloc_node_align_noprof+0x158/0x3c0
   nf_ct_ext_add+0x110/0x380
   nf_ct_helper_ext_add+0x17/0x50
   nft_ct_helper_obj_eval+0x1e5/0x3a0
  [...]
  The buggy address is located 5 bytes inside of
   freed 128-byte region [ffff8880108f0a00, ffff8880108f0a80)

Offset 5 is ext->offset[NF_CT_EXT_TSTAMP], which ct_show_delta_time()
reads even when the timestamp extension is not present.  An earlier
build with a udelay() added in seq_print_acct() hit the same free
there.

6.12.y has the same code (read in v6.12.118, not run there); the hunk
needs its context adjusted, as c5ba345b2d35 is not in that branch.
Reproducer available on request.

 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.56.1
Technical Details
Message-ID: <20261117181140.133758-1-eritque-arcus@ikuyo.dev>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365529-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365529-linux-kernel-netdev=dewy.ru
From: eritque-arcus@ikuyo.dev (Yiran Qiu)
Newsgroups: linux.kernel.netdev
Subject: [PATCH nf] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack
Date: Tue, 17 Nov 2026 13:11:40 -0500
Organization: Usenet Network
Message-ID: <20261117181140.133758-1-eritque-arcus@ikuyo.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="2397343"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:lrvqvBkrlyxwlaYX5+7D5lJ2VwU= sha256:l7FxzvYYch8TTMdBaF/qZxevzzGu6S+YDMcOqG6XP0c= sha1:gUPfaDBr7ZH7hsdgGDz2GtTohWY= sha256:V+15zdRuZsPvHs4ic+sJINd9Jhydd/7ehb4uLbz2CVA=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 87AC111503B; Tue, 17 Nov 2026 21:13:01 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.75
X-Spam-Status: No, score=-2.75 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=ikuyo.dev
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XHX9mHp4xijK; Tue, 17 Nov 2026 21:12:57 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-365529-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=ikuyo.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 679E5115009; Tue, 17 Nov 2026 21:12:49 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 2E7EE2A007; Tue, 17 Nov 2026 18:12:46 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794939165; b=ANG6RrkdOQqmGmrRZYfABy6EMXHE7a8wCd+YP/RPKccoWu8Znc3n1g9gw3iIavq3zoZX wKVnBvV/Nq66zX7U2vVFSt8PcH30IHMmiynPAiPU7m2lipWS0Es8Zpi44TqTQq2JwwXes XDsHfKCFaDbGEM9pNPeAKEykaImlUNot6nkyW5NmtkWfASco/c6zKYXbaDDmqJTVvlg55 A9cqHGBeepeDZSWTkakE1fU5lIKpSAHnmxxB+6y08q9cKzPa/OjHzt7iS1CguytWq/qeb ntb8/3PF1OzAUyeW6k7bL8PzuJ9iIVcO6sQvEGdjFJOHWbDVoWGO2qtIdtM7Xe6jAJw==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794939165; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To: Cc:Subject:Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Transfer-Encoding; bh=9ncxxBe7GKoTncLOaM2IGmBRr5NiBhBbaaIsvj0fMI0=; b=uk8+fi1E8T9JgjTn/aPXPCqiWP78o4injfGVPM+CRQg7Z9DF0nzIzOC8vJJ6UH76jfNx Yr2w/qsvMRynCc0B6U3laacQGBplu1vyN+GRpcU6ZRPtB9NpkZikfsC5HPMUMmy9LP1UR vNWQsTIR80B3NOAJhAP+VRr6vOOh22wYh7Np0b89Fbq2La0EfY0TZK911i35qrW9Qbdkc SKblO6g2RlanrlFhZK7Nwrh2LO0PPh8KtQmBhxuDLj+qJL+2HYBth5t8cTCZL57C3E4jb nCmkwOaryxjZn/8ec9x0x3I9NDmj2bRB+IF1sfJAOLFp8Yx81MSijOuCQsnK5tTUN6A==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" header.d=ikuyo.dev header.i=@ikuyo.dev header.a=rsa-sha256 header.s=s1 header.b=fNM88yJn; dmarc=pass header.from=ikuyo.dev; spf=pass smtp.mailfrom=ikuyo.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DFB4606A339; Tue, 17 Nov 2026 18:12:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ikuyo.dev header.i=@ikuyo.dev header.a=rsa-sha256 header.s=s1 header.b=fNM88yJn
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.15
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794939154; b=Mvu0viNeowpwv50FpjPS8wqk+HK8Dn1Efcf1kAD4T6WAarYN/XSJl2lCNLyn+Xqm5kTX B8w/Z40v1YaE6AMweHEBTEeX5O7Oqiq27ZEmM6iENYLqFgdik8jy/nVSdPK3tVkn1OY0v zdUoGgLArw00sJLWxMW46EPvQs4n3gQP+EOwHaNKq2UT8ie0n+BP8v9p9HJ16ase54vN0 cY+HBBTq0C9VU23qyD57+Df8qvuAcXgd7JLNDjvkQvK77i2M+9gsGNOaYrICsuNl9pQct vGyLyOAKzilUHLtc+8OT4DIrSTvpPXeCfclv065gcCu6LLWOvqKaUe3n7YjPI+SQvsQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794939154; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=9ncxxBe7GKoTncLOaM2IGmBRr5NiBhBbaaIsvj0fMI0=; b=Ncv1tNOMp7ec2UAQSrVYrJBhtWlWZqeTr5Juz+TyS4hiuOaV9gUQBBuvpEqE438afpZi AtrZ46e1oz9W+vGmMRrC+3kn3yZRDvFeyO/XdyO9XbrMxSJ31+QKvNN9AzDX6AOEp2S1l VE0vhACEH49+v64bM2ZSI+PG4gXsZs1Br57DBfiImx/pIGfWWXfL/VWlo4Dw5ZaE7JFET aR5UWQ1z3hTnK+COqazrPdBL9YNMNaKP6BX8GXio4ph3K/ASxLpNbjaBCa4NLAW4l7FOq g36bkDMTVZKpuoFTMVvUAjAk2qLSQ0vnGmxY7tuI31tsIWhGT0YzH9nCVR1P75jMdwA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=ikuyo.dev; spf=pass smtp.mailfrom=ikuyo.dev; dkim=pass header.d=ikuyo.dev header.i=@ikuyo.dev header.a=rsa-sha256 header.s=s1 header.b=fNM88yJn; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.15
X-Received: from sender6-op-o15.zoho.com (sender6-op-o15.zoho.com [165.173.180.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AC7E606A32C; Tue, 17 Nov 2026 18:12:33 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0AC7E606A32C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ikuyo.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ikuyo.dev
X-ARC-Seal: i=1; a=rsa-sha256; t=1794939122; cv=none; d=zohomail.com; s=zohoarc; b=hp8n2l4ek/mo5GAPuuSxk7LVgM8yT3mAftdKcYrOIGIbcEXtGLowgAWJLyGaNIob2gUtMxzjXQh8xhRcJYxCUG769kwzk6jvQNnJZK/EP1R6eOUXITliEfWLeJ620Edlw4ZOx+kaGPx1rQHzDfJo8vyOFEnkIrfzqIoEcWMp34E=
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794939122; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=9ncxxBe7GKoTncLOaM2IGmBRr5NiBhBbaaIsvj0fMI0=; b=e4NM1yQ7WNy6HPaXw4SgU1tXQjwsPqwM0wjV6o8i1JBUmlgxTcxwtd3VFYXahZpgRrj35gCZKTmjwvhHjSXORdJnat8luILPHVhnEDniKfHWNRcBYSeGwi2kndj4kMrhLUTte5iE0dEkOrc0F1K4AR3P7ukDni+0HcgDlDa9MUE=
X-ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass  header.i=ikuyo.dev; spf=pass  smtp.mailfrom=eritque-arcus@ikuyo.dev; dmarc=pass header.from=<eritque-arcus@ikuyo.dev>
X-DKIM-Signature: a=rsa-sha256; b=fNM88yJnVxYcPgtCaJwt4KjJBT2EjIvyyUfbe2xy2XoN4R2mZXTHWsw+bszjty6sGZmpgNsW7eTpFW4J7FvQkl7Nw9hUJnthEkQ7Kr7t34StOSiXkS+xOhF78GoKEDjhK0R+QR+f3+qQa3sohe4/Cz5CvhUbZaDBsx52hjAjrn7ATgYSmIIU7Z8Lv2jz2XaolYqITz6q0Lt/NHvljKaXuGQmu4W4p07v96M4Nc6dnt1LxH9dbVIPGWeEt0wJ4IwxFyS5P1tVi5iWWrc6wn+Dg8U68H18EtG37fmeaJX1xk1ewxdKntzWxncoUEhjrredP4ZGOT315rnzMSoJttgDKw==; c=relaxed/relaxed; s=s1; d=ikuyo.dev; v=1; bh=9ncxxBe7GKoTncLOaM2IGmBRr5NiBhBbaaIsvj0fMI0=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc;
X-Received: by smtp.zohomail.com with SMTPS id 1794939120565329.8648114396691; Tue, 17 Nov 2026 10:12:00 -0800 (PST)
X-Cc: phil@nwl.cc, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yiran Qiu <eritque-arcus@ikuyo.dev>, stable@vger.kernel.org
X-Mailer: git-send-email 2.56.1
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-Received-Bytes: 13634