Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: xdp: Fix skb->tail after bpf_xdp_adjust_tail() in generic mode
@ 2026-11-26 12:55 Sechang Lim
  2026-11-26 12:58 ` netdev-bot+sinfo
  0 siblings, 1 reply; 3+ messages in thread
From: Sechang Lim @ 2026-11-26 12:55 UTC (permalink / raw)
  To: netdev
  Cc: bpf, davem, edumazet, kuba, pabeni, willemb, horms, ast, daniel,
	hawk, john.fastabend, sdf, tehnerd

In generic XDP the program sees a frame starting at the MAC header,
mac_len bytes before skb->data. After bpf_xdp_adjust_tail(), skb->tail
is set to skb->data + (xdp->data_end - xdp->data), which is mac_len
bytes beyond the new end of the frame and can be beyond skb->end.
When a tc program then calls bpf_skb_change_tail(), __skb_grow()
compares the negative skb_tailroom() as unsigned and does not expand
the head, so zeroing the new bytes runs past the end of the buffer:

  BUG: KASAN: slab-out-of-bounds in bpf_skb_grow_rcsum+0x1cc/0x460
  Write of size 4096 at addr ffff888108e84ec0 by task xg/365
  Call Trace:
   bpf_skb_grow_rcsum+0x1cc/0x460
   bpf_skb_change_tail+0x50b/0x800
   bpf_prog_f9246b7887bf521b_tail+0x53/0x67
   __netif_receive_skb_core.constprop.0+0x132f/0x2e60

Subtract mac_len from the offset.

Fixes: 198d83bb3bec ("bpf: make generic xdp compatible w/ bpf_xdp_adjust_tail")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index cd0796a1dbfd..1934e11c4401 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 */
 	}
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-26 13:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox