usb: gadget: Check for NULL pointer in disconnect
PATCH 1/1 usb: gadget: Check for NULL pointer in disconnect
Added a safety net to make sure thatcomposite_disconnect does not end up disconneting
a NULL device. Prevents NULL pointer crash.
--- drivers/usb/gadget/composite.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/gadget/composite.c +5 -0
@@ -1823,6 +1823,11 @@ void composite_disconnect(struct usb_gadget *gadget)struct usb_composite_dev *cdev =get_gadget_data (gadget);unsigned long flags; +if (!cdev) { +WARN (1 ,"Trying to disconnect a NULL composite device\n" ); +return ; + } +/* REVISIT: should we have config and device level * disconnect callbacks? */
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Quoted 14 lines · Badhri Jagan Sridharan
Added a safety net to make sure that
composite_disconnectdoes not end up disconneting
a NULL device. Prevents NULL pointer crash.Signed-off-by Badhri Jagan Sridharan <[email protected]>--- drivers/usb/gadget/composite.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/gadget/composite.c +0
-0
drivers/usb/gadget/composite.c void composite_disconnect(struct usb_gadget *gadget) · line 1830
Quoted 8 lines
drivers/usb/gadget/composite.c +5
-0@@ -1823,6 +1823,11 @@ void composite_disconnect(struct usb_gadget *gadget)struct usb_composite_dev *cdev =get_gadget_data (gadget);unsigned long flags; +if (!cdev) { +WARN (1 ,"Trying to disconnect a NULL composite device\n" ); +return ; + } +
Do you really see some udc drivers call it after composite_unbind is called? If it is, you may add dump_stack() to track that error.
Besides this, function suspended_show is needed to add cdev NULL pointer checking.
Quoted 10 lines
drivers/usb/gadget/composite.c +0
-0/* REVISIT: should we have config and device level * disconnect callbacks? */ Signature · 6 lines
2.2.0.rc0.207.ga3a616c -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best Regards, Peter Chen
Quoted 5 lines
Do you really see some udc drivers call it after
composite_unbindis called? If it is, you may adddump_stack()to track that error.Besides this, function
suspended_showis needed to add cdev NULL pointer checking.
We see this happening occasionally in *not yet* upstreamed UDC code of some vendors (Yes, disconnect being called after unbind) After reviewing the entire composite.c file, I did notice that none of the functions check for NULL pointer when cdev is obtained from get_gadget_data.
Is crashing/bringing down the whole kernel intentionally left to happen ? Isn't printing a WARN/ERROR msg and returning not the preferable approach ?
Quoted 41 lines · Peter Chen
Quoted 14 lines · Badhri Jagan Sridharan
Added a safety net to make sure that
composite_disconnectdoes not end up disconneting
a NULL device. Prevents NULL pointer crash.Signed-off-by Badhri Jagan Sridharan <[email protected]>--- drivers/usb/gadget/composite.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/gadget/composite.c +0
-0drivers/usb/gadget/composite.c void composite_disconnect(struct usb_gadget *gadget) · line 1830
Quoted 8 lines
drivers/usb/gadget/composite.c +5
-0@@ -1823,6 +1823,11 @@ void composite_disconnect(struct usb_gadget *gadget)struct usb_composite_dev *cdev =get_gadget_data (gadget);unsigned long flags; +if (!cdev) { +WARN (1 ,"Trying to disconnect a NULL composite device\n" ); +return ; + } +Do you really see some udc drivers call it after
composite_unbindis called? If it is, you may adddump_stack()to track that error.Besides this, function
suspended_showis needed to add cdev NULL pointer checking.Quoted 10 lines
drivers/usb/gadget/composite.c +0
-1/* REVISIT: should we have config and device level * disconnect callbacks? */ --2.2.0.rc0.207.ga3a616c
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Badhri Jagan Sridharan
Quoted 5 lines
Do you really see some udc drivers call it after
composite_unbindis called? If it is, you may adddump_stack()to track that error.Besides this, function
suspended_showis needed to add cdev NULL pointer checking.We see this happening occasionally in *not yet* upstreamed UDC code of some vendors (Yes, disconnect being called after unbind)
Does it a spurious interrupt?
I guess if you add struct usb_gadget_driver NULL pointer check check, it will not occur:
if (you_udc->driver) you_udc->driver->disconnect(&you_udc->gadget);
Quoted 5 lines
After reviewing the entire
composite.cfile, I did notice that none of the functions check for NULL pointer when cdev is obtained fromget_gadget_data.
Is crashing/bringing down the whole kernel intentionally left to happen ?
Hmm, I don't think, the design may think it never occurs.
Quoted 2 lines
Isn't printing a WARN/ERROR msg and
returning not the preferable approach ?
I think BUG_ON is more suitable, let's see Felipe's comment.
Quoted 43 lines · Peter Chen
Quoted 41 lines · Badhri Jagan Sridharan
Quoted 14 lines
Added a safety net to make sure that
composite_disconnectdoes not end up disconneting
a NULL device. Prevents NULL pointer crash.Signed-off-by Badhri Jagan Sridharan <[email protected]>--- drivers/usb/gadget/composite.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/gadget/composite.c +0
-0drivers/usb/gadget/composite.c void composite_disconnect(struct usb_gadget *gadget) · line 1830
Quoted 8 lines
drivers/usb/gadget/composite.c +5
-0@@ -1823,6 +1823,11 @@ void composite_disconnect(struct usb_gadget *gadget)struct usb_composite_dev *cdev =get_gadget_data (gadget);unsigned long flags; +if (!cdev) { +WARN (1 ,"Trying to disconnect a NULL composite device\n" ); +return ; + } +Do you really see some udc drivers call it after
composite_unbindis called? If it is, you may adddump_stack()to track that error.Besides this, function
suspended_showis needed to add cdev NULL pointer checking.Quoted 10 lines
drivers/usb/gadget/composite.c +0
-1/* REVISIT: should we have config and device level * disconnect callbacks? */ --2.2.0.rc0.207.ga3a616c
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best Regards, Peter Chen
Quoted 8 lines · Badhri Jagan Sridharan
Quoted 5 lines
Do you really see some udc drivers call it after
composite_unbindis called? If it is, you may adddump_stack()to track that error.Besides this, function
suspended_showis needed to add cdev NULL pointer checking.We see this happening occasionally in *not yet* upstreamed UDC code of some vendors (Yes, disconnect being called after unbind)
fix your UDC. We leave these sort of thing open so people realise they have to fix their drivers.
Signature · 1 line
balbi