mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v4 0/2] usb: gadget: gadgetfs: fix ep0 request lifetime and event counter
Date: Sun, 8 Nov 2026 21:43:05 -0500	[thread overview]
Message-ID: <071e601f-4a8d-4ff6-bf1f-bae9606ade0d@rowland.harvard.edu> (raw)
In-Reply-To: <20261107-b4-gadgetfs-ep0-v4-0-86bdfd684b54@gmail.com>

On Sat, Nov 07, 2026 at 09:46:12PM +0900, Jing Lin via B4 Relay wrote:
> gadgetfs_unbind() frees the preallocated ep0 request after disconnecting
> the gadget, assuming that no I/O remains active. With dummy_hcd, a
> delayed userspace response can leave the request queued when it is freed,
> which triggers the warning in dummy_free_request() and a use-after-free
> when dummy_udc_stop() drains the endpoint queue.

That's right; gadget drivers in general are responsible for cancelling 
any outstanding ep0 requests when they unbind, and not submitting any 
new ones.

Another thing worth fixing is near the start of gadgetfs_setup(), 
where it casts away the constness of ctrl.  This may not cause problems 
in practice, but it definitely has a bad look.

> gadgetfs_setup() and ep0_write() also race on dev->req and req->buf
> while a control transfer is in flight or while a completed delegated OUT
> transfer is waiting for ep0_read() to copy the payload to userspace.

Can you explain these races in greater detail, showing how they occur?

> Overwriting req->buf with a descriptor pointer causes clean_req() to
> free the descriptor buffer instead of the request buffer.

Can some of these problems be solved more simply, by using a new mutex 
to protect dev->req and related values?

Alan Stern

      parent reply	other threads:[~2026-11-09  2:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07 12:46 Jing Lin via B4 Relay
2026-11-07 12:46 ` [PATCH v4 1/2] usb: gadget: gadgetfs: fix ep0 request lifetime on disconnect Jing Lin via B4 Relay
2026-11-09  2:51   ` Alan Stern
2026-11-07 12:46 ` [PATCH v4 2/2] usb: gadget: gadgetfs: prevent ep0 event counter underflow Jing Lin via B4 Relay
2026-11-09  2:43 ` 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=071e601f-4a8d-4ff6-bf1f-bae9606ade0d@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®