mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] gpio: avoid undersized array bitmap in get fastpath
@ 2026-11-30  0:27 Baek Kyu, Kim
  0 siblings, 0 replies; only message in thread
From: Baek Kyu, Kim @ 2026-11-30  0:27 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel

The array get fast path passes the caller's value bitmap directly to
get_multiple(). The bitmap is sized for the requested array, but
providers such as gpio-sim process it for the entire chip. With a
128-line chip and a one-line array on a 64-bit kernel, gpio-sim's
bitmap_replace() reads and writes two words when the caller has
allocated only one. The second word is accessed even though its mask
is zero.

Use the existing per-chip path when the chip needs more bitmap words
than the caller provides. That path uses a chip-sized temporary bitmap
and copies only the requested values back.

Fixes: b17566a6b08b ("gpiolib: Implement fast processing path in get/set array")
Signed-off-by: Baek Kyu, Kim <pocj8ur4in@gmail.com>
---
Changes in v2:
- Regenerate against gpio/for-next after the public v1 diff arrived with
  a wrapped hunk header; omit the long header context. Code is unchanged.

Link to v1: https://lore-kernel.gnuweeb.org/linux-gpio/nh-fc54eb6a-a671-409c-bf5d-51ad5828438e@google.com/

The arm64 QEMU/KVM KASAN comparison of the original code and this
one-line change used gpio-virtuser with a 128-line gpio-sim chip and a
one-line array. The original kernel reported an 8-byte out-of-bounds
read and write; the changed kernel completed the read without a KASAN
report. A 64-line control case had no KASAN report on either kernel.
These are preserved v1 kernel images; the v2 base was not rebuilt.
No physical GPIO chip was tested.

 drivers/gpio/gpiolib.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index c09342fc5..5ff53c2a8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3560,6 +3560,7 @@
 	 */
 	if (array_info && array_info->desc == desc_array &&
 	    array_size <= array_info->size &&
+	    BITS_TO_LONGS(array_info->gdev->ngpio) <= BITS_TO_LONGS(array_size) &&
 	    (void *)array_info == desc_array + array_info->size) {
 		if (!can_sleep)
 			WARN_ON(array_info->gdev->can_sleep);
-- 
2.55.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-30  0:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  0:27 [PATCH v2] gpio: avoid undersized array bitmap in get fastpath Baek Kyu, Kim

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®