gpio: mpsse: reject bulk-in endpoints smaller than 3 bytes
Subsystems (2)
PATCH 1/1 gpio: mpsse: reject bulk-in endpoints smaller than 3 bytes
mpsse_read() reads min(len + 2, wMaxPacketSize) bytes and then copies len_actual - 2 bytes to the caller. A device that declares a bulk-in endpoint with wMaxPacketSize 1 completes the read with len_actual 1, so the copy length becomes -1 and memcpy() runs far past the one byte buffer on the caller's stack and past bulk_in_buf:
memcpy: detected buffer overflow: 18446744073709551615 byte write of buffer size 1
WARNING: lib/string_helpers.c:1036 at __fortify_report+0x6e/0xc0 Call Trace: __fortify_panic+0xd/0x10 gpio_mpsse_get_multiple+0x767/0x780 gpio_mpsse_gpio_get+0xa2/0xf0 gpiod_get_raw_value_commit+0xf8/0x1f0 gpiod_get_value_cansleep+0x1e/0xa0 value_show+0x42/0x90
Reproduced with dummy_hcd and raw-gadget. A read needs room for the two status bytes plus at least one data byte, so refuse to bind otherwise.
--- drivers/gpio/gpio-mpsse.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpio/gpio-mpsse.c +4 -0
@@ -676,6 +676,10 @@ static int gpio_mpsse_probe(struct usb_interface *interface,if (err)return err; +/* Every read carries two status bytes ahead of the data */ +if (usb_endpoint_maxp (priv->bulk_in) <3 ) +return -EINVAL ; + priv->bulk_in_buf =devm_kmalloc (dev,usb_endpoint_maxp (priv->bulk_in),GFP_KERNEL );if (!priv->bulk_in_buf)
Signature · 1 line
2.43.0
Bartosz Golaszewski
AppliedQuoted 16 lines · Hyunjung Ko
mpsse_read()readsmin(len + 2, wMaxPacketSize)bytes and then copieslen_actual- 2 bytes to the caller. A device that declares a bulk-in endpoint with wMaxPacketSize 1 completes the read withlen_actual1, so the copy length becomes -1 andmemcpy()runs far past the one byte buffer on the caller's stack and pastbulk_in_buf:memcpy: detected buffer overflow: 18446744073709551615 byte write of buffer size 1
WARNING: lib/string_helpers.c:1036 at __fortify_report+0x6e/0xc0 Call Trace: __fortify_panic+0xd/0x10 gpio_mpsse_get_multiple+0x767/0x780 gpio_mpsse_gpio_get+0xa2/0xf0 gpiod_get_raw_value_commit+0xf8/0x1f0 gpiod_get_value_cansleep+0x1e/0xa0 value_show+0x42/0x90
Quoted 1 line
[...]
Applied, thanks!
[1/1] gpio: mpsse: reject bulk-in endpoints smaller than 3 bytes
https://git.kernel.org/brgl/c/f94f85f82e042c89a1e64ed3ff1d591a2bccfa7b
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
You're right, sorry for the noise..!
buffer[2] is only read when there's no interrupt-in endpoint, so rejecting every short transfer would break the devices that get the status byte from the notification instead. Dropping the patch, I don't have the hardware to test a narrower fix..
Hyunjung
2026년 11월 19일 (목) 오후 7:33, Bartosz Golaszewski
<[email protected]>님이 작성:
Quoted 29 lines · Hyunjung Ko
Quoted 16 lines
mpsse_read()readsmin(len + 2, wMaxPacketSize)bytes and then copieslen_actual- 2 bytes to the caller. A device that declares a bulk-in endpoint with wMaxPacketSize 1 completes the read withlen_actual1, so the copy length becomes -1 andmemcpy()runs far past the one byte buffer on the caller's stack and pastbulk_in_buf:memcpy: detected buffer overflow: 18446744073709551615 byte write of buffer size 1
WARNING: lib/string_helpers.c:1036 at __fortify_report+0x6e/0xc0 Call Trace: __fortify_panic+0xd/0x10 gpio_mpsse_get_multiple+0x767/0x780 gpio_mpsse_gpio_get+0xa2/0xf0 gpiod_get_raw_value_commit+0xf8/0x1f0 gpiod_get_value_cansleep+0x1e/0xa0 value_show+0x42/0x90Quoted 1 line
[...]
Applied, thanks!
[1/1] gpio: mpsse: reject bulk-in endpoints smaller than 3 bytes
https://git.kernel.org/brgl/c/f94f85f82e042c89a1e64ed3ff1d591a2bccfa7bBest regards,
--
Bartosz Golaszewski <[email protected]>
Sorry, wrong thread - that reply was meant for an unrelated usbtmc patch. Nothing to do here, the mpsse one is fine as applied.
Hyunjung
2026년 11월 19일 (목) 오후 10:23, khj <[email protected]>님이 작성:
Quoted 41 lines
You're right, sorry for the noise..!
buffer[2] is only read when there's no interrupt-in endpoint, so rejecting every short transfer would break the devices that get the status byte from the notification instead. Dropping the patch, I don't have the hardware to test a narrower fix..
Hyunjung
2026년 11월 19일 (목) 오후 7:33, Bartosz Golaszewski
<[email protected]>님이 작성:Quoted 29 lines · Hyunjung Ko
Quoted 16 lines
mpsse_read()readsmin(len + 2, wMaxPacketSize)bytes and then copieslen_actual- 2 bytes to the caller. A device that declares a bulk-in endpoint with wMaxPacketSize 1 completes the read withlen_actual1, so the copy length becomes -1 andmemcpy()runs far past the one byte buffer on the caller's stack and pastbulk_in_buf:memcpy: detected buffer overflow: 18446744073709551615 byte write of buffer size 1
WARNING: lib/string_helpers.c:1036 at __fortify_report+0x6e/0xc0 Call Trace: __fortify_panic+0xd/0x10 gpio_mpsse_get_multiple+0x767/0x780 gpio_mpsse_gpio_get+0xa2/0xf0 gpiod_get_raw_value_commit+0xf8/0x1f0 gpiod_get_value_cansleep+0x1e/0xa0 value_show+0x42/0x90Quoted 1 line
[...]
Applied, thanks!
[1/1] gpio: mpsse: reject bulk-in endpoints smaller than 3 bytes
https://git.kernel.org/brgl/c/f94f85f82e042c89a1e64ed3ff1d591a2bccfa7bBest regards,
--
Bartosz Golaszewski <[email protected]>