Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>, stable@vger.kernel.org
Subject: [PATCH nf-next v4 7/9] netfilter: conntrack: confirm ct when helper validation fails
Date: Thu,  3 Dec 2026 16:58:10 +0100	[thread overview]
Message-ID: <20261203155812.8873-8-fw@strlen.de> (raw)
In-Reply-To: <20261203155812.8873-1-fw@strlen.de>

nf_confirm_cthelper() is called via nf_conntrack_update() when a packet
that was queued to a userspace conntrack helper is reinjected with an
ACCEPT verdict.

When the l4 header can't be located -- the packet is a fragment, or the
header chain is malformed, or userspace rewrote the packet such that it
no longer matches the conntrack tuple -- the function returns NF_ACCEPT
without confirming the conntrack entry.

This is wrong for packets that were queued from the confirm hook itself,
which is the expected case: the userspace helper queues the packet from
within nf_confirm(), i.e. before the conntrack entry was added to the
hash table.  On reinject there is no later hook that could confirm the
entry, so the skb leaves the host with an unconfirmed conntrack entry
attached.

The entry is never inserted into the conntrack hash table, so later
packets of the same flow create new (unconfirmed) entries and nat,
helper and expectation state is lost.

Skip helper and seqadj processing as before, but fall through to
nf_conntrack_confirm().

Problem located during an LLM-assisted review of the helper hardening
series; verified by inspection.  No reproducer: it needs a userspace
conntrack helper whose verdict rewrites the reinjected packet into a
state that fails header validation.  As this isn't supposed to be
possible anymore, this patch should not have an observable effect.

Fixes: ee04805ff54a ("netfilter: conntrack: make conntrack userspace helpers work again")
Cc: stable@vger.kernel.org
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/netfilter/nf_conntrack_core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 2ceb198c70ac..03c800f29ad5 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2234,8 +2234,13 @@ static int nf_confirm_cthelper(struct sk_buff *skb, struct nf_conn *ct,
 		return NF_ACCEPT;
 
 	if (!nf_confirm_get_protoff(skb, nf_ct_net(ct), ct, ctinfo, &protoff,
-				   &pnum))
-		return NF_ACCEPT;
+				   &pnum)) {
+		/* Helper and seqadj are skipped, but the ct must still be
+		 * committed: the packet was queued from nf_confirm(), no
+		 * later hook will confirm it.
+		 */
+		return nf_conntrack_confirm(skb);
+	}
 
 	if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) &&
 	    !nf_is_loopback_packet(skb)) {
-- 
2.56.1


      parent reply	other threads:[~2026-12-03 15:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261203155812.8873-1-fw@strlen.de>
2026-12-03 15:58 ` [PATCH nf-next v4 2/9] netfilter: nf_conntrack_h323: register H.245 helper as TCP Florian Westphal
2026-12-03 15:58 ` [PATCH nf-next v4 3/9] netfilter: conntrack: refactor helper call logic in nf_confirm() Florian Westphal
2026-12-03 15:58 ` [PATCH nf-next v4 4/9] netfilter: conntrack: verify L4 protocol before calling helper Florian Westphal
2026-12-03 15:58 ` [PATCH nf-next v4 5/9] netfilter: conntrack: replace open-coded helper invocation Florian Westphal
2026-12-03 15:58 ` [PATCH nf-next v4 6/9] netfilter: conntrack: harden helper invocation with tuple revalidation Florian Westphal
2026-12-03 15:58 ` 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=20261203155812.8873-8-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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