Skip to content

Commit e256926

Browse files
committed
ALSA: usb-audio: Fix a DMA to stack memory bug
jira VULN-46737 cve-bf CVE-2024-53197 commit-author Dan Carpenter <[email protected]> commit f7d306b upstream-diff This kernel doesn't have snd_usb_mbox3_boot_quirk(), so that change hunk from the upstream commit isn't necessary. The usb_get_descriptor() function does DMA so we're not allowed to use a stack buffer for that. Doing DMA to the stack is not portable all architectures. Move the "new_device_descriptor" from being stored on the stack and allocate it with kmalloc() instead. Fixes: b909df1 ("ALSA: usb-audio: Fix potential out-of-bound accesses for Extigy and Mbox devices") Cc: [email protected] Signed-off-by: Dan Carpenter <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]> (cherry picked from commit f7d306b) Signed-off-by: Brett Mastbergen <[email protected]>
1 parent 07d158c commit e256926

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

sound/usb/quirks.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ int snd_usb_create_quirk(struct snd_usb_audio *chip,
577577
static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
578578
{
579579
struct usb_host_config *config = dev->actconfig;
580-
struct usb_device_descriptor new_device_descriptor;
580+
struct usb_device_descriptor *new_device_descriptor __free(kfree) = NULL;
581581
int err;
582582

583583
if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
@@ -588,15 +588,19 @@ static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interfac
588588
0x10, 0x43, 0x0001, 0x000a, NULL, 0);
589589
if (err < 0)
590590
dev_dbg(&dev->dev, "error sending boot message: %d\n", err);
591+
592+
new_device_descriptor = kmalloc(sizeof(*new_device_descriptor), GFP_KERNEL);
593+
if (!new_device_descriptor)
594+
return -ENOMEM;
591595
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
592-
&new_device_descriptor, sizeof(new_device_descriptor));
596+
new_device_descriptor, sizeof(*new_device_descriptor));
593597
if (err < 0)
594598
dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
595-
if (new_device_descriptor.bNumConfigurations > dev->descriptor.bNumConfigurations)
599+
if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations)
596600
dev_dbg(&dev->dev, "error too large bNumConfigurations: %d\n",
597-
new_device_descriptor.bNumConfigurations);
601+
new_device_descriptor->bNumConfigurations);
598602
else
599-
memcpy(&dev->descriptor, &new_device_descriptor, sizeof(dev->descriptor));
603+
memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor));
600604
err = usb_reset_configuration(dev);
601605
if (err < 0)
602606
dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
@@ -930,7 +934,7 @@ static void mbox2_setup_48_24_magic(struct usb_device *dev)
930934
static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
931935
{
932936
struct usb_host_config *config = dev->actconfig;
933-
struct usb_device_descriptor new_device_descriptor;
937+
struct usb_device_descriptor *new_device_descriptor __free(kfree) = NULL;
934938
int err;
935939
u8 bootresponse[0x12];
936940
int fwsize;
@@ -965,15 +969,19 @@ static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
965969

966970
dev_dbg(&dev->dev, "device initialised!\n");
967971

972+
new_device_descriptor = kmalloc(sizeof(*new_device_descriptor), GFP_KERNEL);
973+
if (!new_device_descriptor)
974+
return -ENOMEM;
975+
968976
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
969-
&new_device_descriptor, sizeof(new_device_descriptor));
977+
new_device_descriptor, sizeof(*new_device_descriptor));
970978
if (err < 0)
971979
dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
972-
if (new_device_descriptor.bNumConfigurations > dev->descriptor.bNumConfigurations)
980+
if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations)
973981
dev_dbg(&dev->dev, "error too large bNumConfigurations: %d\n",
974-
new_device_descriptor.bNumConfigurations);
982+
new_device_descriptor->bNumConfigurations);
975983
else
976-
memcpy(&dev->descriptor, &new_device_descriptor, sizeof(dev->descriptor));
984+
memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor));
977985

978986
err = usb_reset_configuration(dev);
979987
if (err < 0)

0 commit comments

Comments
 (0)