mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Urban <surban@surban.net>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] usb: gadget: dummy_hcd: fix data corruption with queued requests
Date: Sun, 15 Mar 2026 15:06:21 +0000	[thread overview]
Message-ID: <2131664a-9730-4934-9acd-8da72afb6ba5@surban.net> (raw)
In-Reply-To: <9f2c403b-5955-4e6b-a356-330cebead7ed@rowland.harvard.edu>

On 3/15/26 15:44, Alan Stern wrote:
> On Sun, Mar 15, 2026 at 10:03:07AM +0100, Sebastian Urban wrote:
>> The transfer() function in dummy_hcd iterates over all queued gadget
>> requests for a given endpoint via list_for_each_entry(). When the
>> per-frame bandwidth budget is exhausted mid-request, leaving a
>> partially-transferred gadget request, the loop continues to the next
>> queued request instead of stopping.
> 
> Why do you say this?  Did you not see the code (at line 1445
> approximately):
> 
> 		if (unlikely(len == 0))
> 			is_short = 1;
> 		else {
> 			/* not enough bandwidth left? */
> 			if (limit < ep->ep.maxpacket && limit < len)
> 				break;
> 
> It does break out of the loop when there is not enough space remaining
> in the bandwidth budget for another transaction.  But it does so at the
> start of the iteration following the last allowed transfer, rather than
> at the end of last transfer's iteration (as your patch does).
> 
You're right that the existing bandwidth check at line 1444 handles the 
general case of a non-zero request following a partial transfer.

However, if a ZLP follows a partially-transferred request, the check is 
skipped because of the unlikely(len == 0) branch, leading to a false 
complete of the transfer with a shortened length.

Thus the bug can only be triggered by a ZLP. I will resubmit the patch 
with an updated commit message.



  reply	other threads:[~2026-03-15 15:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-15  9:03 Sebastian Urban
2026-03-15 14:44 ` Alan Stern
2026-03-15 15:06   ` Sebastian Urban [this message]
2026-03-15 15:21     ` Alan Stern
2026-03-15 15:28       ` Alan Stern
2026-03-15 15:55         ` Sebastian Urban
2026-03-15 18:23           ` Alan Stern
2026-03-15 15:10   ` [PATCH v2] usb: gadget: dummy_hcd: fix premature URB completion when ZLP follows partial transfer Sebastian Urban
2026-03-15 18:24     ` Alan Stern

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=2131664a-9730-4934-9acd-8da72afb6ba5@surban.net \
    --to=surban@surban.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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

all inboxes | Powered by JetHome®