CVE-2025-22058

In the Linux kernel, the following vulnerability has been resolved: udp: Fix memory accounting leak. Matt Dowling reported a weird UDP memory usage issue. Under normal operation, the UDP memory usage reported in /proc/net/sockstat remains close to zero. However, it occasionally spiked to 524,288 pages and never dropped. Moreover, the value doubled when the application was terminated. Finally, it caused intermittent packet drops. We can reproduce the issue with the script below [0]: 1. /proc/net/sockstat reports 0 pages # cat /proc/net/sockstat | grep UDP: UDP: inuse 1 mem 0 2. Run the script till the report reaches 524,288 # python3 test.py & sleep 5 # cat /proc/net/sockstat | grep UDP: UDP: inuse 3 mem 524288 <-- (INT_MAX + 1) >> PAGE_SHIFT 3. Kill the socket and confirm the number never drops # pkill python3 && sleep 5 # cat /proc/net/sockstat | grep UDP: UDP: inuse 1 mem 524288 4. (necessary since v6.0) Trigger proto_memory_pcpu_drain() # python3 test.py & sleep 1 && pkill python3 5. The number doubles # cat /proc/net/sockstat | grep UDP: UDP: inuse 1 mem 1048577 The application set INT_MAX to SO_RCVBUF, which triggered an integer overflow in udp_rmem_release(). When a socket is close()d, udp_destruct_common() purges its receive queue and sums up skb->truesize in the queue. This total is calculated and stored in a local unsigned integer variable. The total size is then passed to udp_rmem_release() to adjust memory accounting. However, because the function takes a signed integer argument, the total size can wrap around, causing an overflow. Then, the released amount is calculated as follows: 1) Add size to sk->sk_forward_alloc. 2) Round down sk->sk_forward_alloc to the nearest lower multiple of PAGE_SIZE and assign it to amount. 3) Subtract amount from sk->sk_forward_alloc. 4) Pass amount >> PAGE_SHIFT to __sk_mem_reduce_allocated(). When the issue occurred, the total in udp_destruct_common() was 2147484480 (INT_MAX + 833), which was cast to -2147482816 in udp_rmem_release(). At 1) sk->sk_forward_alloc is changed from 3264 to -2147479552, and 2) sets -2147479552 to amount. 3) reverts the wraparound, so we don't see a warning in inet_sock_destruct(). However, udp_memory_allocated ends up doubling at 4). Since commit 3cd3399dd7a8 ("net: implement per-cpu reserves for memory_allocated"), memory usage no longer doubles immediately after a socket is close()d because __sk_mem_reduce_allocated() caches the amount in udp_memory_per_cpu_fw_alloc. However, the next time a UDP socket receives a packet, the subtraction takes effect, causing UDP memory usage to double. This issue makes further memory allocation fail once the socket's sk->sk_rmem_alloc exceeds net.ipv4.udp_rmem_min, resulting in packet drops. To prevent this issue, let's use unsigned int for the calculation and call sk_forward_alloc_add() only once for the small delta. Note that first_packet_length() also potentially has the same problem. [0]: from socket import * SO_RCVBUFFORCE = 33 INT_MAX = (2 ** 31) - 1 s = socket(AF_INET, SOCK_DGRAM) s.bind(('', 0)) s.setsockopt(SOL_SOCKET, SO_RCVBUFFORCE, INT_MAX) c = socket(AF_INET, SOCK_DGRAM) c.connect(s.getsockname()) data = b'a' * 100 while True: c.send(data)
Configurations

Configuration 1 (hide)

OR cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*

History

31 Oct 2025, 20:09

Type Values Removed Values Added
References () https://git.kernel.org/stable/c/13550273171f5108b1ac572d8f72f4256ab92854 - () https://git.kernel.org/stable/c/13550273171f5108b1ac572d8f72f4256ab92854 - Patch
References () https://git.kernel.org/stable/c/3836029448e76c1e6f77cc5fe0adc09b018b5fa8 - () https://git.kernel.org/stable/c/3836029448e76c1e6f77cc5fe0adc09b018b5fa8 - Patch
References () https://git.kernel.org/stable/c/9122fec396950cc866137af7154b1d0d989be52e - () https://git.kernel.org/stable/c/9122fec396950cc866137af7154b1d0d989be52e - Patch
References () https://git.kernel.org/stable/c/a116b271bf3cb72c8155b6b7f39083c1b80dcd00 - () https://git.kernel.org/stable/c/a116b271bf3cb72c8155b6b7f39083c1b80dcd00 - Patch
References () https://git.kernel.org/stable/c/aeef6456692c6f11ae53d278df64f1316a2a405a - () https://git.kernel.org/stable/c/aeef6456692c6f11ae53d278df64f1316a2a405a - Patch
References () https://git.kernel.org/stable/c/c3ad8c30b6b109283d2643e925f8e65f2e7ab34e - () https://git.kernel.org/stable/c/c3ad8c30b6b109283d2643e925f8e65f2e7ab34e - Patch
References () https://git.kernel.org/stable/c/c4bac6c398118fba79e32b1cd01db22dbfe29fbf - () https://git.kernel.org/stable/c/c4bac6c398118fba79e32b1cd01db22dbfe29fbf - Patch
References () https://git.kernel.org/stable/c/d9c8266ce536e8314d84370e983afcaa36fb19cf - () https://git.kernel.org/stable/c/d9c8266ce536e8314d84370e983afcaa36fb19cf - Patch
References () https://git.kernel.org/stable/c/df207de9d9e7a4d92f8567e2c539d9c8c12fd99d - () https://git.kernel.org/stable/c/df207de9d9e7a4d92f8567e2c539d9c8c12fd99d - Patch
First Time Linux linux Kernel
Linux
CWE CWE-401
CPE cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
CVSS v2 : unknown
v3 : unknown
v2 : unknown
v3 : 5.5

