Netdev List
 help / color / mirror / Atom feed
From: zhuorao yang <alex000young@gmail.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>,
	Florian Westphal <fw@strlen.de>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>
Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	netdev@vger.kernel.org
Subject: [PATCH net] netfilter: conntrack: serialize helper extension allocation
Date: Tue,  1 Dec 2026 16:58:14 +0800	[thread overview]
Message-ID: <20261201085814.82573-1-alex000young@gmail.com> (raw)

Two CPUs can add the helper extension to the same unconfirmed conntrack
when shared skbs are evaluated concurrently.  nf_ct_ext_add() then calls
krealloc() on the same ct->ext from both CPUs.  If the first call moves
the extension allocation, the second call can double-free the old one.

Serialize nf_ct_helper_ext_add() with the conntrack lock.  The lock also
covers publishing IPS_HELPER_BIT and initializing the expectation list,
so a concurrent caller observes a fully initialized helper extension.

Fixes: 1a64edf54f55 ("netfilter: nft_ct: add helper set support")
Signed-off-by: zhuorao yang <alex000young@gmail.com>
---

Vulnerability report

Affected versions: Linux 7.4.0-rc5 at
  fe6ff8d5d675c01793b9f051d16055dd4aa75244; the helper-set path dates to
  v4.12.
Trigger conditions: CONFIG_NFT_CT and CAP_NET_ADMIN in the target
  network namespace. Two skbs must share the same unconfirmed conntrack
  and execute nft_ct_helper_obj_eval() concurrently on different CPUs.
  Existing accounting, timestamp, event-cache, or label extensions make
  the helper extension enlarge and relocate ct->ext.
Reproducer status: A QEMU KASAN harness forced two CPUs to enter
  nf_ct_helper_ext_add() on the same unconfirmed conntrack with a
  104-byte extension allocation. The unpatched kernel produced a double-
  free in krealloc_node_align_noprof. With the fix, 1000 synchronized
  two-CPU iterations completed without KASAN. The exact shared-skbs
  network path has not yet been shown without the test harness.
Reproducer material is intentionally withheld from this public message.

AI assistance: DeepSeek identified the issue and drafted the patch.
The submitter reviewed the code and certified the Developer Certificate
of Origin.

 net/netfilter/nf_conntrack_helper.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index c30ae3f203be..4d2dd88e74f3 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -184,11 +184,13 @@ nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)
 {
 	struct nf_conn_help *help;
 
+	spin_lock_bh(&ct->lock);
 	help = nf_ct_ext_add(ct, NF_CT_EXT_HELPER, gfp);
 	if (help) {
 		__set_bit(IPS_HELPER_BIT, &ct->status);
 		INIT_HLIST_HEAD(&help->expectations);
 	}
+	spin_unlock_bh(&ct->lock);
 	return help;
 }
 EXPORT_SYMBOL_GPL(nf_ct_helper_ext_add);
-- 
2.56.0


             reply	other threads:[~2026-12-01  9:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  8:58 zhuorao yang [this message]
2026-12-01  9:21 ` [PATCH net] netfilter: conntrack: serialize helper extension allocation 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=20261201085814.82573-1-alex000young@gmail.com \
    --to=alex000young@gmail.com \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=willemb@google.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