bpf: Validate BTF repeated field counts before expansion
Linux
Affected versions
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
Linux
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
| No fix yet |
| Linux Linux |
|
|
In the Linux kernel, the following vulnerability has been resolved:
bpf: Validate BTF repeated field counts before expansion
btf_parse_struct_metas() walks user-supplied BTF during BPF_BTF_LOAD, and btf_repeat_fields() expands repeatable fields from array elements into the fixed BTF_FIELDS_MAX scratch array used by btf_parse_fields().
The remaining-capacity check performs the expanded field count calculation in u32. A malformed BTF can wrap that calculation, causing the check to pass even when the expanded field count exceeds the scratch array capacity. The following memcpy() can then write past the end of the array.
Use checked addition and multiplication before copying repeated fields and reject impossible counts.
From the CVE record · Linux
The Linux kernel can miscalculate repeated-field counts while processing user-supplied BTF during BPF_BTF_LOAD. An attacker able to submit malformed BTF can cause a memcpy() to write past a fixed scratch array. The input does not specify authentication requirements or whether user interaction is needed.
Engineers running Linux kernels should check whether their kernel includes the fix; affected versions are not specified.