Re: [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show

From: Linus Walleij

Date: Tue Dec 01 2026 - 16:15:07 EST


Hi Lin Tzu,

On Tue, Dec 1, 2026 at 3:42 AM Lin Tzu Yang <rongh7426@xxxxxxxxx> wrote:

> 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@xxxxxxxxxxxxxxx

Oh come on, a small bug in testing code does not need to
go into stable!

> Signed-off-by: Lin Tzu Yang <rongh7426@xxxxxxxxx>

Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>

Yours,
Linus Walleij