usb: gadget: composite: Fix double free memory bug
Hi,
Quoted 4 lines · Chandana Kishori Chiluveru
configfs_dev_cleanupfunction can double freeos_descand buffer when called from different context. For example, this can be called fromcomposite_unbind()and whencomposite_bind()fails.
Shouldn't we instead fix the error path handling of composite_bind and configfs_composite_bind?
Quoted 14 lines
Fix this issue by setting
request and buffer pointer to NULL after kfree.Signed-off-by Chandana Kishori Chiluveru <[email protected]>--- drivers/usb/gadget/composite.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/usb/gadget/composite.c +0
-0
drivers/usb/gadget/composite.c void composite_dev_cleanup(struct · line 2161
Quoted 7 lines
drivers/usb/gadget/composite.c +2
-0@@ -2155,14 +2155,18 @@ void composite_dev_cleanup(struct usb_composite_dev *cdev) usb_ep_dequeue(cdev->gadget->ep0, cdev->os_desc_req);kfree (cdev->os_desc_req->buf); + cdev->os_desc_req->buf =NULL ;usb_ep_free_request (cdev->gadget->ep0, cdev->os_desc_req); + cdev->os_desc_req =NULL ;
Better to move os_desc_cleanup handling to a different function say - composite_os_desc_req_cleanup (to match composite_os_desc_req_prepare())
Quoted 12 lines
drivers/usb/gadget/composite.c +2
-0}if (cdev->req) {if (cdev->setup_pending)usb_ep_dequeue (cdev->gadget->ep0, cdev->req);kfree (cdev->req->buf); + cdev->req->buf =NULL ;usb_ep_free_request (cdev->gadget->ep0, cdev->req); + cdev->req =NULL ; } cdev->next_string_id =0 ;
device_remove_file(&cdev->gadget->dev, &dev_attr_suspended);