CVE-2024-36894
JSON

7.8high

usb: gadget: f_fs: Fix race between aio_cancel() and AIO request complete

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

Description

In the Linux kernel, the following vulnerability has been resolved: usb: gadget: f_fs: Fix race between aio_cancel() and AIO request complete FFS based applications can utilize the aio_cancel() callback to dequeue pending USB requests submitted to the UDC. There is a scenario where the FFS application issues an AIO cancel call, while the UDC is handling a soft disconnect. For a DWC3 based implementation, the callstack looks like the following: DWC3 Gadget FFS Application dwc3_gadget_soft_disconnect() ... --> dwc3_stop_active_transfers() --> dwc3_gadget_giveback(-ESHUTDOWN) --> ffs_epfile_async_io_complete() ffs_aio_cancel() --> usb_ep_free_request() --> usb_ep_dequeue() There is currently no locking implemented between the AIO completion handler and AIO cancel, so the issue occurs if the completion routine is running in parallel to an AIO cancel call coming from the FFS application. As the completion call frees the USB request (io_data->req) the FFS application is also referencing it for the usb_ep_dequeue() call. This can lead to accessing a stale/hanging pointer. commit b566d38857fc ("usb: gadget: f_fs: use io_data->status consistently") relocated the usb_ep_free_request() into ffs_epfile_async_io_complete(). However, in order to properly implement locking to mitigate this issue, the spinlock can't be added to ffs_epfile_async_io_complete(), as usb_ep_dequeue() (if successfully dequeuing a USB request) will call the function driver's completion handler in the same context. Hence, leading into a deadlock. Fix this issue by moving the usb_ep_free_request() back to ffs_user_copy_worker(), and ensuring that it explicitly sets io_data->req to NULL after freeing it within the ffs->eps_lock. This resolves the race condition above, as the ffs_aio_cancel() routine will not continue attempting to dequeue a request that has already been freed, or the ffs_user_copy_work() not freeing the USB request until the AIO cancel is done referencing it. This fix depends on commit b566d38857fc ("usb: gadget: f_fs: use io_data->status consistently")

Affected

Product or packageVersionsReported by
Linux Linuxfrom 2e4c7553cd6f9c68bb741582dcb614edcbeca70f before f71a53148ce34898fef099b75386a3a9f4449311, from 2e4c7553cd6f9c68bb741582dcb614edcbeca70f before 9e72ef59cbe61cd1243857a6418ca92104275867, from 2e4c7553cd6f9c68bb741582dcb614edcbeca70f before e500b1c4e29ad0bd1c1332a1eaea2913627a92dd, from 2e4c7553cd6f9c68bb741582dcb614edcbeca70f before 3613e5023f09b3308545e9d1acda86017ebd418a, from 2e4c7553cd6f9c68bb741582dcb614edcbeca70f before a0fdccb1c9e027e3195f947f61aa87d6d0d2ea14, from 2e4c7553cd6f9c68bb741582dcb614edcbeca70f before 73c05ad46bb4fbbdb346004651576d1c8dbcffbb, from 2e4c7553cd6f9c68bb741582dcb614edcbeca70f before d7461830823242702f5d84084bcccb25159003f4, from 2e4c7553cd6f9c68bb741582dcb614edcbeca70f before 24729b307eefcd7c476065cd7351c1a018082c19 and 1 more
Not affected: before 3.15, from 4.19.317 up to 4.19.*, from 5.4.279 up to 5.4.*, from 5.10.221 up to 5.10.*, from 5.15.162 up to 5.15.*, from 6.1.95 up to 6.1.*
CVE List
linux linux_kernelfrom 2e4c7553cd6f before 73c05ad46bb4, from 2e4c7553cd6f before d74618308232, from 2e4c7553cd6f before 24729b307eef, from 2e4c7553cd6f before f71a53148ce3, from 2e4c7553cd6f before 9e72ef59cbe6, from 2e4c7553cd6f before e500b1c4e29a, from 2e4c7553cd6f before 3613e5023f09, from 2e4c7553cd6f before a0fdccb1c9e0 and 9 more
Not affected: before 3.15, from 4.19.317 up to 4.20, from 5.4.279 up to 5.5, from 5.10.221 up to 5.11, from 5.15.162 up to 5.16, from 6.1.95 up to 6.2
CVE List, NVD

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
CISA-ADP5.6medium CVSS:3.1CVSS:3.1/AV:P/AC:H/PR:L/UI:N/S:U/C:H/I:N/A:H

Classification

