mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Arges <carges@cloudflare.com>
To: netdev-bot+sashiko@kernel.org
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	 pabeni@redhat.com, horms@kernel.org, dsahern@kernel.org,
	idosch@nvidia.com,  june@cloudflare.com, danjones@cloudflare.com,
	jbrandeburg@cloudflare.com,  josef@toxicpanda.com,
	mason@kernel.org, kernel-team@cloudflare.com,
	 netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@kernel.org
Subject: Re: [PATCH] net: prevent receive header offset overflow during decapsulation
Date: Wed, 18 Nov 2026 19:40:01 -0600	[thread overview]
Message-ID: <av5RgJZR2HKzAN2D@20HS2G4> (raw)
In-Reply-To: <179502356763.3136.15330216541876894208@kernel.org>

On 2026-11-18 17:39:27, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
> 
> Critical: 0 · High: 1 · Medium: 0 · Low: 0
> 
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
> 
> - [High] The new SKB_MAX_RX_HEADROOM (32 KiB) checks run in only three
>   places: when __netif_receive_skb_core() is entered…
> 
> --
> 
> net: prevent receive header offset overflow during decapsulation
> 
> This patch limits receive headroom to 32 KiB (SKB_MAX_RX_HEADROOM). The
> goal is to keep the 16-bit skb header offsets from being truncated after
> repeated decapsulation. The check runs on entry to
> __netif_receive_skb_core() and at the resubmit points of
> ip_protocol_deliver_rcu() and ip6_protocol_deliver_rcu(), and drops
> packets with the new SKB_RX_HEADROOM drop reason.
> 
> [ ... ]
> 
> > diff --git a/net/core/dev.c b/net/core/dev.c
> > index 3c58db732761a..6140fd9d11cd0 100644
> > --- a/net/core/dev.c
> > +++ b/net/core/dev.c
> > @@ -6223,6 +6223,10 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc,
> >  	trace_netif_receive_skb(skb);
> >  
> >  	orig_dev = skb->dev;
> > +	if (unlikely(skb_headroom(skb) > SKB_MAX_RX_HEADROOM)) {
> > +		drop_reason = SKB_DROP_REASON_SKB_RX_HEADROOM;
> > +		goto drop;
> > +	}
> 
> [Severity: High]
> 
> This check runs once, when __netif_receive_skb_core() is entered. That is
> before the another_round label, sch_handle_ingress(), vlan_do_receive()
> and the rx_handler call.
> 
> Can headers stripped later in the same receive pass still push the 16-bit
> header offsets past U16_MAX?
> 
> For example, tc act_mpls with TCA_MPLS_ACT_POP calls skb_mpls_pop() once
> per action. Each call stores the current headroom into the u16 header
> fields:
> 
> net/core/skbuff.c:skb_mpls_pop() {
>     ...
> 	__skb_pull(skb, MPLS_HLEN);
> 	skb_reset_mac_header(skb);
> 	skb_set_network_header(skb, mac_len);
>     ...
> }
> 
> Outside CONFIG_DEBUG_NET, the only guard in those helpers is
> DEBUG_NET_WARN_ON_ONCE(), so the value gets truncated silently.
> 
> The number of pops per pass doesn't look bounded:
> 
>   - a filter can hold up to 32 actions
>   - a filter whose action control is continue returns a negative result,
>     and __tcf_classify() moves on to the next tcf_proto without counting
>     it toward max_reclassify_loop (that limit only covers the
>     TC_ACT_RECLASSIFY / TC_ACT_GOTO_CHAIN reset path)
>   - about 512 matchall or flower filters with 32 pops each comes to
>     roughly 16K pops in one pass
> 
> veth_setup() sets dev->max_mtu = ETH_MAX_MTU. A frame of about 65.5 KB
> carrying about 16K MPLS labels, sent with AF_PACKET on one veth end, would
> reach __netif_receive_skb_core() on the peer with about 30 bytes of
> headroom and pass this check.
> 
> tc ingress could then pop the labels while skb_ensure_writable() keeps
> pulling data from the frags into the linear head. At some point
> mac_header and network_header would wrap past U16_MAX.
> 
> After the wrap, the remaining skb_mpls_pop() calls would run memmove(),
> skb_postpull_rcsum() and skb_mod_eth_type() at the truncated offsets.
> ip_rcv_core() would then read ip_hdr() from stale bytes and set
> transport_header from that position. L4 code could then misparse the
> packet, for example in tcp_data_queue():
> 
> 	__skb_pull(skb, tcp_hdr(skb)->doff * 4);
> 
> Here doff comes from the wrong bytes, so could this wrap skb->len or hit
> the BUG() in __skb_pull()?
> 
> This setup needs only CAP_NET_ADMIN and CAP_NET_RAW in a netns owned by a
> user namespace.
> 
> Similar in-pass header strips look possible elsewhere:
> 
>   - openvswitch pop_mpls with recirculation, where
>     ovs_dp_process_packet() runs again without re-entering
>     __netif_receive_skb_core()
>   - bpf_skb_adjust_room() shrinking, which adds len directly to
>     mac_header and network_header
>

These additional paths can be addressed in a follow-up patchset. I'd
prefer to fix the currently known cases first.

> The commit message says:
> 
>     Together, these checks
>     prevent 16-bit header-offset truncation in cases of repeated
>     decapsulation.
> 
> Is that still accurate given these paths?
> 
> Would it be more robust to bound the offset where it is stored, either in
> the skb_set_*_header() / skb_reset_*_header() helpers or in the pop/shrink
> helpers, instead of only at the chosen re-entry points?
> 
> [ ... ]
> 
> -- 
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-prevent_rx_header_offset_overflow-v1-1-92a5be55f994%40cloudflare.com

If the checks were moved to where the offset is stored (using something like
skb_set_transport_header_careful()), then we could introduce potential
performance issues.

--chris

      reply	other threads:[~2026-11-19  1:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 14:32 Chris J Arges
2026-11-18 14:38 ` netdev-bot+sinfo
2026-11-18 17:39 ` netdev-bot+sashiko
2026-11-19  1:40   ` Chris Arges [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=av5RgJZR2HKzAN2D@20HS2G4 \
    --to=carges@cloudflare.com \
    --cc=danjones@cloudflare.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=jbrandeburg@cloudflare.com \
    --cc=josef@toxicpanda.com \
    --cc=june@cloudflare.com \
    --cc=kernel-team@cloudflare.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@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

all inboxes | Powered by JetHome®