From: Edward Adam Davis <eadavis@sina.com>
To: tiwai@suse.de
Cc: eadavis@sina.com, gregkh@linuxfoundation.org, kees@kernel.org,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
syzbot+c35f34092a4bc9855be6@syzkaller.appspotmail.com,
syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH] usb: gadget: midi2: prevent in/out jack from oob
Date: Sat, 29 Aug 2026 10:05:50 +0800 [thread overview]
Message-ID: <20260829020550.277161-1-eadavis@sina.com> (raw)
In-Reply-To: <87cxv2v46o.wl-tiwai@suse.de>
From: Edward Aadm Davis <eadavis@sina.com>
On Fri, 28 Aug 2026 14:07:43 +0200, Takashi Iwai wrote:
> > The increment of config->jack_out in append_midi1_out_jack() lacked
> > bounds checking, triggering issue [1] when the value approached the
> > limit MAX_CABLES.
> >
> > A similar out-of-bounds issue exists in append_midi1_in_jack(), so it
> > is being fixed as well.
> >
> > Before incrementing jack_out/in, the code now checks if the value has
> > reached the upper limit MAX_CABLES; if so, it exits and returns -EINVAL.
> >
> > Additionally, the jack_id assignment is moved to occur after the jack_out
> > bounds check to prevent wasting IDs on invalid increments.
>
> I think the bug is rather the arrays are too small; they should have
> been twice as the jacks can be added from both input and output.
>
> Both append_midi1_out_jack() and append_midi1_in_jack() are called
> from the loops of midi2->num_midi1_out and midi2->num_midi1_in
> counts, and they are properly upper-bound to MAX_CABLES.
In reproducer, set num_groups and midi1_num_groups to 16, this will cause
num_midi1_in and num_midi1_out to both be 16 (total 32), overflowing the
MAX_CABLES (16) sized arrays on the stack during bind.
>
> Could you check whether the fix below works instead?
Yes, the fix below works.
cheers,
Edward
>
>
> thanks,
>
> Takashi
>
> --- a/drivers/usb/gadget/function/f_midi2.c
> +++ b/drivers/usb/gadget/function/f_midi2.c
> @@ -1634,8 +1634,8 @@ struct f_midi2_usb_config {
>
> /* MIDI 1.0 jacks */
> unsigned char jack_in, jack_out, jack_id;
> - struct usb_midi_in_jack_descriptor jack_ins[MAX_CABLES];
> - struct usb_midi_out_jack_descriptor_1 jack_outs[MAX_CABLES];
> + struct usb_midi_in_jack_descriptor jack_ins[MAX_CABLES * 2];
> + struct usb_midi_out_jack_descriptor_1 jack_outs[MAX_CABLES * 2];
> };
>
> static int append_config(struct f_midi2_usb_config *config, void *d)
prev parent reply other threads:[~2026-08-29 2:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 11:49 [syzbot] [usb?] KASAN: stack-out-of-bounds Write in append_midi1_out_jack syzbot
2026-08-26 13:46 ` [PATCH] usb: gadget: midi2: prevent in/out jack from oob Edward Adam Davis
2026-08-28 12:07 ` Takashi Iwai
2026-08-29 2:05 ` Edward Adam Davis [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=20260829020550.277161-1-eadavis@sina.com \
--to=eadavis@sina.com \
--cc=gregkh@linuxfoundation.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=syzbot+c35f34092a4bc9855be6@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tiwai@suse.de \
/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