From: Florian Westphal <fw@strlen.de>
To: Vimal Agrawal <avimalin@gmail.com>
Cc: netfilter-devel@vger.kernel.org,
Pablo Neira Ayuso <pablo@netfilter.org>,
Jozsef Kadlecsik <kadlec@netfilter.org>,
coreteam@netfilter.org, Vimal Agrawal <vimal.agrawal@sophos.com>
Subject: Re: netfilter: nf_nat: race in nf_nat_setup_info() corrupts nat_bysource list (GPF / soft lockup)
Date: Mon, 17 Aug 2026 17:13:14 +0200 [thread overview]
Message-ID: <aoMlCi9pduIyddFU@strlen.de> (raw)
In-Reply-To: <CALkUMdRqwCXbA+9tSFgxxA=pBCAPymRbLBa-UXUi6PE1qytvAA@mail.gmail.com>
Vimal Agrawal <avimalin@gmail.com> wrote:
> I do see some conntrack updates passed nf_nat_initialized check in
> nf_nat_setup_info so ideally it should not do anything for the second
> or other run for the same conntrack.
> How about locking out the whole of nf_nat_setup_info on ct->lock. i..e
> spin_lock_bh(&ct->lock) at the start of the function and unlock before
> return.
It would be good to understand that this isn't a 3rd party module bug
first.
As I said, conntrack doesn't expect unconfirmed conntracks racing
on multiple CPUs.
Minimal hack (not even compile tested):
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -815,16 +815,12 @@ nf_nat_setup_info(struct nf_conn *ct,
&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
lock = &nf_nat_locks[srchash % CONNTRACK_LOCKS];
spin_lock_bh(lock);
- hlist_add_head_rcu(&ct->nat_bysource,
- &nf_nat_bysource[srchash]);
+ if (!test_and_set_bit(&ct->status, IPS_SRC_NAT_DONE_BIT))
+ hlist_add_head_rcu(&ct->nat_bysource,
+ &nf_nat_bysource[srchash]);
spin_unlock_bh(lock);
- }
-
- /* It's done. */
- if (maniptype == NF_NAT_MANIP_DST)
- ct->status |= IPS_DST_NAT_DONE;
- else
- ct->status |= IPS_SRC_NAT_DONE;
+ } else
+ set_bit(&ct->status, IPS_DST_NAT_DONE_BIT);
return NF_ACCEPT;
}
But its not enough, if we assume racing unconfirmed conntracks are now allowed, then
all places adding conntrack extensions are buggy, and all direct ct->status changes
(not using set_bit APIs) are buggy too.
prev parent reply other threads:[~2026-08-17 15:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-16 14:00 netfilter: nf_nat: race in nf_nat_setup_info() corrupts nat_bysource list (GPF / soft lockup) Vimal Agrawal
2026-08-16 14:25 ` Florian Westphal
2026-08-17 9:56 ` Vimal Agrawal
2026-08-17 15:13 ` Florian Westphal [this message]
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=aoMlCi9pduIyddFU@strlen.de \
--to=fw@strlen.de \
--cc=avimalin@gmail.com \
--cc=coreteam@netfilter.org \
--cc=kadlec@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=vimal.agrawal@sophos.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