CVE-2024-49861
JSON

7.8high

bpf: Fix helper writes to read-only maps

Severity
7.8high CVSS:3.1 by Linux
Exploit likelihood
0.24% (higher than 16% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
Linux

Description

In the Linux kernel, the following vulnerability has been resolved: bpf: Fix helper writes to read-only maps Lonial found an issue that despite user- and BPF-side frozen BPF map (like in case of .rodata), it was still possible to write into it from a BPF program side through specific helpers having ARG_PTR_TO_{LONG,INT} as arguments. In check_func_arg() when the argument is as mentioned, the meta->raw_mode is never set. Later, check_helper_mem_access(), under the case of PTR_TO_MAP_VALUE as register base type, it assumes BPF_READ for the subsequent call to check_map_access_type() and given the BPF map is read-only it succeeds. The helpers really need to be annotated as ARG_PTR_TO_{LONG,INT} | MEM_UNINIT when results are written into them as opposed to read out of them. The latter indicates that it's okay to pass a pointer to uninitialized memory as the memory is written to anyway. However, ARG_PTR_TO_{LONG,INT} is a special case of ARG_PTR_TO_FIXED_SIZE_MEM just with additional alignment requirement. So it is better to just get rid of the ARG_PTR_TO_{LONG,INT} special cases altogether and reuse the fixed size memory types. For this, add MEM_ALIGNED to additionally ensure alignment given these helpers write directly into the args via *<ptr> = val. The .arg*_size has been initialized reflecting the actual sizeof(*<ptr>). MEM_ALIGNED can only be used in combination with MEM_FIXED_SIZE annotated argument types, since in !MEM_FIXED_SIZE cases the verifier does not know the buffer size a priori and therefore cannot blindly write *<ptr> = val.

Affected

Product or packageVersionsReported by
Linux Linuxfrom 57c3bb725a3dd97d960d7e1cd0845d88de53217f before 988e55abcf7fdb8fc9a76a7cf3f4e939a4d4fb3a, from 57c3bb725a3dd97d960d7e1cd0845d88de53217f before a2c8dc7e21803257e762b0bf067fd13e9c995da0, from 57c3bb725a3dd97d960d7e1cd0845d88de53217f before 2ed98ee02d1e08afee88f54baec39ea78dc8a23c, from 57c3bb725a3dd97d960d7e1cd0845d88de53217f before 1e75d25133158b525e0456876e9bcfd6b2993fd5, from 57c3bb725a3dd97d960d7e1cd0845d88de53217f before 32556ce93bc45c730829083cb60f95a2728ea48b, 5.2
Not affected: before 5.2, from 6.1.120 up to 6.1.*, from 6.6.54 up to 6.6.*, from 6.10.13 up to 6.10.*, from 6.11.2 up to 6.11.*, from 6.12 up to *
CVE List
linux linux_kernelfrom 5.2 before 6.6.54, from 6.7 before 6.10.13, from 6.11 before 6.11.2NVD

All scores

Linux7.8high CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
NVD7.1high CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H

Classification

SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.

What each source says

CVE List

In the Linux kernel, the following vulnerability has been resolved: bpf: Fix helper writes to read-only maps Lonial found an issue that despite user- and BPF-side frozen BPF map (like in case of .rodata), it was still possible to write into it from a BPF program side through specific helpers having ARG_PTR_TO_{LONG,INT} as arguments. In check_func_arg() when the argument is as mentioned, the meta->raw_mode is never set. Later, check_helper_mem_access(), under the case of PTR_TO_MAP_VALUE as register base type, it assumes BPF_READ for the subsequent call to check_map_access_type() and given the BPF map is read-only it succeeds. The helpers really need to be annotated as ARG_PTR_TO_{LONG,INT} | MEM_UNINIT when results are written into them as opposed to read out of them. The latter indicates that it's okay to pass a pointer to uninitialized memory as the memory is written to anyway. However, ARG_PTR_TO_{LONG,INT} is a special case of ARG_PTR_TO_FIXED_SIZE_MEM just with additional alignment requirement. So it is better to just get rid of the ARG_PTR_TO_{LONG,INT} special cases altogether and reuse the fixed size memory types. For this, add MEM_ALIGNED to additionally ensure alignment given these helpers write directly into the args via *<ptr> = val. The .arg*_size has been initialized reflecting the actual sizeof(*<ptr>). MEM_ALIGNED can only be used in combination with MEM_FIXED_SIZE annotated argument types, since in !MEM_FIXED_SIZE cases the verifier does not know the buffer size a priori and therefore cannot blindly write *<ptr> = val.

NVD (es)

En el kernel de Linux, se ha resuelto la siguiente vulnerabilidad: bpf: Arregla las escrituras del ayudante en mapas de solo lectura Lonial encontró un problema que a pesar del mapa BPF congelado del lado del usuario y del BPF (como en el caso de .rodata), aún era posible escribir en él desde el lado del programa BPF a través de ayudantes específicos que tienen ARG_PTR_TO_{LONG,INT} como argumentos. En check_func_arg() cuando el argumento es como se menciona, el meta-&gt;raw_mode nunca se establece. Más tarde, check_helper_mem_access(), bajo el caso de PTR_TO_MAP_VALUE como tipo base de registro, asume BPF_READ para la llamada posterior a check_map_access_type() y dado que el mapa BPF es de solo lectura, tiene éxito. Los ayudantes realmente necesitan ser anotados como ARG_PTR_TO_{LONG,INT} | MEM_UNINIT cuando los resultados se escriben en ellos en lugar de leerse de ellos. Este último indica que está bien pasar un puntero a la memoria no inicializada, ya que la memoria se escribe de todos modos. Sin embargo, ARG_PTR_TO_{LONG,INT} es un caso especial de ARG_PTR_TO_FIXED_SIZE_MEM solo que con un requisito de alineación adicional. Por lo tanto, es mejor deshacerse de los casos especiales ARG_PTR_TO_{LONG,INT} por completo y reutilizar los tipos de memoria de tamaño fijo. Para esto, agregue MEM_ALIGNED para garantizar adicionalmente la alineación dado que estos ayudantes escriben directamente en los argumentos a través de * = val. El .arg*_size se ha inicializado reflejando el tamaño real de (*). MEM_ALIGNED solo se puede usar en combinación con los tipos de argumentos anotados MEM_FIXED_SIZE, ya que en los casos !MEM_FIXED_SIZE el verificador no conoce el tamaño del búfer a priori y, por lo tanto, no puede escribir ciegamente * = val.

References

Sources

SourceRecordLicence
CVE ListCVE-2024-49861 changed 2026-08-05CVE Terms of Use
NVDCVE-2024-49861 changed 2026-08-04Public domain