]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ALSA: usb-audio: Add sanity checks for endpoint accesses
authorTakashi Iwai <tiwai@suse.de>
Tue, 15 Mar 2016 14:20:58 +0000 (15:20 +0100)
committerChuck Anderson <chuck.anderson@oracle.com>
Thu, 26 May 2016 22:46:29 +0000 (15:46 -0700)
Orabug: 23331117

[ Upstream commit 447d6275f0c21f6cc97a88b3a0c601436a4cdf2a ]

Add some sanity check codes before actually accessing the endpoint via
get_endpoint() in order to avoid the invalid access through a
malformed USB descriptor.  Mostly just checking bNumEndpoints, but in
one place (snd_microii_spdif_default_get()), the validity of iface and
altsetting index is checked as well.

Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=971125
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
(cherry picked from commit 4fa1657957f668fcc9606268df01bc0f3e4f1379)

Signed-off-by: Dan Duval <dan.duval@oracle.com>
sound/usb/clock.c
sound/usb/endpoint.c
sound/usb/mixer_quirks.c
sound/usb/pcm.c

index 2ed260b10f6dc02cd129550ba1067c878034cb07..7ccbcaf6a1476423e0d2becf0bf91f3463a47b46 100644 (file)
@@ -285,6 +285,8 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
        unsigned char data[3];
        int err, crate;
 
+       if (get_iface_desc(alts)->bNumEndpoints < 1)
+               return -EINVAL;
        ep = get_endpoint(alts, 0)->bEndpointAddress;
 
        /* if endpoint doesn't have sampling rate control, bail out */
index 03b074419964967ab16644a916112f1d2c514712..e7f470afd13333046998b2677da151924339d435 100644 (file)
@@ -413,6 +413,9 @@ exit_clear:
  *
  * New endpoints will be added to chip->ep_list and must be freed by
  * calling snd_usb_endpoint_free().
+ *
+ * For SND_USB_ENDPOINT_TYPE_SYNC, the caller needs to guarantee that
+ * bNumEndpoints > 1 beforehand.
  */
 struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
                                              struct usb_host_interface *alts,
index 337c317ead6fbc2fa7e3ae80bcfb7cb64119cf55..e737aeb3c5aa729e71cdad1c4b60bbfa9d279545 100644 (file)
@@ -1531,7 +1531,11 @@ static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
 
        /* use known values for that card: interface#1 altsetting#1 */
        iface = usb_ifnum_to_if(chip->dev, 1);
+       if (!iface || iface->num_altsetting < 2)
+               return -EINVAL;
        alts = &iface->altsetting[1];
+       if (get_iface_desc(alts)->bNumEndpoints < 1)
+               return -EINVAL;
        ep = get_endpoint(alts, 0)->bEndpointAddress;
 
        err = snd_usb_ctl_msg(chip->dev,
index b4ef410e5a982b31adc933153773b34f9ccbbc2b..cbb93258ea992f170a8daf7edf48f46405e30651 100644 (file)
@@ -159,6 +159,8 @@ static int init_pitch_v1(struct snd_usb_audio *chip, int iface,
        unsigned char data[1];
        int err;
 
+       if (get_iface_desc(alts)->bNumEndpoints < 1)
+               return -EINVAL;
        ep = get_endpoint(alts, 0)->bEndpointAddress;
 
        data[0] = 1;