Skip to contentSkip to conversation

usb: gadget: fix null pointer dereference in usb_put_function_instance()

PATCH In review Jeffin Philip 2 participants 3 messages Aug 16 – Aug 27

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

PATCH 1/1 usb: gadget: fix null pointer dereference in usb_put_function_instance()

usb_put_function_instance() attempts to dereference fd inside fi struct to get mod in uvc_alloc_inst() error path. However, fd is not allocated until later in try_get_usb_function_instance() after allocating fi in uvc_alloc_inst() and thus guranteed to be null in error path. Fix this by adding a null check for fi->fd that returns if fd is null.

Reported-by [email protected]
Fixes 0062f6e56f70 ("usb: gadget: add a forward pointer from usb_function to its "instance"")
---
 drivers/usb/gadget/functions.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/functions.c +1 -1
index 203361a64212..70e31c40e267 100644
@@ -70,7 +70,7 @@ void usb_put_function_instance(struct usb_function_instance *fi)
 {
 	struct module *mod;
 
-	if (!fi)
+	if (!fi || !fi->fd)
 		return;
 
 	mod = fi->fd->mod;
Signature · 1 line
2.55.0
#1 lore raw
Quoted 5 lines · Jeffin Philip

usb_put_function_instance() attempts to dereference fd inside fi struct to get mod in uvc_alloc_inst() error path. However, fd is not allocated until later in try_get_usb_function_instance() after allocating fi in uvc_alloc_inst() and thus guranteed to be null in error path. Fix this by adding a null check for fi->fd that returns if fd is null.

Friendly ping, let me know if you want me to fix anything.

Thanks.
Jeffin.

maintainer
#2 lore raw
Quoted 9 lines · Jeffin Philip
Quoted 5 lines · Jeffin Philip

usb_put_function_instance() attempts to dereference fd inside fi struct to get mod in uvc_alloc_inst() error path. However, fd is not allocated until later in try_get_usb_function_instance() after allocating fi in uvc_alloc_inst() and thus guranteed to be null in error path. Fix this by adding a null check for fi->fd that returns if fd is null.

Friendly ping, let me know if you want me to fix anything.

It's the middle of the merge window, we can't do anything until after -rc1 is out.

In the meantime, please help review other patches on the list so that yours rises to the top.

thanks,

greg k-h