[PATCH net 0/2] xdp: fix skb length accounting after frag adjustment
From: Sun Jian <hidden>
Date: 2026-07-27 03:25:50
Also in:
bpf, stable
Both generic XDP and veth restore skb fragment accounting after running an XDP program by copying xdp_frags_size into skb->data_len. skb->len is only adjusted by the linear tail delta, so the stale fragment contribution is left in place. When an XDP program shrinks only the fragment area, skb_headlen() therefore exceeds the actual linear area. In the reproduced UDP receive path, __skb_datagram_iter() copied 1024 bytes past the actual linear tail to userspace, starting at struct skb_shared_info. The copied bytes included the affected skb's nr_frags, xdp_frags_size and a kernel pointer from skb_shinfo(skb)->frags[0]. Real packet data was displaced by the same amount and truncated at the end. Maciej suggested assigning xdp_get_buff_len(xdp) to skb->len. That works for veth, where the skb and XDP views both include the MAC header at this point, but not for generic XDP. bpf_prog_run_generic_xdp() builds the XDP view with skb_headlen(skb) + mac_len while the skb has already been pulled past the MAC header, so that assignment would overcount skb->len by mac_len. Both patches instead replace the old data_len contribution in skb->len with the updated one. This is independent of the current packet view and keeps the accounting sequence identical at both sites. Tested with a 60000-byte UDP datagram over a veth pair with MTU 64000. An XDP program shortened the fragment area by 1024 bytes. Before the fixes, both generic and native XDP produced corrupted payloads in 10/10 runs. After the fixes, both paths matched the expected payload exactly in 10/10 runs. Sun Jian (2): net: fix skb length accounting after generic XDP frag adjustment veth: fix skb length accounting after XDP frag adjustment drivers/net/veth.c | 4 +++- net/core/dev.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) base-commit: 53658c6f3682967a5e76ed4bc7462c4bdcddaec3 -- 2.43.0