29 Oct 2025, 14:15

Type Values Removed Values Added
References
  • () https://git.kernel.org/stable/c/13550273171f5108b1ac572d8f72f4256ab92854 -
  • () https://git.kernel.org/stable/c/d9c8266ce536e8314d84370e983afcaa36fb19cf -

19 Oct 2025, 15:15

Type Values Removed Values Added
References
  • () https://git.kernel.org/stable/c/c3ad8c30b6b109283d2643e925f8e65f2e7ab34e -
Summary
  • (es) En el kernel de Linux, se ha resuelto la siguiente vulnerabilidad: udp: Se corrige la fuga de contabilidad de memoria. Matt Dowling informó de un extraño problema de uso de memoria UDP. En condiciones normales de funcionamiento, el uso de memoria UDP informado en /proc/net/sockstat se mantiene cercano a cero. Sin embargo, ocasionalmente alcanzaba 524&#xa0;288 páginas y nunca se reducía. Además, el valor se duplicaba al finalizar la aplicación. Finalmente, causaba pérdidas intermitentes de paquetes. Podemos reproducir el problema con el siguiente script [0]: 1. /proc/net/sockstat informa 0 páginas # cat /proc/net/sockstat | grep UDP: UDP: inuse 1 mem 0 2. Ejecute el script hasta que el informe alcance 524&#xa0;288 # python3 test.py &amp; sleep 5 # cat /proc/net/sockstat | grep UDP: UDP: inuse 3 mem 524288 &lt;-- (INT_MAX + 1) &gt;&gt; PAGE_SHIFT 3. Matar el socket y confirmar que el número nunca baje # pkill python3 &amp;&amp; sleep 5 # cat /proc/net/sockstat | grep UDP: UDP: inuse 1 mem 524288 4. (necesario desde v6.0) Desencadenar proto_memory_pcpu_drain() # python3 test.py &amp; sleep 1 &amp;&amp; pkill python3 5. El número se duplica # cat /proc/net/sockstat | grep UDP: UDP: inuse 1 mem 1048577 La aplicación estableció INT_MAX en SO_RCVBUF, lo que desencadenó un desbordamiento de entero en udp_rmem_release(). Cuando se cierra un socket, udp_destruct_common() purga su cola de recepción y suma skb-&gt;truesize en ella. Este total se calcula y se almacena en una variable local de entero sin signo. El tamaño total se pasa a udp_rmem_release() para ajustar la memoria. Sin embargo, dado que la función acepta un argumento de entero con signo, el tamaño total puede volver a la normalidad, provocando un desbordamiento. La cantidad liberada se calcula de la siguiente manera: 1) Sumar size a sk-&gt;sk_forward_alloc. 2) Redondear sk-&gt;sk_forward_alloc al múltiplo inferior más cercano de PAGE_SIZE y asignarlo a amount. 3) Restar amount de sk-&gt;sk_forward_alloc. 4) Pasar amount &gt;&gt; PAGE_SHIFT a __sk_mem_reduce_allocated(). Cuando se produjo el problema, el total en udp_destruct_common() era 2147484480 (INT_MAX + 833), que se convirtió a -2147482816 en udp_rmem_release(). En 1) sk-&gt;sk_forward_alloc se cambia de 3264 a -2147479552, y 2) se establece -2147479552 en cantidad. 3) revierte el ajuste, por lo que no vemos ninguna advertencia en inet_sock_destruct(). Sin embargo, udp_memory_allocated se duplica en 4). Desde el commit 3cd3399dd7a8 ("net: implementar reservas por CPU para memory_allocated"), el uso de memoria ya no se duplica inmediatamente después de cerrar un socket, ya que __sk_mem_reduce_allocated() almacena en caché la cantidad en udp_memory_per_cpu_fw_alloc. Sin embargo, la siguiente vez que un socket UDP recibe un paquete, la resta se aplica, duplicando el uso de memoria UDP. Este problema provoca que la asignación de memoria posterior falle una vez que el valor de sk-&gt;sk_rmem_alloc del socket supere net.ipv4.udp_rmem_min, lo que provoca la pérdida de paquetes. Para evitar este problema, usemos unsigned int para el cálculo y llamemos a sk_forward_alloc_add() solo una vez para la delta pequeña. Tenga en cuenta que first_packet_length() también podría tener el mismo problema. [0]: desde la importación de socket * SO_RCVBUFFORCE = 33 INT_MAX = (2 ** 31) - 1 s = socket(AF_INET, SOCK_DGRAM) s.bind(('', 0)) s.setsockopt(SOL_SOCKET, SO_RCVBUFFORCE, INT_MAX) c = socket(AF_INET, SOCK_DGRAM) c.connect(s.getsockname()) datos = b'a' * 100 mientras sea verdadero: c.send(datos)

16 Apr 2025, 15:15

Type Values Removed Values Added
New CVE

Information

Published : 2025-04-16 15:15

Updated : 2025-10-31 20:09


NVD link : CVE-2025-22058

Mitre link : CVE-2025-22058

CVE.ORG link : CVE-2025-22058


JSON object : View

Products Affected

linux

  • linux_kernel
CWE
CWE-401

Missing Release of Memory after Effective Lifetime