From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: bolewara@gmail.com
Cc: Andrey Konovalov <andreyknvl@gmail.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+9aacea11bc70c3ddaff2@syzkaller.appspotmail.com
Subject: Re: [PATCH v3] usb: raw_gadget: fix use-after-free when UDC is removed
Date: Tue, 4 Aug 2026 17:32:07 +0200 [thread overview]
Message-ID: <2026080421-amaretto-bronco-898c@gregkh> (raw)
In-Reply-To: <20260804-raw-gadget-ep0-uaf-v3-1-bb7cf1d892af@gmail.com>
On Tue, Aug 04, 2026 at 08:32:50PM +0530, Anuj Bolewar via B4 Relay wrote:
> From: Anuj Bolewar <bolewara@gmail.com>
>
> When the UDC is removed (e.g. dummy_hcd unbind via sysfs) while the raw
> gadget fd is still open, usb_del_gadget() destroys the gadget device
> and its name. raw_gadget keeps a dangling pointer in dev->gadget, and
> ioctls dereference it after releasing dev->lock, leading to a
> use-after-free in dev_err() when usb_ep_queue() fails.
>
> Take a gadget reference in gadget_bind() and drop it in dev_free() so
> the gadget device and its name stay alive for as long as the fd is open
> and an ioctl may still dereference dev->gadget.
But bind/unbind have nothing to do with open/close. bind/unbind track
the lifetime of a driver being bound to a device. After unbind happens,
the driver CAN NOT touch the device at all. That's not what you are
fixing here, you are attempting to keep a reference alive that you are
NOT allowed to keep alive, as it is gone.
> gadget_unbind() only
> marks the device as failed under dev->lock; the reference is dropped in
> dev_free(), which runs only after the fd is closed and no ioctl can be
> in flight.
Again, bind/unbind have nothing to do with open/close/ioctl. This is
the "traditional" issue with char devices having their "backing device"
go away. There are many different ways to solve this, none of which is
this patch at all.
So please, go back and rethink the lifetime rules here and do NOT rely
on a LLM to attempt to work it out as obviously it is totally getting it
incorrect.
thanks,
greg k-h
prev parent reply other threads:[~2026-08-04 15:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 15:02 [PATCH v3] usb: raw_gadget: fix use-after-free when UDC is removed Anuj Bolewar via B4 Relay
2026-08-04 15:32 ` Greg Kroah-Hartman [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=2026080421-amaretto-bronco-898c@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=andreyknvl@gmail.com \
--cc=bolewara@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=syzbot+9aacea11bc70c3ddaff2@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