Re: [PATCH] usb: gadget: f_uac1_legacy: fix heap overflow in f_audio_out_ep_complete()

From: Greg KH

Date: Fri Nov 20 2026 - 06:14:56 EST


On Sun, Aug 23, 2026 at 03:45:48AM +0800, Haofeng Li wrote:
> f_audio_out_ep_complete() queues the accumulation buffer for playback
> and allocates a fresh, audio_buf_size-byte one whenever an incoming
> request does not fit into the space left in the current buffer. It then
> unconditionally copies req->actual bytes into copy_buf->buf.
>
> audio_buf_size and req_buf_size are independent configfs attributes of
> the function and nothing makes the former cover the latter: a request
> buffer is req_buf_size bytes, req->actual is the size of the packet the
> USB host chose to send, and as soon as one packet exceeds audio_buf_size
> the memcpy() writes past the end of a kzalloc(audio_buf_size) object.
>
> Attack chain (write access to the gadget's configfs attributes before
> the function is bound, plus control of the USB host side; no race
> needed):
>
> echo 1 > .../functions/uac1_legacy.0/audio_buf_size
> echo 200 > .../functions/uac1_legacy.0/req_buf_size
> bind the gadget, host sets the AS interface to altsetting 1
> -> f_audio_set_alt(): 1-byte accumulation buffer allocated,
> 200-byte request buffers queued with req->length = 200
> host sends a single 200-byte OUT audio packet
> -> f_audio_complete() -> f_audio_out_ep_complete()
> -> audio_buf_size - actual = 1 - 0 < 200: the empty buffer is
> queued for playback and a new 1-byte buffer is allocated
> -> memcpy(copy_buf->buf + 0, req->buf, 200)
> -> 199-byte out-of-bounds heap write
>
> The write is silent: FORTIFY cannot derive the size of the destination
> through the runtime offset buf + actual, and because the neighbouring
> slab objects stay addressable, generic KASAN reports nothing either.
> Reproduced on 7.2.0+ with KASAN and slub_debug=Z, where the injected
> 200-byte pattern lands entirely outside the 1-byte kmalloc-8 object and
> reaches the SLUB redzone; the resulting freelist corruption was observed
> to hang the machine (GPF in get_from_partial_node() during later device
> enumeration).

What does this paragraph mean? Please rewrite this whole changelog in
your own words.

thanks,

greg k-h