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/10] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack
Date: Mon, 30 Nov 2026 22:51:38 +0100 [thread overview]
Message-ID: <20261130215141.1009148-8-pablo@netfilter.org> (raw)
In-Reply-To: <20261130215141.1009148-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-30 21:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 21:51 [PATCH net,v2 RESEND 00/10] Netfilter fixes for net Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 01/10] netfilter: conntrack: prevent helper extension relocation Pablo Neira Ayuso
2026-11-30 21:54 ` netdev-bot+sinfo
2026-11-30 21:56 ` Pablo Neira Ayuso
2026-12-01 22:10 ` patchwork-bot+netdevbpf
2026-12-01 22:45 ` netdev-bot+sashiko
2026-11-30 21:51 ` [PATCH net 02/10] netfilter: xt_IDLETIMER: restrict to init_net Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 03/10] netfilter: synproxy: prevent unbounded recursion in transmit path Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 04/10] netfilter: conntrack: wait for RCU readers before freeing the hash Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 05/10] netfilter: nft_synproxy: only handle pure SYN and ACK packets Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 06/10] netfilter: conntrack: limit master chain depth Pablo Neira Ayuso
2026-12-01 22:45 ` netdev-bot+sashiko
2026-11-30 21:51 ` Pablo Neira Ayuso [this message]
2026-11-30 21:51 ` [PATCH net 08/10] netfilter: bridge: detach conntrack template on invalid IP frames Pablo Neira Ayuso
2026-12-01 22:45 ` netdev-bot+sashiko
2026-11-30 21:51 ` [PATCH net 09/10] netfilter: synproxy: fix double tsoff application in server ACK TSecr Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 10/10] netfilter: nf_tables: only disable tables on a dormant transition Pablo Neira Ayuso
-- strict thread matches above, loose matches on Subject: below --
2026-11-30 21:25 [PATCH net,v2 00/10] Netfilter fixes for net Pablo Neira Ayuso
2026-11-30 21:25 ` [PATCH net 07/10] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack 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=20261130215141.1009148-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.