net: fix mac_len of skbs copied by generic XDP
Status from this message: This series was applied to netdev/net.git (main)
Get series with b4
b4 am [email protected]Versions newest first
Patches in v1 All 2 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | net: fix mac_len of skbs copied by generic XDPnet/ | +1 | 1 reply | Applied |
| 2/2 | selftests: drv-net: ping: test generic XDP redirect to cpumaptools/ tools/ | +43 | 0 replies | Applied |
Reviews trailers per patch
1 of 2 patches has a Reviewed-by or Acked-by.
| Patch | Toke Høiland-Jørgensen |
|---|---|
| 1/2 | R-b |
| 2/2 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH net 0/2] net: fix mac_len of skbs copied by generic XDP
Generic XDP copies the skb before it runs a program with frags support. The copy happens when the skb is cloned, nonlinear, or has less than 256 bytes of headroom. skb_pp_cow_data() makes the copy, but it does not copy mac_len. After XDP, the skb has mac_len 0.
Two places after generic XDP move skb->data by mac_len:
- On XDP_REDIRECT to a cpumap, cpu_map_generic_redirect() pulls mac_len bytes, the length of the Ethernet header. Then it queues the skb to the target CPU. With mac_len 0, the IP layer on that CPU sees the Ethernet header and drops the packet.
- On XDP_PASS, the skb can go on to tc ingress with a BPF program attached (tcx, cls_bpf or act_bpf). Before it runs the program, tc pushes mac_len bytes, the length of the Ethernet header. With mac_len 0, skb->data stays at the IP header. Therefore, the program reads the IP header as the Ethernet header.
Patch 1 copies mac_len in skb_pp_cow_data(). Patch 2 adds a test to drivers/net/ping.py. The test redirects packets to a cpumap in generic XDP. On netdevsim, the test fails without patch 1.
---
Copying mac_len in __copy_skb_header() would cover every caller. But it would also change skb_copy(), pskb_copy() and skb_copy_expand(). Commit 6001896f0098 ("bpf: Run generic devmap egress prog on private skb") hit a similar problem. It copies mac_len right after skb_copy() in dev_map_generic_redirect() [1]. We followed that approach.
The bug can be reproduced on veth, virtio_net and netdevsim. The fix was tested on all three. Native XDP is not affected.
[1] https://lore.kernel.org/all/CABFUUZFQXxYVdi_QqhGG8WTTf=F1BqOmroYj50mv0w70Acf5Bw@mail.gmail.com/
Tianyi Gao (2):
net: fix mac_len of skbs copied by generic XDP
selftests: drv-net: ping: test generic XDP redirect to cpumap
net/core/skbuff.c | 1 + tools/testing/selftests/drivers/net/ping.py | 27 ++++++++++++++++--- .../selftests/net/lib/xdp_cpumap.bpf.c | 19 +++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/net/lib/xdp_cpumap.bpf.c
base-commit: 647b81ddefc6364290e67bf33c89d54971f8995e
Signature · 1 line
2.55.0