* [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show
@ 2026-12-01 2:41 Lin Tzu Yang
0 siblings, 0 replies; only message in thread
From: Lin Tzu Yang @ 2026-12-01 2:41 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel, stable
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-01 2:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 2:41 [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show Lin Tzu Yang
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®