diff options
author | Inaky Perez-Gonzalez <inaky@linux.intel.com> | 2007-07-31 23:34:02 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-10-12 17:55:06 -0400 |
commit | 1145065cd0434b0fd5cd7c0efe0f1438fb154ed0 (patch) | |
tree | b124106b43b5b4c656111952200b8b061e685b5c /drivers/usb/core/config.c | |
parent | 16bbab2966309ae82cda3d378964c56096d4858c (diff) |
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>
Diffstat (limited to 'drivers/usb/core/config.c')
-rw-r--r-- | drivers/usb/core/config.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c index cb69aa1e02e8..1a8edcee7f30 100644 --- a/drivers/usb/core/config.c +++ b/drivers/usb/core/config.c | |||
@@ -507,18 +507,30 @@ void usb_destroy_configuration(struct usb_device *dev) | |||
507 | } | 507 | } |
508 | 508 | ||
509 | 509 | ||
510 | // hub-only!! ... and only in reset path, or usb_new_device() | 510 | /* |
511 | // (used by real hubs and virtual root hubs) | 511 | * Get the USB config descriptors, cache and parse'em |
512 | * | ||
513 | * hub-only!! ... and only in reset path, or usb_new_device() | ||
514 | * (used by real hubs and virtual root hubs) | ||
515 | * | ||
516 | * NOTE: if this is a WUSB device and is not authorized, we skip the | ||
517 | * whole thing. A non-authorized USB device has no | ||
518 | * configurations. | ||
519 | */ | ||
512 | int usb_get_configuration(struct usb_device *dev) | 520 | int usb_get_configuration(struct usb_device *dev) |
513 | { | 521 | { |
514 | struct device *ddev = &dev->dev; | 522 | struct device *ddev = &dev->dev; |
515 | int ncfg = dev->descriptor.bNumConfigurations; | 523 | int ncfg = dev->descriptor.bNumConfigurations; |
516 | int result = -ENOMEM; | 524 | int result = 0; |
517 | unsigned int cfgno, length; | 525 | unsigned int cfgno, length; |
518 | unsigned char *buffer; | 526 | unsigned char *buffer; |
519 | unsigned char *bigbuffer; | 527 | unsigned char *bigbuffer; |
520 | struct usb_config_descriptor *desc; | 528 | struct usb_config_descriptor *desc; |
521 | 529 | ||
530 | cfgno = 0; | ||
531 | if (dev->authorized == 0) /* Not really an error */ | ||
532 | goto out_not_authorized; | ||
533 | result = -ENOMEM; | ||
522 | if (ncfg > USB_MAXCONFIG) { | 534 | if (ncfg > USB_MAXCONFIG) { |
523 | dev_warn(ddev, "too many configurations: %d, " | 535 | dev_warn(ddev, "too many configurations: %d, " |
524 | "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG); | 536 | "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG); |
@@ -545,14 +557,15 @@ int usb_get_configuration(struct usb_device *dev) | |||
545 | goto err2; | 557 | goto err2; |
546 | desc = (struct usb_config_descriptor *)buffer; | 558 | desc = (struct usb_config_descriptor *)buffer; |
547 | 559 | ||
548 | for (cfgno = 0; cfgno < ncfg; cfgno++) { | 560 | result = 0; |
561 | for (; cfgno < ncfg; cfgno++) { | ||
549 | /* We grab just the first descriptor so we know how long | 562 | /* We grab just the first descriptor so we know how long |
550 | * the whole configuration is */ | 563 | * the whole configuration is */ |
551 | result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, | 564 | result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, |
552 | buffer, USB_DT_CONFIG_SIZE); | 565 | buffer, USB_DT_CONFIG_SIZE); |
553 | if (result < 0) { | 566 | if (result < 0) { |
554 | dev_err(ddev, "unable to read config index %d " | 567 | dev_err(ddev, "unable to read config index %d " |
555 | "descriptor/%s\n", cfgno, "start"); | 568 | "descriptor/%s: %d\n", cfgno, "start", result); |
556 | dev_err(ddev, "chopping to %d config(s)\n", cfgno); | 569 | dev_err(ddev, "chopping to %d config(s)\n", cfgno); |
557 | dev->descriptor.bNumConfigurations = cfgno; | 570 | dev->descriptor.bNumConfigurations = cfgno; |
558 | break; | 571 | break; |
@@ -599,6 +612,7 @@ int usb_get_configuration(struct usb_device *dev) | |||
599 | 612 | ||
600 | err: | 613 | err: |
601 | kfree(buffer); | 614 | kfree(buffer); |
615 | out_not_authorized: | ||
602 | dev->descriptor.bNumConfigurations = cfgno; | 616 | dev->descriptor.bNumConfigurations = cfgno; |
603 | err2: | 617 | err2: |
604 | if (result == -ENOMEM) | 618 | if (result == -ENOMEM) |