bpf: Fix stack-out-of-bounds write in devmap
Linux
Affected versions
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
Linux
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
≥ aeea1b86f9363f3feabb496534d886f082a89f21 · < ca831567908fd3f73cf97d8a6c09a5054697a182| No fix yet |
| Linux Linux |
|
|
In the Linux kernel, the following vulnerability has been resolved:
bpf: Fix stack-out-of-bounds write in devmap
get_upper_ifindexes() iterates over all upper devices and writes their indices into an array without checking bounds.
Also the callers assume that the max number of upper devices is MAX_NEST_DEV and allocate excluded_devices[1+MAX_NEST_DEV] on the stack, but that assumption is not correct and the number of upper devices could be larger than MAX_NEST_DEV (e.g., many macvlans), causing a stack-out-of-bounds write.
Add a max parameter to get_upper_ifindexes() to avoid the issue. When there are too many upper devices, return -EOVERFLOW and abort the redirect.
To reproduce, create more than MAX_NEST_DEV(8) macvlans on a device with an XDP program attached using BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS. Then send a packet to the device to trigger the XDP redirect path.
From the CVE record · Linux
The Linux kernel’s BPF devmap redirect path can write beyond a stack array when a device has more than MAX_NEST_DEV upper devices. With an XDP program using BPF_F_BROADCAST and BPF_F_EXCLUDE_INGRESS attached, a packet sent to that device can trigger the write. The input does not specify authentication requirements.
Engineers running Linux kernels with XDP programs using BPF devmap redirects should check whether their kernels include the fix; affected versions are not specified.