Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, 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: Re: [PATCH net 08/10] netfilter: bridge: detach conntrack template on invalid IP frames
Date: Tue, 01 Dec 2026 22:45:23 +0000	[thread overview]
Message-ID: <179616512327.3146.16191156456927532457@kernel.org> (raw)
In-Reply-To: <20261130215141.1009148-9-pablo@netfilter.org>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In nf_ct_bridge_pre()
  (net/bridge/netfilter/nf_conntrack_bridge.c), the patch changes the…

--

netfilter: bridge: detach conntrack template on invalid IP frames

This makes nf_ct_bridge_pre() jump to a shared error path when the IPv4
or IPv6 header pull or validation checks fail. That path calls
nf_reset_ct(), so a conntrack template attached by an earlier bridge rule
is released and the frame is treated as ct state invalid. The patch also
changes a failed pskb_trim_rcsum() to return NF_DROP instead of NF_ACCEPT.

Closes: https://sashiko.dev/#/patchset/3cf187b612fd78f8835fa9dad870326ce380f82f.1785479514.git.zhilinz@nebusec.ai

> diff --git a/net/bridge/netfilter/nf_conntrack_bridge.c b/net/bridge/netfilter/nf_conntrack_bridge.c
> index 8c83dc05114ba..aa1e01213e842 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;
> +			return NF_DROP;

[Severity: Low]

The commit message says:

  [ While at it, drop packet if pskb_trim_rcsum() fails, when memory is
    exhausted. --pablo ]

Is memory exhaustion the only way this call can fail? For a
CHECKSUM_PARTIAL skb, pskb_trim_rcsum_slow() can return -EINVAL without
allocating anything:

net/core/skbuff.c:pskb_trim_rcsum_slow() {
    ...
	} else if (skb->ip_summed == CHECKSUM_PARTIAL) {
		int hdlen = (len > skb_headlen(skb)) ? skb_headlen(skb) : len;
		int offset = skb_checksum_start_offset(skb) + skb->csum_offset;

		if (offset + sizeof(__sum16) > hdlen)
			return -EINVAL;
	}
    ...
}

pskb_trim_rcsum_complete() can also return -EFAULT. This happens for
CHECKSUM_COMPLETE skbs with unreadable frags when len > skb_headlen(skb).

Both failures come from packet contents and layout, not from memory
pressure.

Here, len comes straight from the unvalidated iph->tot_len, or from
payload_len on the IPv6 path. nf_ct_br_ip_check() and
nf_ct_br_ipv6_check() have not checked it yet. So can the same malformed
header now get a different verdict depending on skb->ip_summed?

Take a bridged non-GSO IPv4 frame whose tot_len is smaller than ihl * 4:

  CHECKSUM_PARTIAL:
    pskb_trim_rcsum() -> pskb_trim_rcsum_slow() returns -EINVAL
    -> NF_DROP

  CHECKSUM_NONE / CHECKSUM_UNNECESSARY:
    pskb_trim_rcsum() succeeds
    nf_ct_br_ip_check() fails -> goto invalid
    -> nf_reset_ct(), NF_ACCEPT

A tap or veth sender can produce such CHECKSUM_PARTIAL frames by using a
virtio_net_hdr with NEEDS_CSUM. The IPv6 trim path has the same ordering.

The commit body also says the shared error path covers "all IPv4 and
IPv6 header/length rejection paths". The two trim-failure paths don't
take it. With Cc: stable, frames in these cases that used to be bridged
are now dropped.

Dropping on trim failure matches ip_rcv_core() and br_validate_ipv4().
Both drop on any pskb_trim_rcsum() failure, so well-formed traffic should
not be affected.

Could the note be updated to cover these non-ENOMEM failures? Another
option would be to run the header/length checks before the trim. Then
every malformed header reaches the invalid label, and NF_DROP is kept for
real trim failures.

>  
>  		if (nf_ct_br_ip_check(skb))
> -			return NF_ACCEPT;
> +			goto invalid;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130215141.1009148-2-pablo%40netfilter.org

  reply	other threads:[~2026-12-01 22:45 UTC|newest]

Thread overview: 17+ 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 ` [PATCH net 07/10] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack Pablo Neira Ayuso
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 [this message]
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

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=179616512327.3146.16191156456927532457@kernel.org \
    --to=netdev-bot+sashiko@kernel.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 \
    --cc=pablo@netfilter.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