Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: f_tcm: Stall on invalid CBW

If the BOT command CBW is invalid, make sure to respond by setting
status endpoint STALL until the next proper CBW or reset.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/96022e2d5225f01a20263a4ba9c2e2c8a63328b8.1733876548.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thinh Nguyen and committed by
Greg Kroah-Hartman
a4d7274d 29ed1705

+16 -1
+15 -1
drivers/usb/gadget/function/f_tcm.c
··· 287 287 return; 288 288 289 289 ret = bot_submit_command(fu, req->buf, req->actual); 290 - if (ret) 290 + if (ret) { 291 291 pr_err("%s(%d): %d\n", __func__, __LINE__, ret); 292 + if (!(fu->flags & USBG_BOT_WEDGED)) 293 + usb_ep_set_wedge(fu->ep_in); 294 + 295 + fu->flags |= USBG_BOT_WEDGED; 296 + bot_enqueue_cmd_cbw(fu); 297 + } else if (fu->flags & USBG_BOT_WEDGED) { 298 + fu->flags &= ~USBG_BOT_WEDGED; 299 + usb_ep_clear_halt(fu->ep_in); 300 + } 292 301 } 293 302 294 303 static int bot_prepare_reqs(struct f_uas *fu) ··· 451 442 452 443 case US_BULK_RESET_REQUEST: 453 444 /* XXX maybe we should remove previous requests for IN + OUT */ 445 + if (fu->flags & USBG_BOT_WEDGED) { 446 + fu->flags &= ~USBG_BOT_WEDGED; 447 + usb_ep_clear_halt(fu->ep_in); 448 + } 449 + 454 450 bot_enqueue_cmd_cbw(fu); 455 451 return 0; 456 452 }
+1
drivers/usb/gadget/function/tcm.h
··· 130 130 #define USBG_USE_STREAMS (1 << 2) 131 131 #define USBG_IS_BOT (1 << 3) 132 132 #define USBG_BOT_CMD_PEND (1 << 4) 133 + #define USBG_BOT_WEDGED (1 << 5) 133 134 134 135 struct usbg_cdb cmd[USBG_NUM_CMDS]; 135 136 struct usb_ep *ep_in;