From: Pablo Neira Ayuso <pablo@netfilter.org>
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 07/14] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack
Date: Sun, 29 Nov 2026 01:07:17 +0100 [thread overview]
Message-ID: <20261129000724.797425-8-pablo@netfilter.org> (raw)
In-Reply-To: <20261129000724.797425-1-pablo@netfilter.org>
From: Yiran Qiu <eritque-arcus@ikuyo.dev>
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>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
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
next prev parent reply other threads:[~2026-11-29 0:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 0:07 [PATCH net 00/14] Netfilter fixes for net Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 01/14] netfilter: conntrack: prevent helper extension relocation Pablo Neira Ayuso
2026-11-29 0:14 ` netdev-bot+sinfo
2026-11-29 0:16 ` Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 02/14] netfilter: xt_IDLETIMER: restrict to init_net Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 03/14] netfilter: synproxy: prevent unbounded recursion in transmit path Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 04/14] netfilter: conntrack: wait for RCU readers before freeing the hash Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 05/14] netfilter: conntrack: attach generated TCP resets as ESTABLISHED Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 06/14] netfilter: nf_conntrack: limit expectation master chain depth Pablo Neira Ayuso
2026-11-29 0:07 ` Pablo Neira Ayuso [this message]
2026-11-29 0:07 ` [PATCH net 08/14] netfilter: bridge: detach conntrack template on invalid IP frames Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 09/14] netfilter: synproxy: fix double tsoff application in server ACK TSecr Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 10/14] netfilter: nf_tables: only disable tables on a dormant transition Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 11/14] netfilter: nf_tables: add NFT_HOOK_UNREGISTERED and use it Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 12/14] netfilter: nf_tables: unbind flowtable on hook release Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 13/14] netfilter: nf_tables: flush destroy work from flowtable netdev event handler Pablo Neira Ayuso
2026-11-29 0:07 ` [PATCH net 14/14] netfilter: ipv6: stop the conntrack fragment search at AH Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129000724.797425-8-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox