From: Alan Stern <stern@rowland.harvard.edu>
To: kayano050408@gmail.com
Cc: Neill Kapron <nkapron@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+c73e1942197af9f54ca3@syzkaller.appspotmail.com,
stable@vger.kernel.org
Subject: Re: [PATCH v8 0/4] usb: gadget: gadgetfs: fix ep0 request lifetime and event counter
Date: Tue, 10 Nov 2026 17:49:38 -0500 [thread overview]
Message-ID: <a63177cc-ab89-411a-a6f0-a8a71925aa43@rowland.harvard.edu> (raw)
In-Reply-To: <20261110-gadgetfs-ep0-v8-v8-0-8f90434574fe@gmail.com>
On Tue, Nov 10, 2026 at 12:13:21PM +0800, Jing Lin via B4 Relay wrote:
> This series fixes the ep0 request lifetime and shared request buffer
> races in gadgetfs, and the pre-existing event counter underflow.
>
> The first patch covers request lifetime and buffer ownership, the second
> the ep0 setup abort and unbind state races, the third the event counter
> underflow, and the fourth removes the const cast in gadgetfs_setup().
>
> The setup() callback runs in interrupt context and may not sleep, so a
> mutex cannot be used to serialize it against ep0_read() and ep0_write().
> The shared request state remains protected by dev->lock and the control
> payloads are handed off through private buffers.
>
> The series was tested with the syzbot reproducer and with targeted
> lifecycle, request-reuse, abort, unbind, stale-setup, and event-counter
> tests on arm64 QEMU with dummy_hcd, KASAN, and lockdep. The syzbot
> reproducer still exits 137 on the fixed kernel without a BUG, WARNING,
> KASAN report, or lockdep splat.
>
> Signed-off-by: Jing Lin <kayano050408@gmail.com>
> ---
I'm going to need some time to refresh my memory on how all this stuff
works in the current driver before I can review these patches properly.
And since I'm going to be very busy during the next few days with other
matters, it will be a while before I can reply.
But first, one thought about coordinating setup packets and their
replies. It seems that there's an unavoidable race between a gadget
driver queuing a request in response to an old setup packet and the UDC
driver invoking the gadget driver's ->setup() callback for a newly
arrived setup packet:
UDC driver Gadget driver
---------- -------------
Setup packet arrives
Call ->setup()
->setup() returns DELAYED_STATUS
Prepare proper reply to IN request
or carry out actions needed for
OUT request
New setup packet arrives
Call ->setup Call usb_ep_queue() with reply to
or status for first setup
At this point there's no way for the UDC driver to know whether the
request it was just asked to queue is a response to the old setup packet
or the new one. This is a real flaw in the gadget API.
I've often thought that UDC drivers should assign a sequential ID number
to each setup packet and pass this number to the ->setup() callback, and
gadget drivers should include the number in their response so that the
UDC driver can tell whether the response is obsolete. Too late to
change the API now, unfortunately.
Alan Stern
prev parent reply other threads:[~2026-11-10 22:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 4:13 Jing Lin via B4 Relay
2026-11-10 4:13 ` [PATCH v8 1/4] usb: gadget: gadgetfs: fix ep0 request lifetime and buffer races Jing Lin via B4 Relay
2026-11-10 4:13 ` [PATCH v8 2/4] usb: gadget: gadgetfs: fix ep0 setup abort and unbind state races Jing Lin via B4 Relay
2026-11-10 4:13 ` [PATCH v8 3/4] usb: gadget: gadgetfs: prevent ep0 event counter underflow Jing Lin via B4 Relay
2026-11-10 4:13 ` [PATCH v8 4/4] usb: gadget: gadgetfs: avoid writing through the const setup pointer Jing Lin via B4 Relay
2026-11-10 22:49 ` Alan Stern [this message]
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=a63177cc-ab89-411a-a6f0-a8a71925aa43@rowland.harvard.edu \
--to=stern@rowland.harvard.edu \
--cc=gregkh@linuxfoundation.org \
--cc=kayano050408@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
--cc=stable@vger.kernel.org \
--cc=syzbot+c73e1942197af9f54ca3@syzkaller.appspotmail.com \
/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®