{"id":"CVE-2025-68282","aliases":["CVE-2025-68282"],"related":[],"kind":"vulnerability","state":"published","title":"usb: gadget: udc: fix use-after-free in usb_gadget_state_work","summary":"In the Linux kernel, the following vulnerability has been resolved:\n\nusb: gadget: udc: fix use-after-free in usb_gadget_state_work\n\nA race condition during gadget teardown can lead to a use-after-free\nin usb_gadget_state_work(), as reported by KASAN:\n\n  BUG: KASAN: invalid-access in sysfs_notify+0x2c/0xd0\n  Workqueue: events usb_gadget_state_work\n\nThe fundamental race occurs because a concurrent event (e.g., an\ninterrupt) can call usb_gadget_set_state() and schedule gadget->work\nat any time during the cleanup process in usb_del_gadget().\n\nCommit 399a45e5237c (\"usb: gadget: core: flush gadget workqueue after\ndevice removal\") attempted to fix this by moving flush_work() to after\ndevice_del(). However, this does not fully solve the race, as a new\nwork item can still be scheduled *after* flush_work() completes but\nbefore the gadget's memory is freed, leading to the same use-after-free.\n\nThis patch fixes the race condition robustly by introducing a 'teardown'\nflag and a 'state_lock' spinlock to the usb_gadget struct. The flag is\nset during cleanup in usb_del_gadget() *before* calling flush_work() to\nprevent any new work from being scheduled once cleanup has commenced.\nThe scheduling site, usb_gadget_set_state(), now checks this flag under\nthe lock before queueing the work, thus safely closing the race window.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"In the Linux kernel, the following vulnerability has been resolved:\n\nusb: gadget: udc: fix use-after-free in usb_gadget_state_work\n\nA race condition during gadget teardown can lead to a use-after-free\nin usb_gadget_state_work(), as reported by KASAN:\n\n  BUG: KASAN: invalid-access in sysfs_notify+0x2c/0xd0\n  Workqueue: events usb_gadget_state_work\n\nThe fundamental race occurs because a concurrent event (e.g., an\ninterrupt) can call usb_gadget_set_state() and schedule gadget->work\nat any time during the cleanup process in usb_del_gadget().\n\nCommit 399a45e5237c (\"usb: gadget: core: flush gadget workqueue after\ndevice removal\") attempted to fix this by moving flush_work() to after\ndevice_del(). However, this does not fully solve the race, as a new\nwork item can still be scheduled *after* flush_work() completes but\nbefore the gadget's memory is freed, leading to the same use-after-free.\n\nThis patch fixes the race condition robustly by introducing a 'teardown'\nflag and a 'state_lock' spinlock to the usb_gadget struct. The flag is\nset during cleanup in usb_del_gadget() *before* calling flush_work() to\nprevent any new work from being scheduled once cleanup has commenced.\nThe scheduling site, usb_gadget_set_state(), now checks this flag under\nthe lock before queueing the work, thus safely closing the race window.","source":"cvelist"},{"lang":"es","text":"En el kernel de Linux, la siguiente vulnerabilidad ha sido resuelta:\n\nusb: gadget: udc: corregir uso después de liberación en usb_gadget_state_work\n\nUna condición de carrera durante el desmontaje del gadget puede llevar a un uso después de liberación en usb_gadget_state_work(), según lo informado por KASAN:\n\n  BUG: KASAN: acceso inválido en sysfs_notify+0x2c/0xd0\n  Workqueue: events usb_gadget_state_work\n\nLa condición de carrera fundamental ocurre porque un evento concurrente (por ejemplo, una interrupción) puede llamar a usb_gadget_set_state() y programar gadget -> work en cualquier momento durante el proceso de limpieza en usb_del_gadget().\n\nEl commit 399a45e5237c ('usb: gadget: core: purgar la cola de trabajo del gadget después de la eliminación del dispositivo') intentó corregir esto moviendo flush_work() a después de device_del(). Sin embargo, esto no resuelve completamente la condición de carrera, ya que un nuevo elemento de trabajo aún puede ser programado después de que flush_work() se complete pero antes de que se libere la memoria del gadget, lo que lleva al mismo uso después de liberación.\n\nEste parche corrige la condición de carrera de forma robusta introduciendo un indicador 'teardown' y un spinlock 'state_lock' en la estructura usb_gadget. El indicador se establece durante la limpieza en usb_del_gadget() antes de llamar a flush_work() para evitar que se programe cualquier nuevo trabajo una vez que la limpieza ha comenzado. El sitio de programación, usb_gadget_set_state(), ahora verifica este indicador bajo el bloqueo antes de encolar el trabajo, cerrando así de forma segura la ventana de la condición de carrera.","source":"nvd"}],"published":"2025-12-16T15:06:04.332Z","modified":"2026-10-13T19:10:00.193Z","severities":[],"cwes":[],"affected":[{"ranges":[{"type":"git","introduced":"5702f75375aa9ecf8ad3431aef3fe6ce8c8dbd15","fixed":"dddc944d65169b552e09cb54e3ed4fbb9ea26416","status":"affected"},{"type":"git","introduced":"5702f75375aa9ecf8ad3431aef3fe6ce8c8dbd15","fixed":"eee16f3ff08e759ea828bdf7dc1c0ef2f22134f5","status":"affected"},{"type":"git","introduced":"5702f75375aa9ecf8ad3431aef3fe6ce8c8dbd15","fixed":"c12a0c3ef815ddd67e47f9c819f9fe822fed5467","status":"affected"},{"type":"git","introduced":"5702f75375aa9ecf8ad3431aef3fe6ce8c8dbd15","fixed":"f02a412c0a18f02f0f91b0a3d9788315a721b7fd","status":"affected"},{"type":"git","introduced":"5702f75375aa9ecf8ad3431aef3fe6ce8c8dbd15","fixed":"10014310193cf6736c1aeb4105c5f4a0818d0c65","status":"affected"},{"type":"git","introduced":"5702f75375aa9ecf8ad3431aef3fe6ce8c8dbd15","fixed":"3b32caa73d135eea8fb9cabb45e9fc64c5a3ecb9","status":"affected"},{"type":"git","introduced":"5702f75375aa9ecf8ad3431aef3fe6ce8c8dbd15","fixed":"baeb66fbd4201d1c4325074e78b1f557dff89b5b","status":"affected"}],"vendor":"Linux","product":"Linux","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","source":"cvelist"},{"ranges":[{"version":"3.12","status":"affected"},{"type":"semver","introduced":"0","fixed":"3.12","status":"unaffected"},{"type":"semver","introduced":"5.10.248","lastAffected":"5.10.*","status":"unaffected"},{"type":"semver","introduced":"5.15.198","lastAffected":"5.15.*","status":"unaffected"},{"type":"semver","introduced":"6.1.159","lastAffected":"6.1.*","status":"unaffected"},{"type":"semver","introduced":"6.6.119","lastAffected":"6.6.*","status":"unaffected"},{"type":"semver","introduced":"6.12.61","lastAffected":"6.12.*","status":"unaffected"},{"type":"semver","introduced":"6.17.11","lastAffected":"6.17.*","status":"unaffected"},{"type":"original_commit_for_fix","introduced":"6.18","lastAffected":"*","status":"unaffected"}],"vendor":"Linux","product":"Linux","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","source":"cvelist"}],"references":[{"url":"https://git.kernel.org/stable/c/dddc944d65169b552e09cb54e3ed4fbb9ea26416","tags":[],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/eee16f3ff08e759ea828bdf7dc1c0ef2f22134f5","tags":[],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/c12a0c3ef815ddd67e47f9c819f9fe822fed5467","tags":[],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/f02a412c0a18f02f0f91b0a3d9788315a721b7fd","tags":[],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/10014310193cf6736c1aeb4105c5f4a0818d0c65","tags":[],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/3b32caa73d135eea8fb9cabb45e9fc64c5a3ecb9","tags":[],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/baeb66fbd4201d1c4325074e78b1f557dff89b5b","tags":[],"sources":["cvelist","nvd"]}],"credits":[],"assigner":"Linux","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2025-68282","url":"https://www.cve.org/CVERecord?id=CVE-2025-68282","licence":"CVE Terms of Use","modified":"2026-05-11T21:50:08.718Z"},{"source":"nvd","name":"NVD","id":"CVE-2025-68282","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-68282","licence":"Public domain","modified":"2026-10-13T19:10:00.193Z"}],"updatedAt":"2026-11-25T22:59:09.524Z","epss":{"score":0.0022,"percentile":0.13303,"date":"2026-12-01T12:00:22.000Z"}}