Skip to contentSkip to conversation

usb: config: fix iteration issue in 'usb_get_bos_descriptor()'

PATCH In review Niklas Neronin 3 participants 3 messages Nov 15, 2023 – Nov 17, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: config: fix iteration issue in 'usb_get_bos_descriptor()'

The BOS descriptor defines a root descriptor and is the base descriptor for accessing a family of related descriptors.

Function 'usb_get_bos_descriptor()' encounters an iteration issue when skipping the 'USB_DT_DEVICE_CAPABILITY' descriptor type. This results in the same descriptor being read repeatedly.

To address this issue, a 'goto' statement is introduced to ensure that the pointer and the amount read is updated correctly. This ensures that the function iterates to the next descriptor instead of reading the same descriptor repeatedly.

Fixes 3dd550a2d365 ("USB: usbcore: Fix slab-out-of-bounds bug during device reset")
---
 drivers/usb/core/config.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/core/config.c +2 -1
index b19e38d5fd10..7f8d33f92ddb 100644
@@ -1047,7 +1047,7 @@ int usb_get_bos_descriptor(struct usb_device *dev)
 
 		if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {
 			dev_notice(ddev, "descriptor type invalid, skip\n");
-			continue;
+			goto skip_to_next_descriptor;
 		}
 
 		switch (cap_type) {
@@ -1078,6 +1078,7 @@ int usb_get_bos_descriptor(struct usb_device *dev)
 			break;
 		}
 
+skip_to_next_descriptor:
 		total_len -= length;
 		buffer += length;
 	}
Signature · 1 line
2.42.0
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Niklas Neronin

The BOS descriptor defines a root descriptor and is the base descriptor for accessing a family of related descriptors.

Function 'usb_get_bos_descriptor()' encounters an iteration issue when skipping the 'USB_DT_DEVICE_CAPABILITY' descriptor type. This results in the same descriptor being read repeatedly.

To address this issue, a 'goto' statement is introduced to ensure that the pointer and the amount read is updated correctly. This ensures that the function iterates to the next descriptor instead of reading the same descriptor repeatedly.

Quoted 4 lines
Fixes 3dd550a2d365 ("USB: usbcore: Fix slab-out-of-bounds bug during device reset")

---

Reviewed-by on v1 1/1
#2 lore raw
In reply to Niklas Neronin
Quoted 12 lines · Niklas Neronin

The BOS descriptor defines a root descriptor and is the base descriptor for accessing a family of related descriptors.

Function 'usb_get_bos_descriptor()' encounters an iteration issue when skipping the 'USB_DT_DEVICE_CAPABILITY' descriptor type. This results in the same descriptor being read repeatedly.

To address this issue, a 'goto' statement is introduced to ensure that the pointer and the amount read is updated correctly. This ensures that the function iterates to the next descriptor instead of reading the same descriptor repeatedly.

Quoted 4 lines
Fixes 3dd550a2d365 ("USB: usbcore: Fix slab-out-of-bounds bug during device reset")

---

Don't know how I missed that four years ago...

Quoted 27 lines
 drivers/usb/core/config.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/core/config.c +2 -1
index b19e38d5fd10..7f8d33f92ddb 100644
@@ -1047,7 +1047,7 @@ int usb_get_bos_descriptor(struct usb_device *dev)
 
 		if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {
 			dev_notice(ddev, "descriptor type invalid, skip\n");
-			continue;
+			goto skip_to_next_descriptor;
 		}
 
 		switch (cap_type) {
@@ -1078,6 +1078,7 @@ int usb_get_bos_descriptor(struct usb_device *dev)
 			break;
 		}
 
+skip_to_next_descriptor:
 		total_len -= length;
 		buffer += length;
 	}
Signature · 1 line
2.42.0