mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Baek Kyu, Kim" <pocj8ur4in@gmail.com>
To: Linus Walleij <linusw@kernel.org>, Bartosz Golaszewski <brgl@kernel.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] gpio: avoid undersized array bitmap in get fastpath
Date: Mon, 30 Nov 2026 09:27:47 +0900	[thread overview]
Message-ID: <179599846717.10686.17869004160600605139.c258-v2@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-30  0:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=179599846717.10686.17869004160600605139.c258-v2@gmail.com \
    --to=pocj8ur4in@gmail.com \
    --cc=brgl@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®