Skip to content

Commit 32fd87b

Browse files
xairygregkh
authored andcommitted
USB: core: only clean up what we allocated
When cleaning up the configurations, make sure we only free the number of configurations and interfaces that we could have allocated. Reported-by: Andrey Konovalov <[email protected]> Cc: stable <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c1ed473 commit 32fd87b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

drivers/usb/core/config.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,18 +764,21 @@ void usb_destroy_configuration(struct usb_device *dev)
764764
return;
765765

766766
if (dev->rawdescriptors) {
767-
for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
767+
for (i = 0; i < dev->descriptor.bNumConfigurations &&
768+
i < USB_MAXCONFIG; i++)
768769
kfree(dev->rawdescriptors[i]);
769770

770771
kfree(dev->rawdescriptors);
771772
dev->rawdescriptors = NULL;
772773
}
773774

774-
for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
775+
for (c = 0; c < dev->descriptor.bNumConfigurations &&
776+
c < USB_MAXCONFIG; c++) {
775777
struct usb_host_config *cf = &dev->config[c];
776778

777779
kfree(cf->string);
778-
for (i = 0; i < cf->desc.bNumInterfaces; i++) {
780+
for (i = 0; i < cf->desc.bNumInterfaces &&
781+
i < USB_MAXINTERFACES; i++) {
779782
if (cf->intf_cache[i])
780783
kref_put(&cf->intf_cache[i]->ref,
781784
usb_release_interface_cache);

0 commit comments

Comments
 (0)