All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: ljca: validate event payload length
@ 2026-07-17 14:58 David Lee
  2026-07-20  5:42 ` Zhang, Lixu
  2026-07-20  8:04 ` Bartosz Golaszewski
  0 siblings, 2 replies; 5+ messages in thread
From: David Lee @ 2026-07-17 14:58 UTC (permalink / raw)
  To: Lixu Zhang
  Cc: David Lee, Sakari Ailus, Linus Walleij, Bartosz Golaszewski,
	Dominik 'Disconnect3d' Czarnota, linux-gpio, linux-kernel

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
Signed-off-by: David Lee <david.lee@trailofbits.com>
---
 drivers/gpio/gpio-ljca.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/gpio-ljca.c b/drivers/gpio/gpio-ljca.c
index f32d1d237795..cb2b2623ccb1 100644
--- a/drivers/gpio/gpio-ljca.c
+++ b/drivers/gpio/gpio-ljca.c
@@ -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,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH] gpio: ljca: validate event payload length
  2026-07-17 14:58 David Lee
@ 2026-07-20  5:42 ` Zhang, Lixu
  2026-07-20  8:04 ` Bartosz Golaszewski
  1 sibling, 0 replies; 5+ messages in thread
From: Zhang, Lixu @ 2026-07-20  5:42 UTC (permalink / raw)
  To: David Lee
  Cc: Sakari Ailus, Linus Walleij, Bartosz Golaszewski,
	Dominik 'Disconnect3d' Czarnota,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org

>-----Original Message-----
>From: David Lee <david.lee@trailofbits.com>
>Sent: Friday, July 17, 2026 10:58 PM
>To: Zhang, Lixu <lixu.zhang@intel.com>
>Cc: David Lee <david.lee@trailofbits.com>; Sakari Ailus
><sakari.ailus@linux.intel.com>; Linus Walleij <linusw@kernel.org>; Bartosz
>Golaszewski <brgl@kernel.org>; Dominik 'Disconnect3d' Czarnota
><dominik.czarnota@trailofbits.com>; linux-gpio@vger.kernel.org; linux-
>kernel@vger.kernel.org
>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.
>
>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
>Signed-off-by: David Lee <david.lee@trailofbits.com>

Reviewed-by: Zhang Lixu <lixu.zhang@intel.com>

>---


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] gpio: ljca: validate event payload length
@ 2026-07-20  5:49 David Lee
  2026-07-20  6:18 ` Sakari Ailus
  0 siblings, 1 reply; 5+ messages in thread
From: David Lee @ 2026-07-20  5:49 UTC (permalink / raw)
  To: Lixu Zhang
  Cc: David Lee, Sakari Ailus, Linus Walleij, Bartosz Golaszewski,
	Dominik 'Disconnect3d' Czarnota, linux-gpio, linux-kernel

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
Signed-off-by: David Lee <david.lee@trailofbits.com>
---
 drivers/gpio/gpio-ljca.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/gpio-ljca.c b/drivers/gpio/gpio-ljca.c
index f32d1d237795..cb2b2623ccb1 100644
--- a/drivers/gpio/gpio-ljca.c
+++ b/drivers/gpio/gpio-ljca.c
@@ -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,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: ljca: validate event payload length
  2026-07-20  5:49 [PATCH] gpio: ljca: validate event payload length David Lee
@ 2026-07-20  6:18 ` Sakari Ailus
  0 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2026-07-20  6:18 UTC (permalink / raw)
  To: David Lee
  Cc: Lixu Zhang, Linus Walleij, Bartosz Golaszewski,
	Dominik 'Disconnect3d' Czarnota, linux-gpio, linux-kernel

Hi David,

Thanks for the patch.

On Mon, Jul 20, 2026 at 05:49:05AM +0000, David Lee wrote:
> 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
> Signed-off-by: David Lee <david.lee@trailofbits.com>
> ---
>  drivers/gpio/gpio-ljca.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/gpio/gpio-ljca.c b/drivers/gpio/gpio-ljca.c
> index f32d1d237795..cb2b2623ccb1 100644
> --- a/drivers/gpio/gpio-ljca.c
> +++ b/drivers/gpio/gpio-ljca.c
> @@ -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;

I think this case would require a warning message, maybe using
dev_warn_once().

>  
>  	for (i = 0; i < packet->num; i++) {
>  		generic_handle_domain_irq(ljca_gpio->gc.irq.domain,

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: ljca: validate event payload length
  2026-07-17 14:58 David Lee
  2026-07-20  5:42 ` Zhang, Lixu
@ 2026-07-20  8:04 ` Bartosz Golaszewski
  1 sibling, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-07-20  8:04 UTC (permalink / raw)
  To: David Lee
  Cc: Sakari Ailus, Linus Walleij, Bartosz Golaszewski,
	Dominik 'Disconnect3d' Czarnota, linux-gpio, linux-kernel,
	Lixu Zhang

On Fri, 17 Jul 2026 16:58:26 +0200, David Lee <david.lee@trailofbits.com> said:
> 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
> Signed-off-by: David Lee <david.lee@trailofbits.com>
> ---
>  drivers/gpio/gpio-ljca.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpio/gpio-ljca.c b/drivers/gpio/gpio-ljca.c
> index f32d1d237795..cb2b2623ccb1 100644
> --- a/drivers/gpio/gpio-ljca.c
> +++ b/drivers/gpio/gpio-ljca.c
> @@ -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,
> --
> 2.43.0
>
>

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

Bart

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-20  8:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20  5:49 [PATCH] gpio: ljca: validate event payload length David Lee
2026-07-20  6:18 ` Sakari Ailus
  -- strict thread matches above, loose matches on Subject: below --
2026-07-17 14:58 David Lee
2026-07-20  5:42 ` Zhang, Lixu
2026-07-20  8:04 ` Bartosz Golaszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.