* [PATCH] gpio: mpsse: reject bulk-in endpoints smaller than 3 bytes
@ 2026-11-17 10:41 Hyunjung Ko
0 siblings, 0 replies; only message in thread
From: Hyunjung Ko @ 2026-11-17 10:41 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski
Cc: Mary Strodl, linux-gpio, linux-kernel, stable, 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
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")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
drivers/gpio/gpio-mpsse.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/gpio/gpio-mpsse.c b/drivers/gpio/gpio-mpsse.c
index 61c5ca96314b..3ad7048f009f 100644
--- a/drivers/gpio/gpio-mpsse.c
+++ b/drivers/gpio/gpio-mpsse.c
@@ -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)
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-17 10:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 10:41 [PATCH] gpio: mpsse: reject bulk-in endpoints smaller than 3 bytes Hyunjung Ko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®