Skip to content

Commit b909df1

Browse files
Benoît Sevenstiwai
authored andcommitted
ALSA: usb-audio: Fix potential out-of-bound accesses for Extigy and Mbox devices
A bogus device can provide a bNumConfigurations value that exceeds the initial value used in usb_get_configuration for allocating dev->config. This can lead to out-of-bounds accesses later, e.g. in usb_destroy_configuration. Signed-off-by: Benoît Sevens <[email protected]> Fixes: 1da177e ("Linux-2.6.12-rc2") Cc: [email protected] Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent cc3d0b5 commit b909df1

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

sound/usb/quirks.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ int snd_usb_create_quirk(struct snd_usb_audio *chip,
555555
static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
556556
{
557557
struct usb_host_config *config = dev->actconfig;
558+
struct usb_device_descriptor new_device_descriptor;
558559
int err;
559560

560561
if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
@@ -566,10 +567,14 @@ static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interfac
566567
if (err < 0)
567568
dev_dbg(&dev->dev, "error sending boot message: %d\n", err);
568569
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
569-
&dev->descriptor, sizeof(dev->descriptor));
570-
config = dev->actconfig;
570+
&new_device_descriptor, sizeof(new_device_descriptor));
571571
if (err < 0)
572572
dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
573+
if (new_device_descriptor.bNumConfigurations > dev->descriptor.bNumConfigurations)
574+
dev_dbg(&dev->dev, "error too large bNumConfigurations: %d\n",
575+
new_device_descriptor.bNumConfigurations);
576+
else
577+
memcpy(&dev->descriptor, &new_device_descriptor, sizeof(dev->descriptor));
573578
err = usb_reset_configuration(dev);
574579
if (err < 0)
575580
dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
@@ -901,6 +906,7 @@ static void mbox2_setup_48_24_magic(struct usb_device *dev)
901906
static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
902907
{
903908
struct usb_host_config *config = dev->actconfig;
909+
struct usb_device_descriptor new_device_descriptor;
904910
int err;
905911
u8 bootresponse[0x12];
906912
int fwsize;
@@ -936,10 +942,14 @@ static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
936942
dev_dbg(&dev->dev, "device initialised!\n");
937943

938944
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
939-
&dev->descriptor, sizeof(dev->descriptor));
940-
config = dev->actconfig;
945+
&new_device_descriptor, sizeof(new_device_descriptor));
941946
if (err < 0)
942947
dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
948+
if (new_device_descriptor.bNumConfigurations > dev->descriptor.bNumConfigurations)
949+
dev_dbg(&dev->dev, "error too large bNumConfigurations: %d\n",
950+
new_device_descriptor.bNumConfigurations);
951+
else
952+
memcpy(&dev->descriptor, &new_device_descriptor, sizeof(dev->descriptor));
943953

944954
err = usb_reset_configuration(dev);
945955
if (err < 0)
@@ -1249,6 +1259,7 @@ static void mbox3_setup_defaults(struct usb_device *dev)
12491259
static int snd_usb_mbox3_boot_quirk(struct usb_device *dev)
12501260
{
12511261
struct usb_host_config *config = dev->actconfig;
1262+
struct usb_device_descriptor new_device_descriptor;
12521263
int err;
12531264
int descriptor_size;
12541265

@@ -1262,10 +1273,14 @@ static int snd_usb_mbox3_boot_quirk(struct usb_device *dev)
12621273
dev_dbg(&dev->dev, "MBOX3: device initialised!\n");
12631274

12641275
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
1265-
&dev->descriptor, sizeof(dev->descriptor));
1266-
config = dev->actconfig;
1276+
&new_device_descriptor, sizeof(new_device_descriptor));
12671277
if (err < 0)
12681278
dev_dbg(&dev->dev, "MBOX3: error usb_get_descriptor: %d\n", err);
1279+
if (new_device_descriptor.bNumConfigurations > dev->descriptor.bNumConfigurations)
1280+
dev_dbg(&dev->dev, "MBOX3: error too large bNumConfigurations: %d\n",
1281+
new_device_descriptor.bNumConfigurations);
1282+
else
1283+
memcpy(&dev->descriptor, &new_device_descriptor, sizeof(dev->descriptor));
12691284

12701285
err = usb_reset_configuration(dev);
12711286
if (err < 0)

0 commit comments

Comments
 (0)