]> git.ipfire.org Git - thirdparty/linux.git/commit
usb: gadget: printer: fix infinite loop in printer_read()
authorMelbin K Mathew <mlbnkm1@gmail.com>
Thu, 9 Jul 2026 20:56:22 +0000 (21:56 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 13 Jul 2026 05:10:11 +0000 (07:10 +0200)
commitc2e819be6a5c7f34344926b4bd7e3dfca58cf48a
tree311cba3f3daec8905ec10759d8821447688ce8bf
parent5650c18d93a1db7e27cb5a40b394747eb4686d5b
usb: gadget: printer: fix infinite loop in printer_read()

printer_read() uses the same variable for the requested copy size and
the number of bytes actually copied to user space. copy_to_user()
returns the number of bytes not copied, so when it fails to copy
anything, the computed copied length becomes zero.

In that case len, buf, current_rx_bytes and current_rx_buf are left
unchanged. If RX data is available and the user buffer remains
unwritable, the read loop can repeat indefinitely.

Track the copied length separately and return -EFAULT, or the number of
bytes already copied, if an iteration makes no progress.

Fixes: b185f01a9ab7 ("usb: gadget: printer: factor out f_printer")
Cc: stable <stable@kernel.org>
Reviewed-by: Peter Chen <peter.chen@kernel.org>
Signed-off-by: Melbin K Mathew <mlbnkm1@gmail.com>
Link: https://patch.msgid.link/20260709205622.55700-1-mlbnkm1@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_printer.c