From: Michal Pecio <michal.pecio@gmail.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: syzbot <syzbot+832ce9fa3face1b7d44d@syzkaller.appspotmail.com>,
bolewara@gmail.com, devnull@kernel.org,
gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linux-usb@vger.kernel.org,
mchehab@kernel.org, syzkaller-bugs@googlegroups.com,
Daniel Mack <zonque@gmail.com>, Takashi Iwai <tiwai@suse.com>,
linux-sound@vger.kernel.org
Subject: DIY allocation or embedding of URBs in larger structures
Date: Thu, 3 Sep 2026 13:07:57 +0200 [thread overview]
Message-ID: <20260903130757.0668310a.michal.pecio@gmail.com> (raw)
In-Reply-To: <87o6ee8y9e.wl-tiwai@suse.de>
On Thu, 03 Sep 2026 11:44:45 +0200, Takashi Iwai wrote:
> On Thu, 03 Sep 2026 11:24:17 +0200,
> Michal Pecio wrote:
> > So what happens here is that USB core continues to use a URB after
> > completion to implement things like usb_kill_urb(), so URBs are
> > reference counted. Then core decrements the count - one more use.
> >
> > If a driver waits for completion or even usb_kill_urb() to return
> > and then proceeds to free the URB's storage, this becomes a UAF.
> > This driver embeds 2 URBs in its priv and does just that.
> >
> > A URB can only exist as an independent allocation, core will free
> > it if upon finding zero reference count in such case.
>
> So, IIUC, now the URB *must* be always allocated via usb_alloc_urb()
> and an embedded URB isn't allowed? If so, we'd need to address other
> drivers, too.
Yes, that's basically the case and actually has been for a long time.
The only thing that works is for both USB and the driver to call
usb_free_urb() and whoever does last will actually free the storage.
This means URB can't share storage with anything else.
Some drivers got away with making URB the first member of a struct
which is freed together with it. AFAIK this pattern doesn't crash, but
it's deprecated too because it puts a flexible member (in the URB) in
the middle of (the outer) struct.
This pattern here in caiaq has always been one race away from UAF.
Maybe it wasn't very likely to happen, but stuff like PREEMPT_RT and
hypervisors can insert unexpected delays anywhere these days.
Greg KH puts it thusly:
https://lore.kernel.org/linux-usb/2025120716-sway-hypnotic-8cb6@gregkh/
Reragds,
Michal
next prev parent reply other threads:[~2026-09-03 11:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-02 0:53 [syzbot] [media?] KASAN: slab-use-after-free Write in usb_free_urb syzbot
2026-09-02 5:09 ` [syzbot] [usb?] " syzbot
2026-09-03 9:24 ` Michal Pecio
2026-09-03 9:44 ` Takashi Iwai
2026-09-03 11:07 ` Michal Pecio [this message]
2026-09-03 14:37 ` DIY allocation or embedding of URBs in larger structures Takashi Iwai
2026-09-03 9:55 ` [syzbot] [usb?] KASAN: slab-use-after-free Write in usb_free_urb Hillf Danton
2026-09-03 10:01 ` syzbot
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=20260903130757.0668310a.michal.pecio@gmail.com \
--to=michal.pecio@gmail.com \
--cc=bolewara@gmail.com \
--cc=devnull@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=syzbot+832ce9fa3face1b7d44d@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tiwai@suse.com \
--cc=tiwai@suse.de \
--cc=zonque@gmail.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