All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show
@ 2026-12-01  2:41 Lin Tzu Yang
  2026-12-01 21:14 ` Linus Walleij
  2026-12-02  8:44 ` Bartosz Golaszewski
  0 siblings, 2 replies; 4+ messages 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 related	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show
  2026-12-01  2:41 [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show Lin Tzu Yang
@ 2026-12-01 21:14 ` Linus Walleij
  2026-12-02  8:31   ` Bartosz Golaszewski
  2026-12-02  8:44 ` Bartosz Golaszewski
  1 sibling, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2026-12-01 21:14 UTC (permalink / raw)
  To: Lin Tzu Yang; +Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, stable

Hi Lin Tzu,

On Tue, Dec 1, 2026 at 3:42 AM Lin Tzu Yang <rongh7426@gmail.com> 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@vger.kernel.org

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

> Signed-off-by: Lin Tzu Yang <rongh7426@gmail.com>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show
  2026-12-01 21:14 ` Linus Walleij
@ 2026-12-02  8:31   ` Bartosz Golaszewski
  0 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-12-02  8:31 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Lin Tzu Yang, linux-gpio, linux-kernel, stable

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@gmail.com> 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@vger.kernel.org
> 
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show
  2026-12-01  2:41 [PATCH] gpio: virtuser: fix one-byte overflow in lookup entry key show Lin Tzu Yang
  2026-12-01 21:14 ` Linus Walleij
@ 2026-12-02  8:44 ` Bartosz Golaszewski
  1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-12-02  8:44 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Lin Tzu Yang
  Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, stable


On Tue, 01 Dec 2026 10:41:51 +0800, Lin Tzu Yang 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.
> 
> [...]

Applied, thanks!

[1/1] gpio: virtuser: fix one-byte overflow in lookup entry key show
      https://git.kernel.org/brgl/c/b300b1532925ead6b1faed7f952c738dec2b9f68

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-02  8:44 UTC | newest]

Thread overview: 4+ messages (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
2026-12-01 21:14 ` Linus Walleij
2026-12-02  8:31   ` Bartosz Golaszewski
2026-12-02  8:44 ` Bartosz Golaszewski

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.