Re: [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show
From: Bartosz Golaszewski
Date: Wed Dec 02 2026 - 03:32:05 EST
On Tue, Dec 01, 2026 at 10:14:51PM +0100, Linus Walleij wrote:
> 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!
>
FWIW it would probably been picked up by Sasha's automated system
anyway, at least this is my experience with anything containing Fixes:.
Bart