Netdev List
 help / color / mirror / Atom feed
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 08/14] netfilter: bridge: detach conntrack template on invalid IP frames
Date: Sun, 29 Nov 2026 01:07:18 +0100	[thread overview]
Message-ID: <20261129000724.797425-9-pablo@netfilter.org> (raw)
In-Reply-To: <20261129000724.797425-1-pablo@netfilter.org>

From: Luxiao Xu <rakukuip@gmail.com>

A bridge rule such as nftables `ct zone set` can attach a conntrack
template with IP_CT_NEW to an skb before nf_ct_bridge_pre() runs. When
a frame has an ETH_P_IP or ETH_P_IPV6 protocol, nf_ct_bridge_pre()
performs header pull, length trimming, and nf_ct_br_ip_check() /
nf_ct_br_ipv6_check() validation before invoking defragmentation and
nf_conntrack_in().

If any of those six checks fails, nf_ct_bridge_pre() returns NF_ACCEPT
immediately without passing the skb to nf_conntrack_in(), which would
normally clear skb->_nfct and drop the template reference on parse
failure. Because nft_ct_get_eval() evaluates NFT_CT_STATE from ct and
ctinfo before rejecting template objects, the retained template causes
malformed, truncated, or wrong-version IP frames to match `ct state new`
instead of `ct state invalid`.

Jump to a shared error path that calls nf_reset_ct(skb) before returning
NF_ACCEPT on all IPv4 and IPv6 header/length rejection paths so the
template reference is released and the frame is treated as invalid,
even on kernels without downstream template filtering in ct readers.

Fixes: 3c171f496ef5 ("netfilter: bridge: add connection tracking system")
Cc: stable@vger.kernel.org
Reported-by: VEGA <vega@nebusec.ai>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/3cf187b612fd78f8835fa9dad870326ce380f82f.1785479514.git.zhilinz@nebusec.ai
Signed-off-by: Luxiao Xu <rakukuip@gmail.com>
Signed-off-by: Ren Wei <weir@nebusec.ai>
Acked-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/bridge/netfilter/nf_conntrack_bridge.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/net/bridge/netfilter/nf_conntrack_bridge.c b/net/bridge/netfilter/nf_conntrack_bridge.c
index 8c83dc05114b..11d6183fb11d 100644
--- a/net/bridge/netfilter/nf_conntrack_bridge.c
+++ b/net/bridge/netfilter/nf_conntrack_bridge.c
@@ -257,28 +257,28 @@ static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb,
 	switch (skb->protocol) {
 	case htons(ETH_P_IP):
 		if (!pskb_may_pull(skb, sizeof(struct iphdr)))
-			return NF_ACCEPT;
+			goto invalid;
 
 		len = skb_ip_totlen(skb);
 		if (pskb_trim_rcsum(skb, len))
-			return NF_ACCEPT;
+			goto invalid;
 
 		if (nf_ct_br_ip_check(skb))
-			return NF_ACCEPT;
+			goto invalid;
 
 		bridge_state.pf = NFPROTO_IPV4;
 		ret = nf_ct_br_defrag4(skb, &bridge_state);
 		break;
 	case htons(ETH_P_IPV6):
 		if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
-			return NF_ACCEPT;
+			goto invalid;
 
 		len = sizeof(struct ipv6hdr) + skb_ipv6_payload_len(skb);
 		if (pskb_trim_rcsum(skb, len))
-			return NF_ACCEPT;
+			goto invalid;
 
 		if (nf_ct_br_ipv6_check(skb))
-			return NF_ACCEPT;
+			goto invalid;
 
 		bridge_state.pf = NFPROTO_IPV6;
 		ret = nf_ct_br_defrag6(skb, &bridge_state);
@@ -293,6 +293,10 @@ static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb,
 		return ret;
 
 	return nf_conntrack_in(skb, &bridge_state);
+
+invalid:
+	nf_reset_ct(skb);
+	return NF_ACCEPT;
 }
 
 static unsigned int nf_ct_bridge_in(void *priv, struct sk_buff *skb,
-- 
2.47.3


  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 ` [PATCH net 07/14] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack Pablo Neira Ayuso
2026-11-29  0:07 ` Pablo Neira Ayuso [this message]
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-9-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