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 --- 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