Skip to contentSkip to conversation

gpio: ljca: validate event payload length

PATCH In review David Lee 3 participants 3 messages Jul 17 – Jul 20

Subsystems (2)
lore
Share & tools
lore

David Lee

author
#0 lore raw

PATCH 1/1 gpio: ljca: validate event payload length

ljca_gpio_event_cb() ignores the event length and trusts packet->num as the number of two-byte GPIO records. A device can provide a complete USB message whose nested count extends beyond the payload, making the callback read beyond the receive allocation.

Require the payload to contain both the count byte and every record it declares before iterating over the flexible array.

Fixes c5a4b6fd31e8 ("gpio: Add support for Intel LJCA USB GPIO driver")
Assisted-by Codex:gpt-5.5
---
 drivers/gpio/gpio-ljca.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpio/gpio-ljca.c +3 -0
index f32d1d237795..cb2b2623ccb1 100644
@@ -290,6 +290,9 @@ static void ljca_gpio_event_cb(void *context, u8 cmd, const void *evt_data,
 
 	if (cmd != LJCA_GPIO_INT_EVENT)
 		return;
+	if (len < sizeof(*packet) ||
+	    struct_size(packet, item, packet->num) > len)
+		return;
 
 	for (i = 0; i < packet->num; i++) {
 		generic_handle_domain_irq(ljca_gpio->gc.irq.domain,
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines

-----Original Message-----
From: David Lee <[email protected]>
Sent: Friday, July 17, 2026 10:58 PM
To: Zhang, Lixu <[email protected]>
Cc: David Lee <[email protected]>; Sakari Ailus <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Dominik 'Disconnect3d' Czarnota <[email protected]>; [email protected]; linux- [email protected]
Subject: [PATCH] gpio: ljca: validate event payload length

ljca_gpio_event_cb() ignores the event length and trusts packet->num as the number of two-byte GPIO records. A device can provide a complete USB message whose nested count extends beyond the payload, making the callback read beyond the receive allocation.

Quoted 6 lines

Require the payload to contain both the count byte and every record it declares before iterating over the flexible array.

Fixes c5a4b6fd31e8 ("gpio: Add support for Intel LJCA USB GPIO driver")
Assisted-by Codex:gpt-5.5
Quoted 1 line

---

#2 lore raw
In reply to David Lee
Quoted 30 lines · David Lee

ljca_gpio_event_cb() ignores the event length and trusts packet->num as the number of two-byte GPIO records. A device can provide a complete USB message whose nested count extends beyond the payload, making the callback read beyond the receive allocation.

Require the payload to contain both the count byte and every record it declares before iterating over the flexible array.

Fixes c5a4b6fd31e8 ("gpio: Add support for Intel LJCA USB GPIO driver")
Assisted-by Codex:gpt-5.5
---
 drivers/gpio/gpio-ljca.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpio/gpio-ljca.c +3 -1
index f32d1d237795..cb2b2623ccb1 100644
@@ -290,6 +290,9 @@ static void ljca_gpio_event_cb(void *context, u8 cmd, const void *evt_data,
 
 	if (cmd != LJCA_GPIO_INT_EVENT)
 		return;
+	if (len < sizeof(*packet) ||
+	    struct_size(packet, item, packet->num) > len)
+		return;
 
 	for (i = 0; i < packet->num; i++) {
 		generic_handle_domain_irq(ljca_gpio->gc.irq.domain,
--
Quoted 3 lines

2.43.0

There are two separate v1 of this, I'm confused.

Bart