CVE-2024-41045
JSON

7.8high

bpf: Defer work in bpf_timer_cancel_and_free

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

Description

In the Linux kernel, the following vulnerability has been resolved: bpf: Defer work in bpf_timer_cancel_and_free Currently, the same case as previous patch (two timer callbacks trying to cancel each other) can be invoked through bpf_map_update_elem as well, or more precisely, freeing map elements containing timers. Since this relies on hrtimer_cancel as well, it is prone to the same deadlock situation as the previous patch. It would be sufficient to use hrtimer_try_to_cancel to fix this problem, as the timer cannot be enqueued after async_cancel_and_free. Once async_cancel_and_free has been done, the timer must be reinitialized before it can be armed again. The callback running in parallel trying to arm the timer will fail, and freeing bpf_hrtimer without waiting is sufficient (given kfree_rcu), and bpf_timer_cb will return HRTIMER_NORESTART, preventing the timer from being rearmed again. However, there exists a UAF scenario where the callback arms the timer before entering this function, such that if cancellation fails (due to timer callback invoking this routine, or the target timer callback running concurrently). In such a case, if the timer expiration is significantly far in the future, the RCU grace period expiration happening before it will free the bpf_hrtimer state and along with it the struct hrtimer, that is enqueued. Hence, it is clear cancellation needs to occur after async_cancel_and_free, and yet it cannot be done inline due to deadlock issues. We thus modify bpf_timer_cancel_and_free to defer work to the global workqueue, adding a work_struct alongside rcu_head (both used at _different_ points of time, so can share space). Update existing code comments to reflect the new state of affairs.

Affected

Product or packageVersionsReported by
Linux Linuxfrom b00628b1c7d595ae5b544e059c27b1f5828314b4 before 7b27f15cab4c7d4f28c25b94a5284ad6d9d3695d, from b00628b1c7d595ae5b544e059c27b1f5828314b4 before 5eaa11c500ed07f505f86cec07d5593a71927e26, from b00628b1c7d595ae5b544e059c27b1f5828314b4 before 7aa5a19279c3639ae8b758b63f05d0c616a39fa1, from b00628b1c7d595ae5b544e059c27b1f5828314b4 before a6fcd19d7eac1335eb76bc16b6a66b7f574d1d69, 5.15
Not affected: before 5.15, from 6.1.191 up to 6.1.*, from 6.6.158 up to 6.6.*, from 6.9.10 up to 6.9.*, from 6.10 up to *
CVE List
linux linux_kernelfrom 5.15 before 6.9.10, 6.10NVD

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.8high CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

Classification

CWE-416

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: Defer work in bpf_timer_cancel_and_free Currently, the same case as previous patch (two timer callbacks trying to cancel each other) can be invoked through bpf_map_update_elem as well, or more precisely, freeing map elements containing timers. Since this relies on hrtimer_cancel as well, it is prone to the same deadlock situation as the previous patch. It would be sufficient to use hrtimer_try_to_cancel to fix this problem, as the timer cannot be enqueued after async_cancel_and_free. Once async_cancel_and_free has been done, the timer must be reinitialized before it can be armed again. The callback running in parallel trying to arm the timer will fail, and freeing bpf_hrtimer without waiting is sufficient (given kfree_rcu), and bpf_timer_cb will return HRTIMER_NORESTART, preventing the timer from being rearmed again. However, there exists a UAF scenario where the callback arms the timer before entering this function, such that if cancellation fails (due to timer callback invoking this routine, or the target timer callback running concurrently). In such a case, if the timer expiration is significantly far in the future, the RCU grace period expiration happening before it will free the bpf_hrtimer state and along with it the struct hrtimer, that is enqueued. Hence, it is clear cancellation needs to occur after async_cancel_and_free, and yet it cannot be done inline due to deadlock issues. We thus modify bpf_timer_cancel_and_free to defer work to the global workqueue, adding a work_struct alongside rcu_head (both used at _different_ points of time, so can share space). Update existing code comments to reflect the new state of affairs.

NVD (es)

En el kernel de Linux, se ha resuelto la siguiente vulnerabilidad: bpf: Aplazar el trabajo en bpf_timer_cancel_and_free Actualmente, el mismo caso del parche anterior (dos devoluciones de llamada de temporizador que intentan cancelarse entre sí) también se puede invocar a través de bpf_map_update_elem, o más precisamente, liberando mapa elementos que contienen temporizadores. Dado que esto también depende de hrtimer_cancel, es propenso a la misma situación de punto muerto que el parche anterior. Sería suficiente usar hrtimer_try_to_cancel para solucionar este problema, ya que el temporizador no se puede poner en cola después de async_cancel_and_free. Una vez que se haya realizado async_cancel_and_free, el temporizador debe reinicializarse antes de poder armarse nuevamente. La devolución de llamada que se ejecuta en paralelo al intentar armar el temporizador fallará, y liberar bpf_hrtimer sin esperar es suficiente (dado kfree_rcu), y bpf_timer_cb devolverá HRTIMER_NORESTART, evitando que el temporizador se rearme nuevamente. Sin embargo, existe un escenario UAF en el que la devolución de llamada arma el temporizador antes de ingresar a esta función, de modo que si la cancelación falla (debido a que la devolución de llamada del temporizador invoca esta rutina o la devolución de llamada del temporizador de destino se ejecuta simultáneamente). En tal caso, si la expiración del temporizador está significativamente lejos en el futuro, la expiración del período de gracia de RCU que ocurra antes liberará el estado bpf_hrtimer y junto con él la estructura hrtimer, que está en cola. Por lo tanto, está claro que la cancelación debe ocurrir después de async_cancel_and_free y, sin embargo, no se puede realizar en línea debido a problemas de interbloqueo. Por lo tanto, modificamos bpf_timer_cancel_and_free para diferir el trabajo a la cola de trabajo global, agregando un work_struct junto con rcu_head (ambos usados en _diferentes_ puntos de tiempo, por lo que pueden compartir espacio). Actualice los comentarios del código existente para reflejar la nueva situación.

References

Sources

SourceRecordLicence
CVE ListCVE-2024-41045 changed 2026-10-30CVE Terms of Use
NVDCVE-2024-41045 changed 2026-10-30Public domain