Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Adrian Korwel <adriank20047@gmail.com>
Cc: linux-usb@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] usb: gadget: f_uac1_legacy: fix use-after-free in gaudio_open_snd_dev()
Date: Mon, 25 May 2026 07:56:08 +0200	[thread overview]
Message-ID: <2026052528-resupply-fanatic-496a@gregkh> (raw)
In-Reply-To: <CADgB2mFBdTbad5+W=bDOMO+fe1S4jg+aCNjkgd3B3Guq0WFQdw@mail.gmail.com>

On Sun, May 24, 2026 at 11:33:21PM -0500, Adrian Korwel wrote:
> Three bugs exist in this driver related to ALSA device file lifetime:
> 
> 1. gaudio_open_snd_dev() opens the ALSA control file first, then the
>    PCM playback file. If filp_open() for playback fails, the function
>    returns without closing the already-opened control file handle.
> 
> 2. playback_default_hw_params() return value was ignored. If it fails,
>    both the control and playback file handles are leaked, causing
>    gaudio_cleanup() to call filp_close() on already-freed file objects.
> 
> 3. f_audio_bind() guards gaudio_setup() with an 'audio_opts->bound'
>    flag to prevent re-initialization, but the fail: error path
>    unconditionally calls gaudio_cleanup(). On repeated bind attempts
>    after failure, this closes file handles that were opened in a
>    previous bind invocation and already freed by RCU, causing a
>    use-after-free detected by KASAN:
> 
>    BUG: KASAN: slab-use-after-free in filp_flush+0x23/0x1b0
>    Read of size 8 at addr ffff88810d5523a8 by task bash/306
>    ...
>    gaudio_cleanup+0x59/0x100
>    f_audio_bind+0x4b0/0x590
> 
> Fix all three issues:
> - Close already-opened file handles on each error path in
>   gaudio_open_snd_dev().
> - Check and propagate the return value of playback_default_hw_params().
> - Remove the 'bound' guard and call gaudio_setup() unconditionally in
>   f_audio_bind(), making setup and cleanup a matched pair within each
>   bind invocation. Remove the now-unused 'bound' field from the opts
>   struct.

Why is this not broken up into smaller patches to corrispond with each
issue/fix?  Please do so.


> 
> Additionally, f_audio_disable() was an empty stub. Add
> cancel_work_sync() to ensure the playback work item is not in flight
> when the function is unbound and the audio struct is freed.
> 
> Changes since v1:
> - Added removal of the 'bound' guard in f_audio_bind() which was the
>   root cause of the repeated-bind UAF
> - Added cancel_work_sync() to f_audio_disable()
> - Removed now-unused 'bound' field from struct f_uac1_legacy_opts

The "changes" go below the --- line, right?

thanks,

greg k-h

  reply	other threads:[~2026-05-25  5:57 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25  4:33 [PATCH v2] usb: gadget: f_uac1_legacy: fix use-after-free in gaudio_open_snd_dev() Adrian Korwel
2026-05-25  5:56 ` Greg KH [this message]
2026-05-25 14:30   ` Adrian Korwel
2026-05-25 14:33     ` Adrian Korwel
2026-05-25 14:34     ` Adrian Korwel
2026-05-25 14:36     ` Adrian Korwel
2026-05-25 14:37     ` Adrian Korwel
2026-05-25 19:08       ` Greg KH
2026-05-25 20:24         ` [PATCH 1/4] USB: serial: io_ti: fix heap overflow in build_i2c_fw_hdr() Adrian Korwel
2026-05-25 20:24           ` [PATCH 1/4] usb: gadget: f_uac1_legacy: fix file handle leaks in gaudio_open_snd_dev() Adrian Korwel
2026-05-25 20:24           ` [PATCH 2/4] " Adrian Korwel
2026-05-25 20:24           ` [PATCH 2/4] usb: gadget: f_uac1_legacy: fix use-after-free caused by bound guard Adrian Korwel
2026-05-25 20:24           ` [PATCH 3/4] usb: gadget: f_uac1_legacy: cancel work in f_audio_disable() Adrian Korwel
2026-05-25 20:24           ` [PATCH 3/4] usb: gadget: f_uac1_legacy: fix use-after-free caused by bound guard Adrian Korwel
2026-05-25 20:24           ` [PATCH 4/4] usb: gadget: f_uac1_legacy: cancel work in f_audio_disable() Adrian Korwel
2026-05-25 20:24           ` [PATCH 4/4] usb: typec: thunderbolt: cancel work before altmode is removed Adrian Korwel
2026-05-25 20:26         ` [PATCH 1/4] usb: gadget: f_uac1_legacy: fix file handle leaks in gaudio_open_snd_dev() Adrian Korwel
2026-05-25 20:26           ` [PATCH 2/4] usb: gadget: f_uac1_legacy: fix use-after-free caused by bound guard Adrian Korwel
2026-05-25 20:26           ` [PATCH 3/4] usb: gadget: f_uac1_legacy: cancel work in f_audio_disable() Adrian Korwel
2026-05-25 20:26           ` [PATCH 4/4] usb: typec: thunderbolt: cancel work before altmode is removed Adrian Korwel

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=2026052528-resupply-fanatic-496a@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=adriank20047@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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