diff mbox series

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

Message ID 20231115121325.471454-1-niklas.neronin@linux.intel.com (mailing list archive)
State Accepted
Commit 974bba5c118f4c2baf00de0356e3e4f7928b4cbc
Headers show
Series usb: config: fix iteration issue in 'usb_get_bos_descriptor()' | expand

Commit Message

Neronin, Niklas Nov. 15, 2023, 12:13 p.m. UTC
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.

Cc: stable@vger.kernel.org
Fixes: 3dd550a2d365 ("USB: usbcore: Fix slab-out-of-bounds bug during device reset")
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
 drivers/usb/core/config.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Mathias Nyman Nov. 17, 2023, 1:50 p.m. UTC | #1
On 15.11.2023 14.13, Niklas Neronin wrote:
> 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.
> 
> Cc: stable@vger.kernel.org
> Fixes: 3dd550a2d365 ("USB: usbcore: Fix slab-out-of-bounds bug during device reset")
> Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
> ---

Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Alan Stern Nov. 17, 2023, 3:50 p.m. UTC | #2
On Wed, Nov 15, 2023 at 02:13:25PM +0200, Niklas Neronin wrote:
> 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.
> 
> Cc: stable@vger.kernel.org
> Fixes: 3dd550a2d365 ("USB: usbcore: Fix slab-out-of-bounds bug during device reset")
> Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
> ---

Reviewed-by: Alan Stern <stern@rowland.harvard.edu>

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

>  drivers/usb/core/config.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> index b19e38d5fd10..7f8d33f92ddb 100644
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -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;
>  	}
> -- 
> 2.42.0
>
diff mbox series

Patch

diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index b19e38d5fd10..7f8d33f92ddb 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -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;
 	}