Skip to contentSkip to conversation

gpio: mpsse: reject bulk-in endpoints smaller than 3 bytes

PATCH Applied Hyunjung Ko 2 participants 4 messages Nov 17 – Nov 19

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

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.

Fixes c46a74ff05c0 ("gpio: add support for FTDI's MPSSE as GPIO")
---
 drivers/gpio/gpio-mpsse.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpio/gpio-mpsse.c +4 -0
index 61c5ca96314b..3ad7048f009f 100644
@@ -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
#1 lore raw
Quoted 16 lines · Hyunjung Ko

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
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]>
author
#2 lore raw

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() 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
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,
--
Bartosz Golaszewski <[email protected]>

author
#3 lore raw

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() 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
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,
--
Bartosz Golaszewski <[email protected]>