usb: typec: thunderbolt: cancel work on driver removal
Subsystems (4)
PATCH 1/1 usb: typec: thunderbolt: cancel work on driver removal
The probe and alternate mode callbacks can schedule tbt->work. The remove callback drops the cable and plug references without canceling that work, and the devres core then frees tbt. A pending or running work item can therefore dereference both released objects and the freed tbt allocation.
Cancel the work synchronously before dropping the referenced Type-C objects.
--- drivers/usb/typec/altmodes/thunderbolt.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/typec/altmodes/thunderbolt.c +2 -0
@@ -303,6 +303,8 @@ static void tbt_altmode_remove(struct typec_altmode *alt) {struct tbt_altmode *tbt =typec_altmode_get_drvdata (alt); +cancel_work_sync (&tbt->work); +for (int i =TYPEC_PLUG_SOP_PP ; i >=0 ; --i) {if (tbt->plug[i])typec_altmode_put_plug (tbt->plug[i]);
Signature · 1 line
2.50.1.windows.1
Heikki Krogerus
maintainerQuoted 20 lines · Hongyan Xu
The probe and alternate mode callbacks can schedule
tbt->work. The remove callback drops the cable and plug references without canceling that work, and the devres core then frees tbt. A pending or running work item can therefore dereference both released objects and the freed tbt allocation.Cancel the work synchronously before dropping the referenced Type-C objects.
Fixes 100e25738659 ("usb: typec: Add driver for Thunderbolt 3 Alternate Mode")Signed-off-by Hongyan Xu <[email protected]>--- drivers/usb/typec/altmodes/thunderbolt.c | 2 ++ 1 file changed, 2 insertions(+)drivers/usb/typec/altmodes/thunderbolt.c +0
-0
drivers/usb/typec/altmodes/thunderbolt.c static void tbt_altmode_remove(struct typec_altmode *alt) · line 306
Quoted 4 lines
drivers/usb/typec/altmodes/thunderbolt.c +1
-0@@ -303,6 +303,8 @@ static void tbt_altmode_remove(struct typec_altmode *alt) {struct tbt_altmode *tbt =typec_altmode_get_drvdata (alt); +cancel_work_sync (&tbt->work);
There's already a fix for this one:
https://lore.kernel.org/linux-usb/[email protected]/
thanks,
Signature · 1 line
heikki