extcon: fix work-vs-devres teardown use-after-free in MUIC/connector drivers
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest5 patches 1 replyIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | extcon: intel-int3496: drain ID work before its GPIOs and extcon device are freeddrivers/ | +4 | 1 reply | |
| 2/5 | extcon: palmas: drain ID-detect work before the extcon device is freeddrivers/ | +6 | 0 replies | |
| 3/5 | extcon: max8997: drain MUIC IRQ work before extcon device is freeddrivers/ | +13 | 0 replies | |
| 4/5 | extcon: max14577: drain MUIC IRQ work before extcon device is freeddrivers/ | +14 | 0 replies | |
| 5/5 | extcon: max77693: drain MUIC IRQ work before extcon device is freeddrivers/ | +14 | 0 replies |
Reviews trailers per patch
1 of 5 patches has a Reviewed-by or Acked-by.
| Patch | Hans de Goede |
|---|---|
| 1/5 | R-b |
| 2/5 | |
| 3/5 | |
| 4/5 | |
| 5/5 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 0/5] extcon: fix work-vs-devres teardown use-after-free in MUIC/connector drivers
From: Hyunjung Ko <[email protected]>
Five extcon drivers register a detect/IRQ work for device-managed cancellation (devm_work_autocancel() / devm_delayed_work_autocancel()) in their probe function *before* they acquire the resources that the work handler dereferences -- most importantly the extcon device from devm_extcon_dev_allocate() / devm_extcon_dev_register(), and for intel-int3496 also several GPIO descriptors.
devres unwinds in reverse registration order, so on unbind the extcon device (and the GPIOs) are released first and the work is cancelled last:
/* free_irq() */ devm_extcon_dev_unregister() / extcon freed ... cancel_[delayed_]work_sync(&work); /* too late */
The work is armed from the IRQ handler (schedule_work() in the MUIC drivers; queue_delayed_work()/mod_delayed_work() in palmas/int3496), so an instance can still be pending or running at unbind. When it runs in the window after the extcon device has been freed but before the work is cancelled, the handler dereferences freed memory via extcon_set_state_sync() -> use-after-free. The MUIC drivers' early "if (!info->edev) return;" guard does not help: info is itself devm memory freed last, so info->edev is a dangling, non-NULL pointer in that window rather than NULL.
Each patch fixes one driver by moving the devm work-cancel registration to *after* the extcon device (and, for int3496, the GPIOs) are acquired and registered, and still *before* the IRQ that arms the work. Teardown then runs in the correct order: free IRQ -> drain/cancel work -> free extcon device. The relocated devm_[delayed_]work_autocancel() still performs the INIT before the work's first queuing site (the IRQ handler, requested afterwards), so no queue-before-INIT window is introduced. No functional change otherwise.
Found by static analysis / code review. None of the five is reproduced on hardware: each needs its MUIC/PMIC/USB-ID-mux chip and is not QEMU-reproducible. Treat accordingly.
Hyunjung Ko (5):
extcon: intel-int3496: drain ID work before its GPIOs and extcon device are freed
extcon: palmas: drain ID-detect work before the extcon device is freed
extcon: max8997: drain MUIC IRQ work before extcon device is freed
extcon: max14577: drain MUIC IRQ work before extcon device is freed
extcon: max77693: drain MUIC IRQ work before extcon device is freed
drivers/extcon/extcon-intel-int3496.c | 7 ++++--- drivers/extcon/extcon-palmas.c | 12 ++++++------ drivers/extcon/extcon-max8997.c | 26 +++++++++++++------------- drivers/extcon/extcon-max14577.c | 28 ++++++++++++++-------------- drivers/extcon/extcon-max77693.c | 28 ++++++++++++++-------------- 5 files changed, 51 insertions(+), 50 deletions(-)
--
2.43.0