Skip to contentSkip to conversation

usb: roles: fix a potential use after free

PATCH In review Wen Yang 3 participants 4 messages Nov 24, 2019 – Nov 26, 2019 USB

lore
Share & tools
lore

Wen Yang

author
#0 lore raw

PATCH 1/1 usb: roles: fix a potential use after free

Free the sw structure only after we are done using it. This patch just moves the put_device() down a bit to avoid the use after free.

Fixes 5c54fcac9a9d ("usb: roles: Take care of driver module reference counting")
Cc Heikki Krogerus <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Chunfeng Yun <[email protected]>
Cc Suzuki K Poulose <[email protected]>
---
 drivers/usb/roles/class.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/roles/class.c +1 -1
index 8273126..63a00ff 100644
@@ -169,8 +169,8 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode)
 void usb_role_switch_put(struct usb_role_switch *sw)
 {
 	if (!IS_ERR_OR_NULL(sw)) {
-		put_device(&sw->dev);
 		module_put(sw->dev.parent->driver->owner);
+		put_device(&sw->dev);
 	}
 }
 EXPORT_SYMBOL_GPL(usb_role_switch_put);
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · Wen Yang

Free the sw structure only after we are done using it. This patch just moves the put_device() down a bit to avoid the use after free.

Fixes 5c54fcac9a9d ("usb: roles: Take care of driver module reference counting")
Cc Heikki Krogerus <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Chunfeng Yun <[email protected]>
Cc Suzuki K Poulose <[email protected]>
---
 drivers/usb/roles/class.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/roles/class.c +1 -1
index 8273126..63a00ff 100644
@@ -169,8 +169,8 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode)
 void usb_role_switch_put(struct usb_role_switch *sw)
 {
 	if (!IS_ERR_OR_NULL(sw)) {
-		put_device(&sw->dev);
 		module_put(sw->dev.parent->driver->owner);
+		put_device(&sw->dev);
 	}
 }
 EXPORT_SYMBOL_GPL(usb_role_switch_put);
Signature · 1 line
1.8.3.1
Signature · 2 lines
Thanks,
Peter Chen
#2 lore raw
In reply to Wen Yang
Quoted 33 lines · Wen Yang

Free the sw structure only after we are done using it. This patch just moves the put_device() down a bit to avoid the use after free.

Fixes 5c54fcac9a9d ("usb: roles: Take care of driver module reference counting")
Cc Heikki Krogerus <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Chunfeng Yun <[email protected]>
Cc Suzuki K Poulose <[email protected]>
---
 drivers/usb/roles/class.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/roles/class.c +1 -1
index 8273126..63a00ff 100644
@@ -169,8 +169,8 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode)
 void usb_role_switch_put(struct usb_role_switch *sw)
 {
 	if (!IS_ERR_OR_NULL(sw)) {
-		put_device(&sw->dev);
 		module_put(sw->dev.parent->driver->owner);
+		put_device(&sw->dev);
 	}
 }
 EXPORT_SYMBOL_GPL(usb_role_switch_put);
Signature · 1 line
1.8.3.1
Signature · 1 line
heikki
Reviewed-by
#3 lore raw
Quoted 5 lines · Heikki Krogerus
Quoted 4 lines · Wen Yang

Free the sw structure only after we are done using it. This patch just moves the put_device() down a bit to avoid the use after free.

Quoted 9 lines
Quoted 9 lines
Fixes 5c54fcac9a9d ("usb: roles: Take care of driver module reference counting")
Cc Heikki Krogerus <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Chunfeng Yun <[email protected]>
Cc Suzuki K Poulose <[email protected]>

Ups, sorry. I meant:

thanks,

Signature · 1 line
heikki