Skip to content

Commit 6f5c69f

Browse files
samasth-norwaytiwai
authored andcommitted
ALSA: scarlett2: Fix buffer overflow in config retrieval
The scarlett2_usb_get_config() function has a logic error in the endianness conversion code that can cause buffer overflows when count > 1. The code checks `if (size == 2)` where `size` is the total buffer size in bytes, then loops `count` times treating each element as u16 (2 bytes). This causes the loop to access `count * 2` bytes when the buffer only has `size` bytes allocated. Fix by checking the element size (config_item->size) instead of the total buffer size. This ensures the endianness conversion matches the actual element type. Fixes: ac34df7 ("ALSA: usb-audio: scarlett2: Update get_config to do endian conversion") Cc: stable@vger.kernel.org Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com> Link: https://patch.msgid.link/20260117012706.1715574-1-samasth.norway.ananda@oracle.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 6b97119 commit 6f5c69f

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

sound/usb/mixer_scarlett2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,13 +2533,13 @@ static int scarlett2_usb_get_config(
25332533
err = scarlett2_usb_get(mixer, config_item->offset, buf, size);
25342534
if (err < 0)
25352535
return err;
2536-
if (size == 2) {
2536+
if (config_item->size == 16) {
25372537
u16 *buf_16 = buf;
25382538

25392539
for (i = 0; i < count; i++, buf_16++)
25402540
*buf_16 = le16_to_cpu(*(__le16 *)buf_16);
2541-
} else if (size == 4) {
2542-
u32 *buf_32 = buf;
2541+
} else if (config_item->size == 32) {
2542+
u32 *buf_32 = (u32 *)buf;
25432543

25442544
for (i = 0; i < count; i++, buf_32++)
25452545
*buf_32 = le32_to_cpu(*(__le32 *)buf_32);

0 commit comments

Comments
 (0)