gpio: virtuser: fix one-byte overflow in lookup entry key show
Subsystems (2)
PATCH 1/1 gpio: virtuser: fix one-byte overflow in lookup entry key show
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.
---
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(-)
drivers/gpio/gpio-virtuser.c +1 -1
@@ -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
Signature · 1 line
2.47.3