Netdev List
 help / color / mirror / Atom feed
* [PATCH net 0/2] xdp: fix skb length accounting after frag adjustment
@ 2026-07-27  3:25 Sun Jian
  2026-07-27  3:25 ` [PATCH net 1/2] net: fix skb length accounting after generic XDP " Sun Jian
  2026-07-27  3:25 ` [PATCH net 2/2] veth: fix skb length accounting after " Sun Jian
  0 siblings, 2 replies; 5+ messages in thread
From: Sun Jian @ 2026-07-27  3:25 UTC (permalink / raw)
  To: netdev
  Cc: bpf, stable, sun.jian.kdev, davem, edumazet, kuba, pabeni,
	andrew+netdev, horms, ast, daniel, hawk, john.fastabend, sdf,
	lorenzo, toke, maciej.fijalkowski, matt

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


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

end of thread, other threads:[~2026-07-27  7:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-27  3:25 [PATCH net 0/2] xdp: fix skb length accounting after frag adjustment Sun Jian
2026-07-27  3:25 ` [PATCH net 1/2] net: fix skb length accounting after generic XDP " Sun Jian
2026-07-27  3:25 ` [PATCH net 2/2] veth: fix skb length accounting after " Sun Jian
2026-07-27  6:54   ` Lorenzo Bianconi
2026-07-27  7:28   ` Lorenzo Bianconi

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