Skip to content

vmxnet3: fix native XDP crash on oversized frames and XDP loss on reset

Philipp Sudakas bpf netdev 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 0 repliesNew
  2. v12 patches 1 replySuperseded

Changes in v2 from the cover letter

- New patch 1, and the rx_error double count fix in patch 4, after an automated review of v1 (Sashiko).
- New patch 2: v1 patch 2 made the attach failure path in vmxnet3_xdp_set() reachable with a stale program pointer.
- New patch 3: v1 left the MTU 3051..VMXNET3_XDP_MAX_MTU range as a known limit; it is now refused.
- Patch 4 no longer counts the dropped frame against the NAPI budget:
in mainline other non-PASS XDP verdicts are not counted either, so the v1 comment claiming so was wrong.
- Patch 4: fixed a line over 80 columns.
- Cc the networking, XDP and BPF maintainers and the author of the blamed commit, as get_maintainer.pl lists them.
- v1: https://lore.kernel.org/netdev/[email protected]/

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5vmxnet3: clear rx_ctx.skb after a data ring XDP verdictdrivers/net/vmxnet3/vmxnet3_drv.c+1 -00 replies
2/5vmxnet3: keep the previous XDP program when attaching failsdrivers/net/vmxnet3/vmxnet3_xdp.c+17 -50 replies
3/5vmxnet3: limit the XDP MTU to the rx head buffer sizedrivers/net/vmxnet3/vmxnet3_xdp.h+8 -20 replies
4/5vmxnet3: drop XDP frames that do not fit in one rx bufferdrivers/net/vmxnet3/vmxnet3_drv.c+19 -10 replies
5/5vmxnet3: keep the XDP program across device resetsdrivers/net/vmxnet3/vmxnet3_drv.c+5 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH net v2 0/5] vmxnet3: fix native XDP crash on oversized frames and XDP loss on reset

Fixes for native XDP on vmxnet3. A single frame from any host on the same L2 segment can crash a guest that has an XDP program attached; any device reset silently stops XDP; and the attach error path leaves the driver with a program it holds no reference to.

Patch 1: the rx data ring XDP path leaves rx_ctx.skb pointing at the ring head page after a non-PASS verdict. Patch 4 relies on rx_ctx.skb being NULL between frames.

Patch 2: vmxnet3_xdp_set() releases the old program before the device is active again and does not roll back on failure. Keep the old program on failure. Patch 5 removes the side effect that used to hide this.

Patch 3: with an MTU between 3051 and VMXNET3_XDP_MAX_MTU, full-sized frames do not fit the 3072-byte rx head buffer. Limit the XDP MTU so that they do.

Patch 4: a frame that does not fit in one XDP rx buffer (sop without eop) reaches the skb path, which takes the page_pool page for an skb:
kernel BUG in skb_put(). With MTU 1500, a single untagged frame of 1523..1526 bytes is enough. Drop such frames.

Patch 5: vmxnet3_rq_cleanup_all() clears xdp_bpf_prog on every quiesce (MTU change, down/up, ring resize, reset). XDP stops being called while the program is still reported as attached, and its reference leaks.

Reproduced with stock modules on Debian kernels 6.12.113, 6.12.117 and 7.2.12 (7.2.12 untainted), VMware virtual hardware version 20. A small reproducer (raw frame sender and an XDP_PASS counter program) is available on request.

Testing:
- Run-tested: the patched vmxnet3 files of net as of today, with the driver's current vmxnet3_ethtool.c and headers, built as a module for a Debian 7.2.12 kernel; VMware virtual hardware version 20, MTU 1500, native XDP:
- untagged frames of 1514..1522 bytes reach XDP; 1523, 1524 and 1526 bytes are dropped and counted in drop_total; 1530 bytes with a VLAN 0 tag are dropped; no crash;
- 5000 frames of 1500 bytes mixed with 5000 of 1524 bytes: exactly

    5000 XDP passes and 5000 drops;
  - with XDP_DROP attached, small frames over the rx data ring
    (64 and 100 bytes) are dropped by XDP, followed by normal and
    oversized frames without issue;
  - after an MTU change, down/up and an rx ring resize the same
    program keeps running; after detach no program is left loaded;

- MTU 3051 is refused with XDP attached and attaching at MTU 3051 is refused; at MTU 3050 frames of 3064 bytes reach XDP and 3073 bytes are dropped;
- attach and detach failures were forced with a test-only module parameter that skips vmxnet3_rq_create_all() and returns -ENOMEM:
after a failed attach no XDP program is attached or left loaded, and after down/up the stack receives again; after a failed detach the old program stays attached and runs again after down/up, and is freed after a later detach.
No warnings in dmesg.
- Not covered: the rx_error paths (no way to make the virtual device report a receive error), and VLAN tags other than 0, which the test switch does not pass.

Changes in v2:
- New patch 1, and the rx_error double count fix in patch 4, after an automated review of v1 (Sashiko).
- New patch 2: v1 patch 2 made the attach failure path in vmxnet3_xdp_set() reachable with a stale program pointer.
- New patch 3: v1 left the MTU 3051..VMXNET3_XDP_MAX_MTU range as a known limit; it is now refused.
- Patch 4 no longer counts the dropped frame against the NAPI budget:
in mainline other non-PASS XDP verdicts are not counted either, so the v1 comment claiming so was wrong.
- Patch 4: fixed a line over 80 columns.
- Cc the networking, XDP and BPF maintainers and the author of the blamed commit, as get_maintainer.pl lists them.
- v1: https://lore.kernel.org/netdev/[email protected]/

The problems were found and analysed, and the patches drafted, with the help of an AI coding assistant; reproduction and testing were run on the reporter's lab systems.

Philipp Sudakas (5):
vmxnet3: clear rx_ctx.skb after a data ring XDP verdict
vmxnet3: keep the previous XDP program when attaching fails
vmxnet3: limit the XDP MTU to the rx head buffer size
vmxnet3: drop XDP frames that do not fit in one rx buffer
vmxnet3: keep the XDP program across device resets

 drivers/net/vmxnet3/vmxnet3_drv.c | 27 +++++++++++++++++++++++++--
 drivers/net/vmxnet3/vmxnet3_xdp.c | 22 +++++++++++++++++-----
 drivers/net/vmxnet3/vmxnet3_xdp.h | 10 ++++++++--
 3 files changed, 50 insertions(+), 9 deletions(-)
Signature · 1 line
2.47.3