]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ALSA: usb: Fix UBSAN warning in parse_audio_unit()
authorTakashi Iwai <tiwai@suse.de>
Sun, 28 Jul 2024 16:09:44 +0000 (12:09 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jan 2025 12:24:51 +0000 (13:24 +0100)
[ Upstream commit 2f38cf730caedaeacdefb7ff35b0a3c1168117f9 ]

A malformed USB descriptor may pass the lengthy mixer description with
a lot of channels, and this may overflow the 32bit integer shift
size, as caught by syzbot UBSAN test.  Although this won't cause any
real trouble, it's better to address.

This patch introduces a sanity check of the number of channels to bail
out the parsing when too many channels are found.

Reported-by: syzbot+78d5b129a762182225aa@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/0000000000000adac5061d3c7355@google.com
Link: https://patch.msgid.link/20240715123619.26612-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/usb/mixer.c

index b598f8f0d06ec2e058144956278fc139ac39a117..8826a588f5ab8836f0009a3aecf343e44d5b9c00 100644 (file)
@@ -1932,6 +1932,13 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
                bmaControls = ftr->bmaControls;
        }
 
+       if (channels > 32) {
+               usb_audio_info(state->chip,
+                              "usbmixer: too many channels (%d) in unit %d\n",
+                              channels, unitid);
+               return -EINVAL;
+       }
+
        /* parse the source unit */
        err = parse_audio_unit(state, hdr->bSourceID);
        if (err < 0)