* [PATCH v2] ALSA: 6fire: fix OOB write from device-reported iso length
@ 2026-09-14 7:43 Xiang Mei
2026-09-14 9:46 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Xiang Mei @ 2026-09-14 7:43 UTC (permalink / raw)
To: perex, tiwai, torsten.schenk
Cc: co+855929c2df672879, linux-sound, linux-kernel, Xiang Mei
usb6fire_pcm_in_urb_handler() sizes each outgoing isochronous packet as
(actual_length - 4) / (in_n_analog << 2) * (out_n_analog << 2) + 4, where
actual_length is the unsigned length the device reported for the matching
IN packet. A packet completed with status 0 and actual_length < 4 wraps
the subtraction to 0x7fffffec; a zero-length isochronous packet is legal
on the bus, and the preceding loop rejects only non-zero status. The sum
reaches memset() on out_urb->buffer, a 4832-byte object from
kcalloc(PCM_MAX_PACKET_SIZE, PCM_N_PACKETS_PER_URB).
Even without the wrap the result is out of bounds: at 88.2/96 kHz the
4-in/6-out scaling turns a full 420-byte IN packet into 628, so eight
packets span 5024 bytes of that buffer. usb_submit_urb() rejects an
over-long descriptor only after the memset() and the
usb6fire_pcm_playback() copy of user PCM data have run.
Guard the subtraction as the sibling usb6fire_pcm_capture() already does,
and limit the frame count to what fits in rt->out_packet_size, the OUT
endpoint's wMaxPacketSize. This bounds total_length by the buffer size
while keeping each packet length aligned to a whole output frame.
BUG: KASAN: out-of-bounds in usb6fire_pcm_in_urb_handler (sound/usb/6fire/pcm.c:338)
Write of size 18446744073709551456 at addr ffff88802a3d0000 by task vhci_rx/5018
Call Trace:
dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
kasan_report (mm/kasan/report.c:595)
kasan_check_range (mm/kasan/generic.c:186 mm/kasan/generic.c:200)
__asan_memset (mm/kasan/shadow.c:84)
usb6fire_pcm_in_urb_handler (sound/usb/6fire/pcm.c:338)
__usb_hcd_giveback_urb (drivers/usb/core/hcd.c:1657)
usb_hcd_giveback_urb (drivers/usb/core/hcd.c:1741)
vhci_rx_loop (drivers/usb/usbip/vhci_rx.c:107 drivers/usb/usbip/vhci_rx.c:242)
kthread (kernel/kthread.c:436)
ret_from_fork (arch/x86/kernel/process.c:158)
ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
Allocated by task 10:
__kmalloc_cache_noprof (mm/slub.c:5563)
usb6fire_pcm_init (sound/usb/6fire/pcm.c:560 sound/usb/6fire/pcm.c:595)
usb6fire_chip_probe (sound/usb/6fire/chip.c:133)
usb_probe_interface (drivers/usb/core/driver.c:399)
The buggy address belongs to the object at ffff88802a3d0000
which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 0 bytes inside of
4832-byte region [ffff88802a3d0000, ffff88802a3d12e0)
Kernel panic - not syncing: Fatal exception in interrupt
Fixes: c6d43ba816d1 ("ALSA: usb/6fire - Driver for TerraTec DMX 6Fire USB")
Reported-by: co+855929c2df672879@bugs.sh
Closes: https://lore.kernel.org/all/gisnub8aWGLbyZLcDCSc7zWsHonMWGcyRgt5%40bugs.sh/
Assisted-by: LLM
Signed-off-by: Xiang Mei <xmei5@asu.edu>
---
sound/usb/6fire/pcm.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/sound/usb/6fire/pcm.c b/sound/usb/6fire/pcm.c
index 21789db6657d..0285d79ace0f 100644
--- a/sound/usb/6fire/pcm.c
+++ b/sound/usb/6fire/pcm.c
@@ -335,11 +335,19 @@ static void usb6fire_pcm_in_urb_handler(struct urb *usb_urb)
/* setup out urb structure */
for (i = 0; i < PCM_N_PACKETS_PER_URB; i++) {
+ unsigned int frames = 0;
+
isoc_out = &out_urb->instance->iso_frame_desc[i];
isoc_in = &in_urb->instance->iso_frame_desc[i];
+ if (isoc_in->actual_length > 4)
+ frames = (isoc_in->actual_length - 4)
+ / (rt->in_n_analog << 2);
+ frames = min_t(unsigned int, frames,
+ (rt->out_packet_size - 4)
+ / (rt->out_n_analog << 2));
+
isoc_out->offset = total_length;
- isoc_out->length = (isoc_in->actual_length - 4) / (rt->in_n_analog << 2)
- * (rt->out_n_analog << 2) + 4;
+ isoc_out->length = frames * (rt->out_n_analog << 2) + 4;
isoc_out->status = 0;
total_length += isoc_out->length;
}
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] ALSA: 6fire: fix OOB write from device-reported iso length
2026-09-14 7:43 [PATCH v2] ALSA: 6fire: fix OOB write from device-reported iso length Xiang Mei
@ 2026-09-14 9:46 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-09-14 9:46 UTC (permalink / raw)
To: Xiang Mei
Cc: perex, tiwai, torsten.schenk, co+855929c2df672879, linux-sound,
linux-kernel
On Mon, 14 Sep 2026 09:43:24 +0200,
Xiang Mei wrote:
>
> usb6fire_pcm_in_urb_handler() sizes each outgoing isochronous packet as
> (actual_length - 4) / (in_n_analog << 2) * (out_n_analog << 2) + 4, where
> actual_length is the unsigned length the device reported for the matching
> IN packet. A packet completed with status 0 and actual_length < 4 wraps
> the subtraction to 0x7fffffec; a zero-length isochronous packet is legal
> on the bus, and the preceding loop rejects only non-zero status. The sum
> reaches memset() on out_urb->buffer, a 4832-byte object from
> kcalloc(PCM_MAX_PACKET_SIZE, PCM_N_PACKETS_PER_URB).
>
> Even without the wrap the result is out of bounds: at 88.2/96 kHz the
> 4-in/6-out scaling turns a full 420-byte IN packet into 628, so eight
> packets span 5024 bytes of that buffer. usb_submit_urb() rejects an
> over-long descriptor only after the memset() and the
> usb6fire_pcm_playback() copy of user PCM data have run.
>
> Guard the subtraction as the sibling usb6fire_pcm_capture() already does,
> and limit the frame count to what fits in rt->out_packet_size, the OUT
> endpoint's wMaxPacketSize. This bounds total_length by the buffer size
> while keeping each packet length aligned to a whole output frame.
>
> BUG: KASAN: out-of-bounds in usb6fire_pcm_in_urb_handler (sound/usb/6fire/pcm.c:338)
> Write of size 18446744073709551456 at addr ffff88802a3d0000 by task vhci_rx/5018
> Call Trace:
> dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
> print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
> kasan_report (mm/kasan/report.c:595)
> kasan_check_range (mm/kasan/generic.c:186 mm/kasan/generic.c:200)
> __asan_memset (mm/kasan/shadow.c:84)
> usb6fire_pcm_in_urb_handler (sound/usb/6fire/pcm.c:338)
> __usb_hcd_giveback_urb (drivers/usb/core/hcd.c:1657)
> usb_hcd_giveback_urb (drivers/usb/core/hcd.c:1741)
> vhci_rx_loop (drivers/usb/usbip/vhci_rx.c:107 drivers/usb/usbip/vhci_rx.c:242)
> kthread (kernel/kthread.c:436)
> ret_from_fork (arch/x86/kernel/process.c:158)
> ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
>
> Allocated by task 10:
> __kmalloc_cache_noprof (mm/slub.c:5563)
> usb6fire_pcm_init (sound/usb/6fire/pcm.c:560 sound/usb/6fire/pcm.c:595)
> usb6fire_chip_probe (sound/usb/6fire/chip.c:133)
> usb_probe_interface (drivers/usb/core/driver.c:399)
>
> The buggy address belongs to the object at ffff88802a3d0000
> which belongs to the cache kmalloc-8k of size 8192
> The buggy address is located 0 bytes inside of
> 4832-byte region [ffff88802a3d0000, ffff88802a3d12e0)
> Kernel panic - not syncing: Fatal exception in interrupt
>
> Fixes: c6d43ba816d1 ("ALSA: usb/6fire - Driver for TerraTec DMX 6Fire USB")
> Reported-by: co+855929c2df672879@bugs.sh
> Closes: https://lore.kernel.org/all/gisnub8aWGLbyZLcDCSc7zWsHonMWGcyRgt5%40bugs.sh/
> Assisted-by: LLM
> Signed-off-by: Xiang Mei <xmei5@asu.edu>
Applied now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-14 9:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-14 7:43 [PATCH v2] ALSA: 6fire: fix OOB write from device-reported iso length Xiang Mei
2026-09-14 9:46 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®