Skip to contentSkip to conversation

usb: gadget: Use correct endianness of the wLength field for WebUSB

PATCH In review Andy Shevchenko 2 participants 2 messages Mar 13, 2023 – Mar 16, 2023 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: Use correct endianness of the wLength field for WebUSB

WebUSB code uses wLength directly without proper endianness conversion. Update it to use already prepared temporary variable w_length instead.

Fixes 93c473948c58 ("usb: gadget: add WebUSB landing page support")
---
 drivers/usb/gadget/composite.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/gadget/composite.c +3 -4
index fa7dd6cf014d..5377d873c08e 100644
@@ -2079,10 +2079,9 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 				sizeof(url_descriptor->URL)
 				- WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset);
 
-			if (ctrl->wLength < WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH
-					    + landing_page_length)
-				landing_page_length = ctrl->wLength
-					- WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset;
+			if (w_length < WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_length)
+				landing_page_length = w_length
+				- WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset;
 
 			memcpy(url_descriptor->URL,
 				cdev->landing_page + landing_page_offset,
Signature · 1 line
2.39.2
Tested-by on v1 1/1
#1 lore raw
Quoted 3 lines · Andy Shevchenko

WebUSB code uses wLength directly without proper endianness conversion. Update it to use already prepared temporary variable w_length instead.

Excellent catch! Thank you very much for finding this. This could have been a very hard to find issue in a big endian system.

I tested this on my local setup and it (unsurprisingly) works like a charm.

Quoted 2 lines
Fixes 93c473948c58 ("usb: gadget: add WebUSB landing page support")
Quoted 25 lines
---
 drivers/usb/gadget/composite.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/gadget/composite.c +3 -5
index fa7dd6cf014d..5377d873c08e 100644
@@ -2079,10 +2079,9 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                                sizeof(url_descriptor->URL)
                                - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset);
 
-                       if (ctrl->wLength < WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH
-                                           + landing_page_length)
-                               landing_page_length = ctrl->wLength
-                                       - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset;
+                       if (w_length < WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_length)
+                               landing_page_length = w_length
+                               - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset;
 
                        memcpy(url_descriptor->URL,
                                cdev->landing_page + landing_page_offset,
--

2.39.2