From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Gary Guo <gary@garyguo.net>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Toke Høiland-Jørgensen" <toke@toke.dk>,
"Johan Hovold" <johan@kernel.org>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Petko Manolov" <petkan@nucleusys.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Chas Williams" <3chas3@gmail.com>,
"Alan Stern" <stern@rowland.harvard.edu>,
linux-usb@vger.kernel.org, driver-core@lists.linux.dev,
linux-wireless@vger.kernel.org, linux-media@vger.kernel.org,
linux-atm-general@lists.sourceforge.net, netdev@vger.kernel.org,
usb-storage@lists.one-eyed-alien.net,
linux-kernel@vger.kernel.org,
"Manuel Ebner" <manuelebner@mailbox.org>
Subject: Re: [PATCH v2 0/7] usb: fix UAF related to dynamic ID
Date: Fri, 10 Jul 2026 15:13:21 +0200 [thread overview]
Message-ID: <2026071051-finishing-denial-d652@gregkh> (raw)
In-Reply-To: <20260707-usb_dyn_id_uaf-v2-0-632dcf3adfba@garyguo.net>
On Tue, Jul 07, 2026 at 01:26:39PM +0100, Gary Guo wrote:
> This is the USB version of the dynamic ID UAF fix similar to that of PCI
> [1]. usb_match_dynamic_id returns a pointer to field of usb_dynid, which
> can be freed when dynamic ID is removed via sysfs. It can be triggered with
> the following sequence:
>
> echo <vid> <pid> > /sys/bus/usb/drivers/<name>/new_id
> <probe start>
> echo <vid> <pid> > /sys/bus/usb/drivers/<name>/remove_id
> <probe use ID>
>
> Fix it by making a stack copy of the ID. This does mean that the lifetime
> of ID is scoped to probe (which is already the case but never spelled out
> explicitly). Drivers use these device IDs creatively, so this series also
> fix these drivers.
>
> The following coccinelle script is used to find all cases that are deemed
> suspicious. Only useful case for IDs should be access its fields, or
> forwarding (without type cast) to functions that do so.
>
> @usage@
> identifier fn, id;
> position p;
> @@
> fn(..., struct usb_device_id *id, ...)
> {
> ...
> id@p
> ...
> }
>
> // Due to cocci isomorphism this needs to be explicit
> @bad@
> identifier fn, id;
> type T;
> position usage.p;
> @@
> fn(..., struct usb_device_id *id, ...)
> {
> ...
> (T*)id@p
> ...
> }
>
> // Good use cases
> @good@
> identifier fn, id, fld;
> expression E;
> position usage.p;
> @@
> fn(..., struct usb_device_id *id, ...)
> {
> ...
> (
> id@p->fld
> |
> E(..., id@p, ...)
> |
> // Redundant checks, but ignore
> !id@p
> |
> // Redundant checks, but ignore
> id ? ... : ...
> )
> ...
> }
>
> @script:python depends on usage && (bad || !good)@
> p << usage.p;
> @@
> coccilib.report.print_report(p[0], "suspicious use of device ID")
>
> There're 3 drivers that store usb_device_id, and they're converted to just
> use driver_info instead. The other fields of usb_device_id can be easily
> retrieved from usb_device via descriptor.id{Vendor,Product}.
>
> There're also a few users that rely on pointer arithmetics. Pegaus and
> xusbatm are converted to use driver_info. All unusal USB mass storage
> drivers rely on pointer arithemtic to index into a side table, because USB
> storage subsystem is using the driver_data for flags. Luckily all these
> drivers set no_dynamic_id. Ideally these could be fixed too but their
> maintainers probably have a better idea of how.
>
> Link: https://lore.kernel.org/driver-core/20260706-pci_id_fix-v3-0-2d48fc025acc@garyguo.net [1]
>
> Signed-off-by: Gary Guo <gary@garyguo.net>
Thanks for these. I had an old patch series that attempted to do some
locking in this area to fix this up, but this version is much nicer.
I'll go queue it up now.
greg k-h
prev parent reply other threads:[~2026-07-10 13:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 12:26 [PATCH v2 0/7] usb: fix UAF related to dynamic ID Gary Guo
2026-07-07 12:26 ` [PATCH v2 1/7] wifi: ath9k_htc: don't store usb_device_id Gary Guo
2026-07-07 12:26 ` [PATCH v2 2/7] usb: usbtmc: " Gary Guo
2026-07-07 12:26 ` [PATCH v2 3/7] usb: serial: spcp8x5: " Gary Guo
2026-07-07 12:26 ` [PATCH v2 4/7] media: as102: do not rely on id table address comparison Gary Guo
2026-07-07 12:26 ` [PATCH v2 5/7] net: usb: pegasus: don't rely on id table pointer arithmetic Gary Guo
2026-07-07 12:26 ` [PATCH v2 6/7] usb: xusbatm: " Gary Guo
2026-07-07 12:26 ` [PATCH v2 7/7] usb: fix UAF when probe runs concurrent to dyn ID removal Gary Guo
2026-07-07 13:41 ` Danilo Krummrich
2026-07-10 13:13 ` 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=2026071051-finishing-denial-d652@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=3chas3@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=dakr@kernel.org \
--cc=davem@davemloft.net \
--cc=driver-core@lists.linux.dev \
--cc=edumazet@google.com \
--cc=gary@garyguo.net \
--cc=johan@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-atm-general@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=manuelebner@mailbox.org \
--cc=mchehab@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petkan@nucleusys.com \
--cc=rafael@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=toke@toke.dk \
--cc=usb-storage@lists.one-eyed-alien.net \
/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