Takashi Iwai c1d342
From 0141254b0a74b37aa7eb13d42a56adba84d51c73 Mon Sep 17 00:00:00 2001
Takashi Iwai c1d342
From: Johan Hovold <johan@kernel.org>
Takashi Iwai c1d342
Date: Fri, 20 Dec 2019 10:31:34 +0100
Takashi Iwai c1d342
Subject: [PATCH] ALSA: usb-audio: fix set_format altsetting sanity check
Takashi Iwai c1d342
Git-commit: 0141254b0a74b37aa7eb13d42a56adba84d51c73
Takashi Iwai d0f0e2
Patch-mainline: v5.5-rc5
Takashi Iwai c1d342
References: bsc#1051510
Takashi Iwai c1d342
Takashi Iwai c1d342
Make sure to check the return value of usb_altnum_to_altsetting() to
Takashi Iwai c1d342
avoid dereferencing a NULL pointer when the requested alternate settings
Takashi Iwai c1d342
is missing.
Takashi Iwai c1d342
Takashi Iwai c1d342
The format altsetting number may come from a quirk table and there does
Takashi Iwai c1d342
not seem to be any other validation of it (the corresponding index is
Takashi Iwai c1d342
checked however).
Takashi Iwai c1d342
Takashi Iwai c1d342
Fixes: b099b9693d23 ("ALSA: usb-audio: Avoid superfluous usb_set_interface() calls")
Takashi Iwai c1d342
Cc: stable <stable@vger.kernel.org>     # 4.18
Takashi Iwai c1d342
Signed-off-by: Johan Hovold <johan@kernel.org>
Takashi Iwai c1d342
Link: https://lore.kernel.org/r/20191220093134.1248-1-johan@kernel.org
Takashi Iwai c1d342
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Takashi Iwai c1d342
Takashi Iwai c1d342
---
Takashi Iwai c1d342
 sound/usb/pcm.c |    4 ++--
Takashi Iwai c1d342
 1 file changed, 2 insertions(+), 2 deletions(-)
Takashi Iwai c1d342
Takashi Iwai c1d342
--- a/sound/usb/pcm.c
Takashi Iwai c1d342
+++ b/sound/usb/pcm.c
Takashi Iwai c1d342
@@ -511,9 +511,9 @@ static int set_format(struct snd_usb_sub
Takashi Iwai c1d342
 	if (WARN_ON(!iface))
Takashi Iwai c1d342
 		return -EINVAL;
Takashi Iwai c1d342
 	alts = usb_altnum_to_altsetting(iface, fmt->altsetting);
Takashi Iwai c1d342
-	altsd = get_iface_desc(alts);
Takashi Iwai c1d342
-	if (WARN_ON(altsd->bAlternateSetting != fmt->altsetting))
Takashi Iwai c1d342
+	if (WARN_ON(!alts))
Takashi Iwai c1d342
 		return -EINVAL;
Takashi Iwai c1d342
+	altsd = get_iface_desc(alts);
Takashi Iwai c1d342
 
Takashi Iwai c1d342
 	if (fmt == subs->cur_audiofmt)
Takashi Iwai c1d342
 		return 0;