mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Krzysztof Mazur <krzysiek@podlesie.net>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-usb@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org,
	Daniel J Blueman <daniel@numascale-asia.com>
Subject: Re: [PATCH 2/2] usb: fail on usb_hub_create_port_device() errors
Date: Tue, 20 Aug 2013 21:07:30 +0200	[thread overview]
Message-ID: <20130820190730.GA13696@shrek.podlesie.net> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1308201415020.1591-100000@iolanthe.rowland.org>

On Tue, Aug 20, 2013 at 02:18:57PM -0400, Alan Stern wrote:
> On Tue, 20 Aug 2013, Krzysztof Mazur wrote:
> 
> > Ignoring usb_hub_create_port_device() errors cause later NULL pointer
> > deference when uninitialized hub->ports[i] entries are dereferenced
> > after port memory allocation error.
> > 
> > Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
> > ---
> > I'm not sure if failing in that case is a good idea, but other solutions
> > are more complex.
> > 
> > I tried also changing hdev->maxchild and skiping initialization
> > of later ports, but it didn't work because in some cases
> > hub->descriptor->bNbrPorts is used instead of hdev->maxchild.
> > With simulated usb_hub_create_port_device() failure I have an Oops
> > in hub_power_on().
> 
> I think this patch is correct.  However, we also should change the 
> other places that refer to bNbrPorts; make them use maxchild instead.

Ok, I can try to catch all such cases and fix problems with
maxchild < bNBrPorts, but I think that changing bNBrPorts to maxchild
might be not enough. For instance:

	for (port1 = 1; port1 <= hub->descriptor->bNbrPorts; port1++)
		if (hub->ports[port1 - 1]->power_is_on)
			set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER);
		else
			usb_clear_port_feature(hub->hdev, port1,
						USB_PORT_FEAT_POWER);

in hub_power_on() should be probably changed to something like:
	
	for (port1 = 1; port1 <= hub->descriptor->bNbrPorts; port1++)
		if (hub->ports[port1 - 1] && hub->ports[port1 - 1]->power_is_on)
			set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER);
		else
			usb_clear_port_feature(hub->hdev, port1,
						USB_PORT_FEAT_POWER);

to disable uninitialized ports.

> 
> > Another possible solution is allowing for uninitialized ports and
> > checking for hub->ports[i] == NULL.
> 
> No, if we can't allocate memory for all the ports then the whole thing 
> should fail.

The usb_hub_create_port_device() might fail also in case of device_add()
error.

> 
> Alan Stern

Thanks,
Krzysiek

  reply	other threads:[~2013-08-20 19:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-20 17:24 [PATCH 0/2] usb: fix hub_configure() error handling Krzysztof Mazur
2013-08-20 17:24 ` [PATCH 1/2] usb: fix cleanup after failure in hub_configure() Krzysztof Mazur
2013-08-20 18:14   ` Alan Stern
2013-08-20 18:42     ` Krzysztof Mazur
2013-08-20 18:59       ` Alan Stern
2013-08-20 19:16         ` Krzysztof Mazur
2013-08-20 19:51           ` Alan Stern
2013-08-20 17:24 ` [PATCH 2/2] usb: fail on usb_hub_create_port_device() errors Krzysztof Mazur
2013-08-20 18:18   ` Alan Stern
2013-08-20 19:07     ` Krzysztof Mazur [this message]
2013-08-20 19:50       ` Alan Stern
2013-08-21  9:25         ` Krzysztof Mazur
2013-08-21 14:25           ` Alan Stern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130820190730.GA13696@shrek.podlesie.net \
    --to=krzysiek@podlesie.net \
    --cc=daniel@numascale-asia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®