Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: rhkrqnwk98@gmail.com
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	willemb@google.com, horms@kernel.org, ast@kernel.org,
	daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
	sdf@fomichev.me, tehnerd@tehnerd.com
Subject: Re: [PATCH net] net: xdp: Fix skb->tail after bpf_xdp_adjust_tail() in generic mode
Date: Fri, 27 Nov 2026 12:58:56 +0000	[thread overview]
Message-ID: <179578433682.3135.10241295283064186673@kernel.org> (raw)
In-Reply-To: <20261126125558.2032158-1-rhkrqnwk98@gmail.com>

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] Generic XDP assumes the frame left after the BPF program runs
  still covers the mac_len bytes of L2 header that it subtracts.

--

net: xdp: Fix skb->tail after bpf_xdp_adjust_tail() in generic mode

This patch changes how bpf_prog_run_generic_xdp() recomputes skb->tail
after bpf_xdp_adjust_tail() has moved data_end. It now subtracts mac_len,
because the XDP frame starts mac_len bytes before skb->data. Without this,
skb->tail could land past skb->end, and a later tc bpf_skb_change_tail()
would write out of bounds.

> diff --git a/net/core/dev.c b/net/core/dev.c
> index cd0796a1dbfdf..1934e11c4401a 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -5737,7 +5737,7 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
>  	/* check if bpf_xdp_adjust_tail was used */
>  	off = xdp->data_end - orig_data_end;
>  	if (off != 0) {
> -		skb_set_tail_pointer(skb, xdp->data_end - xdp->data);
> +		skb_set_tail_pointer(skb, xdp->data_end - xdp->data - mac_len);
>  		skb->len += off; /* positive on grow, negative on shrink */

[Severity: High]

This line assumes the frame left after the XDP program still covers the
mac_len bytes being subtracted. Is that guaranteed?

bpf_xdp_adjust_tail() only enforces a floor of ETH_HLEN relative to
xdp->data, not mac_len:

net/core/filter.c:bpf_xdp_adjust_tail() {
    ...
	if (unlikely(data_end < xdp->data + ETH_HLEN))
		return -EINVAL;
    ...
}

bpf_xdp_frags_shrink_tail() uses the same ETH_HLEN floor for nonlinear
frames.

In generic XDP, mac_len can be larger than ETH_HLEN. One example is a GRE
device that uses ipgre_header_ops (no remote, or a multicast remote). On
such a device, __ipgre_rcv() leaves mac_header at the outer IP header:

net/ipv4/ip_gre.c:__ipgre_rcv() {
    ...
		if (tunnel->dev->header_ops == &ipgre_header_ops)
			skb_pop_mac_header(skb);
    ...
}

So mac_len is at least 24 by the time do_xdp_generic() runs. The IPoIB
pseudo-header has a similar effect.

Take mac_len = 24 and headlen H, with a program that shrinks the frame to
data_end = xdp->data + 14:

  off = -(H + 10)
  skb_set_tail_pointer(skb, 14 - 24)  ->  skb->tail = skb->data - 10
  skb->len += off                     ->  skb->len wraps to 0xfffffff6

Before this patch tail was at least skb->data + 14. With it, tail ends up
before skb->data. The skb->len wrap is not new; it happened before this
patch too.

With that state, can the KASAN splat from the commit message still be
reached? A tc program that calls bpf_skb_change_tail(skb, 4096) sees
new_len < skb->len and takes the trim path:

  bpf_skb_change_tail()
    pskb_trim_rcsum()
      __skb_trim()    ->  skb->tail = skb->data + 4096

That can put tail past skb->end. A second call that grows the skb then
reaches __skb_grow() with a negative skb_tailroom(), no expand happens,
and bpf_skb_grow_rcsum() writes past the buffer.

Even without tc, ip_rcv_core() trusts the wrapped skb->len and calls
pskb_trim_rcsum(skb, iph->tot_len). tot_len comes from the received inner
header, so this could also move tail past skb->end.

The adjust_head fixup earlier in bpf_prog_run_generic_xdp() has a similar
gap. bpf_xdp_adjust_head() also keeps only ETH_HLEN bytes:

	if (unlikely(data < data_start ||
		     data > xdp->data_end - ETH_HLEN))
		return -EINVAL;

So off in __skb_pull(skb, off) can reach headlen + mac_len - ETH_HLEN. On
a linear skb that is larger than skb->len, and skb->len wraps silently.

Would it make sense to drop or clamp the frame here when
xdp->data_end - xdp->data < mac_len, and to do the same for the
adjust_head path? Another option is a lower bound in the helpers that
accounts for the generic XDP mac_len.

>  	}
>

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126125558.2032158-1-rhkrqnwk98%40gmail.com

      parent reply	other threads:[~2026-11-27 12:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 12:55 [PATCH net] net: xdp: Fix skb->tail after bpf_xdp_adjust_tail() in generic mode Sechang Lim
2026-11-26 12:58 ` netdev-bot+sinfo
2026-11-26 13:15   ` Sechang Lim
2026-11-27 12:58 ` netdev-bot+sashiko [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=179578433682.3135.10241295283064186673@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rhkrqnwk98@gmail.com \
    --cc=sdf@fomichev.me \
    --cc=tehnerd@tehnerd.com \
    --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