Skip to contentSkip to conversation

ALSA: usb-audio: Fix DMA buffer out-of-bounds write when fill_max is set

PATCH In review Sonali Pradhan 2 participants 2 messages Jul 28 – Jul 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: usb-audio: Fix DMA buffer out-of-bounds write when fill_max is set

When a USB audio endpoint requests full packet transfers via the fill_max descriptor flag, data_ep_set_params() promotes ep->curpacksize to ep->maxpacksize. However, maxsize is left at the original sample-rate derived value.

Since u->buffer_size is allocated as maxsize * packets, the resulting DMA buffer is far too small for the requested transfer length. When the USB host controller streams up to curpacksize bytes per packet, it writes past the end of the buffer via DMA, corrupting kernel heap memory.

Update maxsize to curpacksize when fill_max is set so that the allocated DMA buffer size matches the actual transfer request size.

Fixes 8fdff6a319e7 ("ALSA: snd-usb: implement new endpoint streaming model")
Assisted-by Jetski:Gemini-3.6-Flash
---
 sound/usb/endpoint.c | 1 +
 1 file changed, 1 insertion(+)
sound/usb/endpoint.c +1 -0
index 24cd7692bd01..d825c09a766a 100644
@@ -1172,6 +1172,7 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep)
 		ep->curpacksize = ep->maxpacksize;
 	else
 		ep->curpacksize = maxsize;
+	maxsize = ep->curpacksize;
 
 	if (snd_usb_get_speed(chip->dev) != USB_SPEED_FULL) {
 		packs_per_ms = 8 >> ep->datainterval;
Signature · 1 line
2.55.0.487.gaf234c4eb3-goog
#1 lore raw
Quoted 27 lines · Sonali Pradhan

When a USB audio endpoint requests full packet transfers via the fill_max descriptor flag, data_ep_set_params() promotes ep->curpacksize to ep->maxpacksize. However, maxsize is left at the original sample-rate derived value.

Since u->buffer_size is allocated as maxsize * packets, the resulting DMA buffer is far too small for the requested transfer length. When the USB host controller streams up to curpacksize bytes per packet, it writes past the end of the buffer via DMA, corrupting kernel heap memory.

Update maxsize to curpacksize when fill_max is set so that the allocated DMA buffer size matches the actual transfer request size.

Fixes 8fdff6a319e7 ("ALSA: snd-usb: implement new endpoint streaming model")
Assisted-by Jetski:Gemini-3.6-Flash
---
 sound/usb/endpoint.c | 1 +
 1 file changed, 1 insertion(+)
sound/usb/endpoint.c +0 -0
index 24cd7692bd01..d825c09a766a 100644

sound/usb/endpoint.c static int data_ep_set_params(struct snd_usb_endpoint *ep) · line 1176

Quoted 5 lines
sound/usb/endpoint.c +1 -0
@@ -1172,6 +1172,7 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep)
 		ep->curpacksize = ep->maxpacksize;
 	else
 		ep->curpacksize = maxsize;
+	maxsize = ep->curpacksize;
 

Unconditionally reassigning here makes harder to understand the intention. So I modified slightly to make the reassignment conditional, only when ep->fill_max is set.

	if (ep->fill_max) {
		ep->curpacksize = ep->maxpacksize;
		maxsize = ep->curpacksize;
	} else {
		ep->curpacksize = maxsize;
	}

Applied the fix in the form above now. Thanks.

Takashi