Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	Janusz Krzysztofik <jmkrzyszt@gmail.com>,
	linux-gpio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 05/10] gpiolib: Avoid undersized array bitmap in set fastpath
Date: Thu,  3 Dec 2026 20:55:03 +0000	[thread overview]
Message-ID: <20261203205606.3905705-6-lee@kernel.org> (raw)
In-Reply-To: <20261203205606.3905705-1-lee@kernel.org>

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@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 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


  parent reply	other threads:[~2026-12-03 20:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261203205606.3905705-1-lee@kernel.org>
2026-12-03 20:54 ` [PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe() Lee Jones
2026-12-03 20:55 ` [PATCH 02/10] gpiolib: acpi: Hold gpio_device reference in acpi_dev_gpio_irq_wake_get_by() Lee Jones
2026-12-03 20:55 ` [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind Lee Jones
2026-12-03 20:55 ` [PATCH 04/10] gpio: rockchip: Unregister gpiochip on pin-range lookup errors Lee Jones
2026-12-03 20:55 ` Lee Jones [this message]
2026-12-03 20:55 ` [PATCH 06/10] gpio: mlxbf2: Embed context save registers to prevent suspend NULL dereference Lee Jones
2026-12-03 20:55 ` [PATCH 07/10] gpio: regmap: Use resolved chip->ngpio for default ngpio_per_reg Lee Jones
2026-12-03 20:55 ` [PATCH 08/10] gpio: mpc8xxx: Drop stale remove callback clearing chained handler Lee Jones
2026-12-03 20:55 ` [PATCH 09/10] gpio: mpsse: Allocate DMA-safe buffer in mpsse_write() Lee Jones
2026-12-03 20:55 ` [PATCH 10/10] gpio: pcie-idio-24: Fix COS_ENABLE_RISING bit definition Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203205606.3905705-6-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=brgl@kernel.org \
    --cc=jmkrzyszt@gmail.com \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox