Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jaegyun Lee" <dreams200260@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH 2/2] usb: gadget: f_tcm: complete the Bulk-Only Reset status stage
Date: Sun, 29 Nov 2026 13:56:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-239659@kernel.org> (raw)
In-Reply-To: <20261129134752.422736-2-dreams200260@gmail.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] usb: gadget: f_tcm: data race in usbg_bot_setup() and
  bot_cmd_complete() [1]
--

commit 8c8c2b026d0d7c87ed616a18a1d98e7e4805cec5
Author: Jaegyun Lee <dreams200260@gmail.com>

usb: gadget: f_tcm: complete the Bulk-Only Reset status stage

This commit validates the USB control request fields for
US_BULK_RESET_REQUEST in usbg_bot_setup() and queues a zero-length status
stage response on ep0.

> diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
> index 2d74ca7c6d126..b213f57cb8296 100644
> --- a/drivers/usb/gadget/function/f_tcm.c
> +++ b/drivers/usb/gadget/function/f_tcm.c
> @@ -466,6 +466,10 @@ static int usbg_bot_setup(struct usb_function *f,
>  		return usb_ep_queue(cdev->gadget->ep0, cdev->req, GFP_ATOMIC);
>  
>  	case US_BULK_RESET_REQUEST:
> +		if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_CLASS |
> +					    USB_RECIP_INTERFACE) || w_value || w_length)
> +			return -EINVAL;
> +
>  		bot_dequeue_req(fu->ep_in, fu->bot_req_in);
>  		bot_dequeue_req(fu->ep_out, fu->bot_req_out);
>  		bot_dequeue_req(fu->ep_in, fu->bot_status.req);
> @@ -475,7 +479,9 @@ static int usbg_bot_setup(struct usb_function *f,
>  		}
>  
>  		bot_enqueue_cmd_cbw(fu);

[Severity: High]
This problem wasn't introduced by this patch, but can usbg_bot_setup() and
bot_cmd_complete() race on fu->flags [1]?

The USB gadget framework does not serialize ep0 setup callbacks against bulk
endpoint completion callbacks across CPUs.  Both usbg_bot_setup() (and its
call to bot_enqueue_cmd_cbw()) and bot_cmd_complete() perform unlocked
read-modify-write updates on fu->flags:

drivers/usb/gadget/function/f_tcm.c:bot_cmd_complete() {
	...
	fu->flags &= ~USBG_BOT_CMD_PEND;
	...
	ret = bot_submit_command(fu, req->buf, req->actual);
	if (ret) {
		...
		fu->flags |= USBG_BOT_WEDGED;
		bot_enqueue_cmd_cbw(fu);
	} else if (fu->flags & USBG_BOT_WEDGED) {
		fu->flags &= ~USBG_BOT_WEDGED;
		usb_ep_clear_halt(fu->ep_in);
	}
}

If an ep0 reset arrives while an ep_out CBW completion is running on another
CPU, one update can clobber the other:

CPU0                                CPU1
usbg_bot_setup()                    bot_cmd_complete()
                                      [read fu->flags]
  [read fu->flags]
  fu->flags &= ~USBG_BOT_WEDGED;      fu->flags &= ~USBG_BOT_CMD_PEND;
  [write fu->flags]
                                      [write fu->flags]  <-- lost update

Losing an update to USBG_BOT_CMD_PEND or USBG_BOT_WEDGED can either
double-queue the CBW request or leave USBG_BOT_CMD_PEND stuck set so that
bot_enqueue_cmd_cbw() never queues another CBW.

[1] https://sashiko.dev/#/bug/linux-7f1632bf-7fa1-4d1c-9f74-d3b84235cdd5

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129134752.422736-1-dreams200260@gmail.com?part=2

  reply	other threads:[~2026-11-29 13:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 13:47 [PATCH 1/2] usb: gadget: f_tcm: dequeue data requests on Bulk-Only Reset Jaegyun Lee
2026-11-29 13:47 ` [PATCH 2/2] usb: gadget: f_tcm: complete the Bulk-Only Reset status stage Jaegyun Lee
2026-11-29 13:56   ` sashiko-bot [this message]
2026-11-29 14:04 ` [PATCH 1/2] usb: gadget: f_tcm: dequeue data requests on Bulk-Only Reset sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-239659@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dreams200260@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox