CVE-2024-42239

In the Linux kernel, the following vulnerability has been resolved: bpf: Fail bpf_timer_cancel when callback is being cancelled Given a schedule: timer1 cb timer2 cb bpf_timer_cancel(timer2); bpf_timer_cancel(timer1); Both bpf_timer_cancel calls would wait for the other callback to finish executing, introducing a lockup. Add an atomic_t count named 'cancelling' in bpf_hrtimer. This keeps track of all in-flight cancellation requests for a given BPF timer. Whenever cancelling a BPF timer, we must check if we have outstanding cancellation requests, and if so, we must fail the operation with an error (-EDEADLK) since cancellation is synchronous and waits for the callback to finish executing. This implies that we can enter a deadlock situation involving two or more timer callbacks executing in parallel and attempting to cancel one another. Note that we avoid incrementing the cancelling counter for the target timer (the one being cancelled) if bpf_timer_cancel is not invoked from a callback, to avoid spurious errors. The whole point of detecting cur->cancelling and returning -EDEADLK is to not enter a busy wait loop (which may or may not lead to a lockup). This does not apply in case the caller is in a non-callback context, the other side can continue to cancel as it sees fit without running into errors. Background on prior attempts: Earlier versions of this patch used a bool 'cancelling' bit and used the following pattern under timer->lock to publish cancellation status. lock(t->lock); t->cancelling = true; mb(); if (cur->cancelling) return -EDEADLK; unlock(t->lock); hrtimer_cancel(t->timer); t->cancelling = false; The store outside the critical section could overwrite a parallel requests t->cancelling assignment to true, to ensure the parallely executing callback observes its cancellation status. It would be necessary to clear this cancelling bit once hrtimer_cancel is done, but lack of serialization introduced races. Another option was explored where bpf_timer_start would clear the bit when (re)starting the timer under timer->lock. This would ensure serialized access to the cancelling bit, but may allow it to be cleared before in-flight hrtimer_cancel has finished executing, such that lockups can occur again. Thus, we choose an atomic counter to keep track of all outstanding cancellation requests and use it to prevent lockups in case callbacks attempt to cancel each other while executing in parallel.
Configurations

Configuration 1 (hide)

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

History

08 Aug 2024, 14:54

Type Values Removed Values Added
First Time Linux
Linux linux Kernel
CPE cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
CWE CWE-667
References () https://git.kernel.org/stable/c/3e4e8178a8666c56813bd167b848fca0f4c9af0a - () https://git.kernel.org/stable/c/3e4e8178a8666c56813bd167b848fca0f4c9af0a - Patch
References () https://git.kernel.org/stable/c/9369830518688ecd5b08ffc08ab3302ce2b5d0f7 - () https://git.kernel.org/stable/c/9369830518688ecd5b08ffc08ab3302ce2b5d0f7 - Patch
References () https://git.kernel.org/stable/c/d4523831f07a267a943f0dde844bf8ead7495f13 - () https://git.kernel.org/stable/c/d4523831f07a267a943f0dde844bf8ead7495f13 - Patch
Summary
  • (es) En el kernel de Linux, se ha resuelto la siguiente vulnerabilidad: bpf: falla bpf_timer_cancel cuando se cancela la devolución de llamada. Dada una programación: timer1 cb timer2 cb bpf_timer_cancel(timer2); bpf_timer_cancel(timer1); Ambas llamadas a bpf_timer_cancel esperarían a que la otra devolución de llamada termine de ejecutarse, introduciendo un bloqueo. Agregue un recuento atomic_t llamado 'cancelación' en bpf_hrtimer. Esto realiza un seguimiento de todas las solicitudes de cancelación en vuelo para un temporizador BPF determinado. Siempre que cancelemos un temporizador BPF, debemos verificar si tenemos solicitudes de cancelación pendientes y, de ser así, debemos fallar la operación con un error (-EDEADLK) ya que la cancelación es sincrónica y espera a que termine de ejecutarse la devolución de llamada. Esto implica que podemos entrar en una situación de punto muerto que involucre dos o más devoluciones de llamada de temporizador ejecutándose en paralelo e intentando cancelarse entre sí. Tenga en cuenta que evitamos incrementar el contador de cancelación para el temporizador de destino (el que se cancela) si no se invoca bpf_timer_cancel desde una devolución de llamada, para evitar errores falsos. El objetivo de detectar cur->cancelar y devolver -EDEADLK es no ingresar a un ciclo de espera ocupado (que puede o no conducir a un bloqueo). Esto no se aplica en caso de que la persona que llama se encuentre en un contexto sin devolución de llamada; la otra parte puede continuar cancelando como mejor le parezca sin cometer errores. Antecedentes de intentos anteriores: Las versiones anteriores de este parche usaban un bit bool de 'cancelación' y usaban el siguiente patrón en temporizador->bloqueo para publicar el estado de cancelación. lock(t->lock); t->cancelling = true; mb(); if (cur->cancelling) return -EDEADLK; unlock(t->lock); hrtimer_cancel(t->timer); t->cancelling = false; El almacén fuera de la sección crítica podría sobrescribir una asignación de cancelación t->de solicitudes paralelas a verdadero, para garantizar que la devolución de llamada que se ejecuta en paralelo observe su estado de cancelación. Sería necesario borrar este bit de cancelación una vez que se complete hrtimer_cancel, pero la falta de serialización introdujo ejecuciones. Se exploró otra opción donde bpf_timer_start borraría el bit al (re)iniciar el temporizador bajo temporizador->bloqueo. Esto garantizaría el acceso serializado al bit de cancelación, pero puede permitir que se borre antes de que hrtimer_cancel en vuelo haya terminado de ejecutarse, de modo que los bloqueos puedan ocurrir nuevamente. Por lo tanto, elegimos un contador atómico para realizar un seguimiento de todas las solicitudes de cancelación pendientes y lo utilizamos para evitar bloqueos en caso de que las devoluciones de llamada intenten cancelarse entre sí mientras se ejecutan en paralelo.
CVSS v2 : unknown
v3 : unknown
v2 : unknown
v3 : 5.5

07 Aug 2024, 16:15

Type Values Removed Values Added
New CVE

Information

Published : 2024-08-07 16:15

Updated : 2024-08-08 14:54


NVD link : CVE-2024-42239

Mitre link : CVE-2024-42239

CVE.ORG link : CVE-2024-42239


JSON object : View

Products Affected

linux

  • linux_kernel
CWE
CWE-667

Improper Locking