usb: gadget: composite: Fix NULL pointer dereference
RFC PATCH 1/1 usb: gadget: composite: Fix NULL pointer dereference
commit f563d230903210acc ("usb: gadget: composite: add req_match method to usb_function") accesses cdev->config even before set config is invoked causing a NULL pointer dereferencing error while running Lecroy Mass Storage Compliance test.
Fix it here by accessing cdev->config only if it is non NULL.
method to usb_function").
---
Running Mass Storage Examples (TD.1.01 Interface Descriptor Test) in Lecroy Compliance Suite produces this NULL pointer dereference abort.
The request is actually
"non-core control reqa0.06 v2a00 i0000 l12"
Tested this patch using USB3 Gen X CV (ch9 tests: usb2 and usb3, link layer testing and MSC tests) and using USB2 X CV (ch9 tests, MSC tests) and verified this doesn't cause any failures.
drivers/usb/gadget/composite.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/usb/gadget/composite.c +7 -4
@@ -1758,10 +1758,13 @@ unknown:* take such requests too, if that's ever needed: to work * in config 0, etc. */ -list_for_each_entry (f, &cdev->config->functions, list) -if (f->req_match && f->req_match (f, ctrl)) - goto try_fun_setup; - f =NULL ; +if (cdev->config) { +list_for_each_entry (f, &cdev->config->functions, list) +if (f->req_match && f->req_match (f, ctrl)) + goto try_fun_setup; + f =NULL ; + } +switch (ctrl->bRequestType &USB_RECIP_MASK ) {case USB_RECIP_INTERFACE :if (!cdev->config || intf >=MAX_CONFIG_INTERFACES )
Signature · 1 line
1.7.9.5