mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-18 23:18:20 +00:00
usb: usb_get_configuration() obeys authorization
If called and the device is not authorized to be used, then we don't allow reading the configurations. Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
16bbab2966
commit
1145065cd0
@ -507,18 +507,30 @@ void usb_destroy_configuration(struct usb_device *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// hub-only!! ... and only in reset path, or usb_new_device()
|
/*
|
||||||
// (used by real hubs and virtual root hubs)
|
* Get the USB config descriptors, cache and parse'em
|
||||||
|
*
|
||||||
|
* hub-only!! ... and only in reset path, or usb_new_device()
|
||||||
|
* (used by real hubs and virtual root hubs)
|
||||||
|
*
|
||||||
|
* NOTE: if this is a WUSB device and is not authorized, we skip the
|
||||||
|
* whole thing. A non-authorized USB device has no
|
||||||
|
* configurations.
|
||||||
|
*/
|
||||||
int usb_get_configuration(struct usb_device *dev)
|
int usb_get_configuration(struct usb_device *dev)
|
||||||
{
|
{
|
||||||
struct device *ddev = &dev->dev;
|
struct device *ddev = &dev->dev;
|
||||||
int ncfg = dev->descriptor.bNumConfigurations;
|
int ncfg = dev->descriptor.bNumConfigurations;
|
||||||
int result = -ENOMEM;
|
int result = 0;
|
||||||
unsigned int cfgno, length;
|
unsigned int cfgno, length;
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
unsigned char *bigbuffer;
|
unsigned char *bigbuffer;
|
||||||
struct usb_config_descriptor *desc;
|
struct usb_config_descriptor *desc;
|
||||||
|
|
||||||
|
cfgno = 0;
|
||||||
|
if (dev->authorized == 0) /* Not really an error */
|
||||||
|
goto out_not_authorized;
|
||||||
|
result = -ENOMEM;
|
||||||
if (ncfg > USB_MAXCONFIG) {
|
if (ncfg > USB_MAXCONFIG) {
|
||||||
dev_warn(ddev, "too many configurations: %d, "
|
dev_warn(ddev, "too many configurations: %d, "
|
||||||
"using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);
|
"using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);
|
||||||
@ -545,14 +557,15 @@ int usb_get_configuration(struct usb_device *dev)
|
|||||||
goto err2;
|
goto err2;
|
||||||
desc = (struct usb_config_descriptor *)buffer;
|
desc = (struct usb_config_descriptor *)buffer;
|
||||||
|
|
||||||
for (cfgno = 0; cfgno < ncfg; cfgno++) {
|
result = 0;
|
||||||
|
for (; cfgno < ncfg; cfgno++) {
|
||||||
/* We grab just the first descriptor so we know how long
|
/* We grab just the first descriptor so we know how long
|
||||||
* the whole configuration is */
|
* the whole configuration is */
|
||||||
result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
|
result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
|
||||||
buffer, USB_DT_CONFIG_SIZE);
|
buffer, USB_DT_CONFIG_SIZE);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
dev_err(ddev, "unable to read config index %d "
|
dev_err(ddev, "unable to read config index %d "
|
||||||
"descriptor/%s\n", cfgno, "start");
|
"descriptor/%s: %d\n", cfgno, "start", result);
|
||||||
dev_err(ddev, "chopping to %d config(s)\n", cfgno);
|
dev_err(ddev, "chopping to %d config(s)\n", cfgno);
|
||||||
dev->descriptor.bNumConfigurations = cfgno;
|
dev->descriptor.bNumConfigurations = cfgno;
|
||||||
break;
|
break;
|
||||||
@ -599,6 +612,7 @@ int usb_get_configuration(struct usb_device *dev)
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
kfree(buffer);
|
kfree(buffer);
|
||||||
|
out_not_authorized:
|
||||||
dev->descriptor.bNumConfigurations = cfgno;
|
dev->descriptor.bNumConfigurations = cfgno;
|
||||||
err2:
|
err2:
|
||||||
if (result == -ENOMEM)
|
if (result == -ENOMEM)
|
||||||
|
Loading…
Reference in New Issue
Block a user