Skip to contentSkip to conversation

usb: gadget: uvc: fix use-after-free in extension drop

PATCH New Shuangpeng Bai 1 participant 1 message Aug 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: uvc: fix use-after-free in extension drop

uvcg_extension_make() adds a newly allocated extension unit to the extension_units list before configfs attaches the item. If attaching the item fails, configfs unlinks it and invokes the drop callback during error cleanup.

On this path, config_item_put() in uvcg_extension_drop() can drop the last reference and free the extension unit. The subsequent list_del() and descriptor cleanup then access the freed object.

Remove the extension unit from the list and free its descriptors while the config item still holds the object alive. Drop the config item reference only after all accesses to the extension unit are complete.

Fixes 0525210c9840 ("usb: gadget: uvc: Allow definition of XUs in configfs")
---
 drivers/usb/gadget/function/uvc_configfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/function/uvc_configfs.c +2 -1
index 70a1415ea401..86facba5109f 100644
@@ -1256,12 +1256,13 @@ static void uvcg_extension_drop(struct config_group *group, struct config_item *
 
 	mutex_lock(&opts->lock);
 
-	config_item_put(item);
 	list_del(&xu->list);
 	kfree(xu->desc.baSourceID);
 	kfree(xu->desc.bmControls);
 
 	mutex_unlock(&opts->lock);
+
+	config_item_put(item);
 }
 
 static struct config_item *uvcg_extension_make(struct config_group *group, const char *name)
Signature · 1 line
2.43.0