Skip to content

Commit f08adf5

Browse files
committed
USB: gadget: bRequestType is a bitfield, not a enum
Szymon rightly pointed out that the previous check for the endpoint direction in bRequestType was not looking at only the bit involved, but rather the whole value. Normally this is ok, but for some request types, bits other than bit 8 could be set and the check for the endpoint length could not stall correctly. Fix that up by only checking the single bit. Fixes: 153a2d7 ("USB: gadget: detect too-big endpoint 0 requests") Cc: Felipe Balbi <[email protected]> Reported-by: Szymon Heidrich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 99ea221 commit f08adf5

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

drivers/usb/gadget/composite.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,14 +1680,14 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
16801680
u8 endp;
16811681

16821682
if (w_length > USB_COMP_EP0_BUFSIZ) {
1683-
if (ctrl->bRequestType == USB_DIR_OUT) {
1684-
goto done;
1685-
} else {
1683+
if (ctrl->bRequestType & USB_DIR_IN) {
16861684
/* Cast away the const, we are going to overwrite on purpose. */
16871685
__le16 *temp = (__le16 *)&ctrl->wLength;
16881686

16891687
*temp = cpu_to_le16(USB_COMP_EP0_BUFSIZ);
16901688
w_length = USB_COMP_EP0_BUFSIZ;
1689+
} else {
1690+
goto done;
16911691
}
16921692
}
16931693

drivers/usb/gadget/legacy/dbgp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,14 @@ static int dbgp_setup(struct usb_gadget *gadget,
346346
u16 len = 0;
347347

348348
if (length > DBGP_REQ_LEN) {
349-
if (ctrl->bRequestType == USB_DIR_OUT) {
350-
return err;
351-
} else {
349+
if (ctrl->bRequestType & USB_DIR_IN) {
352350
/* Cast away the const, we are going to overwrite on purpose. */
353351
__le16 *temp = (__le16 *)&ctrl->wLength;
354352

355353
*temp = cpu_to_le16(DBGP_REQ_LEN);
356354
length = DBGP_REQ_LEN;
355+
} else {
356+
return err;
357357
}
358358
}
359359

drivers/usb/gadget/legacy/inode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,14 +1334,14 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
13341334
u16 w_length = le16_to_cpu(ctrl->wLength);
13351335

13361336
if (w_length > RBUF_SIZE) {
1337-
if (ctrl->bRequestType == USB_DIR_OUT) {
1338-
return value;
1339-
} else {
1337+
if (ctrl->bRequestType & USB_DIR_IN) {
13401338
/* Cast away the const, we are going to overwrite on purpose. */
13411339
__le16 *temp = (__le16 *)&ctrl->wLength;
13421340

13431341
*temp = cpu_to_le16(RBUF_SIZE);
13441342
w_length = RBUF_SIZE;
1343+
} else {
1344+
return value;
13451345
}
13461346
}
13471347

0 commit comments

Comments
 (0)