CWE-362

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: usb: gadget: f_fs: Fix race between aio_cancel() and AIO request complete FFS based applications can utilize the aio_cancel() callback to dequeue pending USB requests submitted to the UDC. There is a scenario where the FFS application issues an AIO cancel call, while the UDC is handling a soft disconnect. For a DWC3 based implementation, the callstack looks like the following: DWC3 Gadget FFS Application dwc3_gadget_soft_disconnect() ... --> dwc3_stop_active_transfers() --> dwc3_gadget_giveback(-ESHUTDOWN) --> ffs_epfile_async_io_complete() ffs_aio_cancel() --> usb_ep_free_request() --> usb_ep_dequeue() There is currently no locking implemented between the AIO completion handler and AIO cancel, so the issue occurs if the completion routine is running in parallel to an AIO cancel call coming from the FFS application. As the completion call frees the USB request (io_data->req) the FFS application is also referencing it for the usb_ep_dequeue() call. This can lead to accessing a stale/hanging pointer. commit b566d38857fc ("usb: gadget: f_fs: use io_data->status consistently") relocated the usb_ep_free_request() into ffs_epfile_async_io_complete(). However, in order to properly implement locking to mitigate this issue, the spinlock can't be added to ffs_epfile_async_io_complete(), as usb_ep_dequeue() (if successfully dequeuing a USB request) will call the function driver's completion handler in the same context. Hence, leading into a deadlock. Fix this issue by moving the usb_ep_free_request() back to ffs_user_copy_worker(), and ensuring that it explicitly sets io_data->req to NULL after freeing it within the ffs->eps_lock. This resolves the race condition above, as the ffs_aio_cancel() routine will not continue attempting to dequeue a request that has already been freed, or the ffs_user_copy_work() not freeing the USB request until the AIO cancel is done referencing it. This fix depends on commit b566d38857fc ("usb: gadget: f_fs: use io_data->status consistently")

NVD (es)

En el kernel de Linux, se ha resuelto la siguiente vulnerabilidad: usb: gadget: f_fs: corrige la ejecución entre aio_cancel() y la solicitud AIO. Las aplicaciones basadas en FFS completas pueden utilizar la devolución de llamada aio_cancel() para quitar de la cola las solicitudes USB pendientes enviadas al UDC. Existe un escenario en el que la aplicación FFS emite una llamada de cancelación de AIO, mientras el UDC maneja una desconexión suave. Para una implementación basada en DWC3, la pila de llamadas se parece a la siguiente: Aplicación DWC3 Gadget FFS dwc3_gadget_soft_disconnect() ... --> dwc3_stop_active_transfers() --> dwc3_gadget_giveback(-ESHUTDOWN) --> ffs_epfile_async_io_complete() ffs_aio_cancel() --> usb_ep_free_request () --> usb_ep_dequeue() Actualmente no hay ningún bloqueo implementado entre el controlador de finalización de AIO y la cancelación de AIO, por lo que el problema ocurre si la rutina de finalización se ejecuta en paralelo a una llamada de cancelación de AIO proveniente de la aplicación FFS. A medida que la llamada de finalización libera la solicitud USB (io_data->req), la aplicación FFS también hace referencia a ella para la llamada usb_ep_dequeue(). Esto puede llevar a acceder a un puntero obsoleto/colgado. commit b566d38857fc ("usb: gadget: f_fs: use io_data->status consistentemente") reubicó usb_ep_free_request() en ffs_epfile_async_io_complete(). Sin embargo, para implementar correctamente el bloqueo para mitigar este problema, el spinlock no se puede agregar a ffs_epfile_async_io_complete(), ya que usb_ep_dequeue() (si se elimina con éxito una solicitud USB) llamará al controlador de finalización del controlador de función en el mismo contexto. De ahí que se llegue a un punto muerto. Solucione este problema moviendo usb_ep_free_request() de nuevo a ffs_user_copy_worker() y asegurándose de que establezca explícitamente io_data->req en NULL después de liberarlo dentro de ffs->eps_lock. Esto resuelve la condición de ejecución anterior, ya que la rutina ffs_aio_cancel() no continuará intentando sacar de la cola una solicitud que ya ha sido liberada, o ffs_user_copy_work() no liberará la solicitud USB hasta que la cancelación de AIO termine de hacer referencia a ella. Esta solución depende de el commit b566d38857fc ("usb: gadget: f_fs: use io_data->status consistentemente")

References

https://git.kernel.org/stable/c/f71a53148ce34898fef099b75386a3a9f4449311patch
https://git.kernel.org/stable/c/9e72ef59cbe61cd1243857a6418ca92104275867patch
https://git.kernel.org/stable/c/e500b1c4e29ad0bd1c1332a1eaea2913627a92ddpatch
https://git.kernel.org/stable/c/3613e5023f09b3308545e9d1acda86017ebd418apatch
https://git.kernel.org/stable/c/a0fdccb1c9e027e3195f947f61aa87d6d0d2ea14patch
https://git.kernel.org/stable/c/73c05ad46bb4fbbdb346004651576d1c8dbcffbbpatch
https://git.kernel.org/stable/c/d7461830823242702f5d84084bcccb25159003f4patch
https://git.kernel.org/stable/c/24729b307eefcd7c476065cd7351c1a018082c19patch
https://lists.debian.org/debian-lts-announce/2025/01/msg00001.html
https://cert-portal.siemens.com/productcert/html/ssa-265688.html
https://cert-portal.siemens.com/productcert/html/ssa-355557.html

Sources

SourceRecordLicence
CVE ListCVE-2024-36894 changed 2026-10-15CVE Terms of Use
NVDCVE-2024-36894 changed 2026-10-15Public domain