freenode
Kernel & Low-Level

AF_XDP zero-copy fix moves packet metadata out of user memory

A kernel patch series stops userspace from rewriting fragment lists the kernel walks, and flags a separate ice buffer-size bug left unfixed.

Björn Töpel has posted fixes for an out-of-bounds access in the Linux kernel's AF_XDP zero-copy receive path. When a packet arrives across several buffers, the kernel has been keeping the fragment list and its count in the user memory region that holds those buffers. Userspace can write that region at any time, including while the kernel is still walking the fragments. A rewritten list or count makes the kernel read and write past the buffers it owns.

The fix moves that shared metadata into the kernel's buffer pool, which outlives the buffers and the queues that point at them. A pool builds one multi-buffer packet at a time, so one copy of the metadata is enough. Devices are then allowed to write through to the end of each chunk, matching what single-buffer pools already do, and programs can grow a packet further with tail adjustment. Copy mode is unchanged.

A companion change stops Intel's libeth helpers from reading that same metadata later, when they flush a batch of transmit completions. idpf was using the fragment count it found there to decide how many completions to report. Once the metadata moves, the next packet in the same poll can overwrite it before the flush. Each buffer is now counted on its own.

Sashiko, an AI code review agent, found the metadata placement while reviewing another AF_XDP buffer-layout series. Maciej Fijalkowski of Intel suggested the approach. Töpel tested on mlx5 hardware and on igb and veth under QEMU, none of which receive multi-buffer packets in zero copy, so i40e, ice, and idpf were initially only build-tested. Fijalkowski later ran the change on an Intel e810 (ice) back-to-back link: 84 cases passed and none failed. He also reviewed the core patch.

While auditing drivers, Töpel found a separate ice problem that this series does not touch. After earlier cleanups, an AF_XDP ring no longer takes its zero-copy receive length from the XSK pool. It inherits whatever the last page-pool setup left behind, or zero if it never had one. With 2K chunks the device can write past a chunk into the next. He found that by reading the code and did not test it.

The selftest update that drops reserved tailroom for the old layout will be split out. Fijalkowski noted it was written against an older test location, and Töpel said he would respin without it.