[PATCH 05/10] gpiolib: Avoid undersized array bitmap in set fastpath
From: Lee Jones
Date: Thu Dec 03 2026 - 15:57:07 EST
gpiod_set_array_value_complex() passes the caller's value_bitmap
directly to gpiochip_set_multiple() whenever array_size <=
array_info->size. When the GPIO chip spans more unsigned long words
than value_bitmap (BITS_TO_LONGS(gdev->ngpio) >
BITS_TO_LONGS(array_size)), drivers operating across gc->ngpio bits
read past the end of value_bitmap.
Require BITS_TO_LONGS(array_info->gdev->ngpio) <=
BITS_TO_LONGS(array_size) before taking the fastpath, mirroring the
corresponding check in the get fastpath.
Fixes: b17566a6b08b ("gpiolib: Implement fast processing path in get/set array")
Closes: https://sashiko.dev/#/bug/linux-9966f9bb-49bb-49d3-b955-762062db0725
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/gpio/gpiolib.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8843b2175caf..7785be3e2de9 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3922,7 +3922,8 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
*/
if (array_info && array_info->desc == desc_array &&
array_size <= array_info->size &&
- (void *)array_info == desc_array + array_info->size) {
+ (void *)array_info == desc_array + array_info->size &&
+ BITS_TO_LONGS(array_info->gdev->ngpio) <= BITS_TO_LONGS(array_size)) {
if (!can_sleep)
WARN_ON(array_info->gdev->can_sleep);
--
2.56.1.911.g883d8bcb20-goog