All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Jeongjun Park <aha310510@gmail.com>
Cc: tiwai@suse.de, clemens@ladisch.de, hdanton@sina.com,
	linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org,
	perex@perex.cz,
	syzbot+f02665daa2abeef4a947@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] [sound?] [usb?] general protection fault in snd_usbmidi_do_output
Date: Sat, 27 Sep 2025 18:07:55 +0200	[thread overview]
Message-ID: <87cy7banfo.wl-tiwai@suse.de> (raw)
In-Reply-To: <20250927154109.879926-1-aha310510@gmail.com>

On Sat, 27 Sep 2025 17:41:09 +0200,
Jeongjun Park wrote:
> 
> Hi,
> 
> Takashi Iwai <tiwai@suse.de> wrote:
> >
> > On Sat, 27 Sep 2025 12:36:07 +0200,
> > Jeongjun Park wrote:
> > >
> > > syzbot <syzbot+f02665daa2abeef4a947@syzkaller.appspotmail.com> wrote:
> > > >
> > > > Hello,
> > > >
> > > > syzbot has tested the proposed patch but the reproducer is still triggering an issue:
> > > > KASAN: slab-use-after-free Write in snd_usbmidi_in_urb_complete
> > > >
> > > > ==================================================================
> > > > BUG: KASAN: slab-use-after-free in snd_usbmidi_in_urb_complete+0x389/0x3c0 sound/usb/midi.c:251
> > > > Write of size 1 at addr ffff888074717943 by task kworker/1:3/5866
> > > >
> > >
> > > Wow, the UAF bug still occurs?
> > >
> > > But... this UAF seems to be a problem with how midi handles urb rather
> > > than a problem with my patch.
> > >
> > > Is there something wrong with the way snd_usbmidi_in_urb_complete() is
> > > implemented?
> >
> > This can be rather a missing kill-and-cleanup in the code path.
> > So the patch like below.
> >
> > Could you check whether this works for you instead of your fix, too?
> > timer_shutdown_sync() is already called in snd_usbmidi_disconnect(),
> > and the call in snd_usbmidi_free() should be superfluous after this
> > change.
> >
> 
> Since both my tests and syzbot tests did not cause any bugs when applying
> this patch, I think the root cause of this vulnerability is the missing
> kill error_timer + urb.
> 
> So, I think it would be okay to patch it this way, but in addition, since
> most of the endpoint delete-related code that existed in
> snd_usbmidi_free() is now done in snd_usbmidi_disconnect(),
> I think it would be appropriate to modify it to only perform
> kfree(ep->out) as in this patch below.

Yes, it makes sense.


thanks,

Takashi


> ---
>  sound/usb/midi.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/sound/usb/midi.c b/sound/usb/midi.c
> index acb3bf92857c..97e7e7662b12 100644
> --- a/sound/usb/midi.c
> +++ b/sound/usb/midi.c
> @@ -1522,15 +1522,14 @@ static void snd_usbmidi_free(struct snd_usb_midi *umidi)
>  {
>  	int i;
>  
> +	if (!umidi->disconnected)
> +		snd_usbmidi_disconnect(&umidi->list);
> +
>  	for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
>  		struct snd_usb_midi_endpoint *ep = &umidi->endpoints[i];
> -		if (ep->out)
> -			snd_usbmidi_out_endpoint_delete(ep->out);
> -		if (ep->in)
> -			snd_usbmidi_in_endpoint_delete(ep->in);
> +		kfree(ep->out);
>  	}
>  	mutex_destroy(&umidi->mutex);
> -	timer_shutdown_sync(&umidi->error_timer);
>  	kfree(umidi);
>  }
>  
> --
> 
> >
> > thanks,
> >
> > Takashi
> >
> > --- a/sound/usb/midi.c
> > +++ b/sound/usb/midi.c
> > @@ -1522,6 +1522,9 @@ static void snd_usbmidi_free(struct snd_usb_midi *umidi)
> >  {
> >         int i;
> >
> > +       if (!umidi->disconnected)
> > +               snd_usbmidi_disconnect(&umidi->list);
> > +
> >         for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
> >                 struct snd_usb_midi_endpoint *ep = &umidi->endpoints[i];
> >                 if (ep->out)
> 
> Regards,
> Jeongjun Park

  reply	other threads:[~2025-09-27 16:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-27  4:41 [PATCH] ALSA: usb-audio: fix race condition to UAF in snd_usbmidi_free Jeongjun Park
2025-09-27  8:01 ` Takashi Iwai
2025-09-27  8:48   ` Jeongjun Park
2025-09-27  9:39     ` Takashi Iwai
2025-09-27  9:19   ` Hillf Danton
2025-09-27 10:03     ` [syzbot] [sound?] [usb?] general protection fault in snd_usbmidi_do_output syzbot
2025-09-27 10:29       ` Takashi Iwai
2025-09-27 10:55         ` syzbot
2025-09-27 11:53           ` Takashi Iwai
2025-09-27 14:30             ` syzbot
2025-09-27 15:50               ` Jeongjun Park
2025-09-27 16:17                 ` syzbot
2025-09-27 10:36       ` Jeongjun Park
2025-09-27 11:52         ` Takashi Iwai
2025-09-27 12:15           ` Jeongjun Park
2025-09-27 15:41           ` Jeongjun Park
2025-09-27 16:07             ` Takashi Iwai [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-09-22 16:54 syzbot
2025-09-23  0:48 ` Hillf Danton
2025-09-23  2:22   ` syzbot
2025-09-23  7:39 ` Hillf Danton
2025-09-23  9:48   ` 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=87cy7banfo.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=aha310510@gmail.com \
    --cc=clemens@ladisch.de \
    --cc=hdanton@sina.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=syzbot+f02665daa2abeef4a947@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.