All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lin Tzu Yang <rongh7426@gmail.com>
To: Linus Walleij <linusw@kernel.org>, Bartosz Golaszewski <brgl@kernel.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show
Date: Tue,  1 Dec 2026 10:41:51 +0800	[thread overview]
Message-ID: <20261201024151.872725-1-rongh7426@gmail.com> (raw)

The key attribute of a lookup entry is a configfs simple attribute, so
its store callback accepts up to 4095 bytes and keeps them in
entry->key. The show callback then prints it with

	sprintf(page, "%s\n", entry->key ?: "");

With a 4095-byte key this writes 4095 characters, the newline and the
terminating NUL, 4097 bytes in total, into the 4096-byte page buffer.
KASAN reports it as a slab-out-of-bounds write in vsnprintf() when the
attribute is read back.

Use sysfs_emit(), which is bounded by PAGE_SIZE. A key of that length
is truncated in the output instead of overflowing the buffer.

Tested in an arm64 QEMU/KVM guest with KASAN: before this change,
writing a 4095-byte key and reading it back triggers the KASAN report;
with it, the read returns 4095 bytes and there is no report. Normal
keys and the other entry attributes read back unchanged.

Fixes: 91581c4b3f29 ("gpio: virtuser: new virtual testing driver for the GPIO API")
Cc: stable@vger.kernel.org
Signed-off-by: Lin Tzu Yang <rongh7426@gmail.com>
---
The bug was found with a small configfs fuzzing script and the fix
was written with AI assistance (Claude); I reviewed and tested it.

 drivers/gpio/gpio-virtuser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c
index 5bf5d891c4..6e244982a6 100644
--- a/drivers/gpio/gpio-virtuser.c
+++ b/drivers/gpio/gpio-virtuser.c
@@ -1082,7 +1082,7 @@ gpio_virtuser_lookup_entry_config_key_show(struct config_item *item, char *page)
 
 	guard(mutex)(&dev->lock);
 
-	return sprintf(page, "%s\n", entry->key ?: "");
+	return sysfs_emit(page, "%s\n", entry->key ?: "");
 }
 
 static ssize_t
-- 
2.47.3


             reply	other threads:[~2026-12-01  2:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  2:41 Lin Tzu Yang [this message]
2026-12-01 21:14 ` [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show Linus Walleij
2026-12-02  8:31   ` Bartosz Golaszewski
2026-12-02  8:44 ` Bartosz Golaszewski

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=20261201024151.872725-1-rongh7426@gmail.com \
    --to=rongh7426@gmail.com \
    --cc=brgl@kernel.org \
    --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 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.