Messages in this thread | | | Date | Tue, 26 Feb 2013 11:07:30 -0500 (EST) | From | Alan Stern <> | Subject | Re: [PATCH] Prevent USB hub remove oops |
| |
On Tue, 26 Feb 2013, Daniel J Blueman wrote:
> When initialisation of one or more USB hub ports fails, we can hit a null > pointer dereference when dropping the hub. Analysis shows there's a false > assumption about the ports being setup, so address this.
> Signed-off-by: Daniel J Blueman <daniel@numascale-asia.com> > --- > drivers/usb/core/hub.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c > index cbf7168..a7abc57 100644 > --- a/drivers/usb/core/hub.c > +++ b/drivers/usb/core/hub.c > @@ -1263,7 +1263,7 @@ static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) > if (type != HUB_SUSPEND) { > /* Disconnect all the children */ > for (i = 0; i < hdev->maxchild; ++i) { > - if (hub->ports[i]->child) > + if (hub->ports[i] && hub->ports[i]->child) > usb_disconnect(&hub->ports[i]->child); > } > }
You missed a case. What happens if hub->ports is NULL?
Also, what about this code in hub_disconnect?
for (i = 0; i < hdev->maxchild; i++) usb_hub_remove_port_device(hub, i + 1);
All of these problems can be fixed in hub_configure by setting hub->maxchild to the total number of allocated ports (or 0 if hub_ports can't be allocated).
Alan Stern
| |