Skip to content

Commit f5c772b

Browse files
Fan Wugregkh
authored andcommitted
usb: typec: ucsi: ccg: Fix use-after-free of ucsi on remove
commit 1f0bdc2 upstream. The threaded IRQ handler ccg_irq_handler() calls ucsi_notify_common(), which on a connector-change event calls ucsi_connector_change() and schedules connector work. In ucsi_ccg_remove(), ucsi_destroy() frees uc->ucsi (kfree) before free_irq() is called, so a handler invocation already in flight may access the freed object after ucsi_destroy(). CPU 0 (remove) | CPU 1 (threaded IRQ) ucsi_destroy(uc->ucsi) | ccg_irq_handler() kfree(ucsi) // FREE | ucsi_notify_common(uc->ucsi) // USE Move free_irq() before ucsi_destroy() in the remove path. It is kept after ucsi_unregister(): ucsi_unregister() cancels connector work whose handler issues GET_CONNECTOR_STATUS through ucsi_send_command_common(), which waits for a completion that is signalled from the IRQ handler, so the IRQ must stay active until that work has been cancelled. The probe error path already orders free_irq() before ucsi_destroy(). This bug was found by static analysis. Fixes: e32fd98 ("usb: typec: ucsi: ccg: Move to the new API") Cc: stable <stable@kernel.org> Signed-off-by: Fan Wu <fanwu01@zju.edu.cn> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://patch.msgid.link/20260616132011.103279-1-fanwu01@zju.edu.cn Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b1dfdff commit f5c772b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/usb/typec/ucsi/ucsi_ccg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,8 @@ static void ucsi_ccg_remove(struct i2c_client *client)
15181518
cancel_work_sync(&uc->work);
15191519
pm_runtime_disable(uc->dev);
15201520
ucsi_unregister(uc->ucsi);
1521-
ucsi_destroy(uc->ucsi);
15221521
free_irq(uc->irq, uc);
1522+
ucsi_destroy(uc->ucsi);
15231523
}
15241524

15251525
static const struct of_device_id ucsi_ccg_of_match_table[] = {

0 commit comments

Comments
 (0)