Re: [PATCH] usb: core: Abort deauthorization if unsetting configurationfails

From: Alan Stern
Date: Wed Dec 04 2013 - 10:21:13 EST


On Tue, 3 Dec 2013, Julius Werner wrote:

> usb_deauthorize_device() tries to unset the configuration of a USB
> device and then unconditionally blows away the configuration descriptors
> with usb_destroy_configuration(). This is bad if the
> usb_set_configuration() call failed before the configuration could be
> correctly unset, since pointers like udev->actconfig can keep pointing
> to the now invalid memory. We have encountered hard to reproduce crashes
> from devices disconnected during suspend due to this, where khubd's
> disconnect handling races with userspace tools that change authorization
> on resume.
>
> This patch ensures that usb_deauthorize_device() aborts when
> usb_set_configuration() fails, and the underlying status code (such as
> ENODEV) is returned to userspace.

I don't like this approach at all. It should always be possible to
deauthorize a device, no matter what.

Instead, how about changing usb_set_configuration() so that it will
never fail when the new config is -1? Except perhaps for -ENODEV
errors (the device has been disconnected), which
usb_deauthorize_device() could check for.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/