* [PATCH 1/2] gpio: virtio: bound the line names block by its configured size
@ 2026-11-04 19:56 Lianjie Wang
2026-11-04 19:56 ` [PATCH 2/2] gpio: virtio: compute the line names size in a size_t Lianjie Wang
2026-11-04 20:03 ` [PATCH 1/2] gpio: virtio: bound the line names block by its configured size sashiko-bot
0 siblings, 2 replies; 4+ messages in thread
From: Lianjie Wang @ 2026-11-04 19:56 UTC (permalink / raw)
To: Enrico Weigelt, metux IT consult, Viresh Kumar, Linus Walleij,
Bartosz Golaszewski
Cc: Lianjie Wang, linux-gpio, virtualization, linux-kernel,
Takahiro Shinagawa, stable
virtio_gpio_get_names() walks the line names that the device returns in
a block of gpio_names_size bytes, which the driver ends with a NUL, and
checks each name only after stepping past it. If the block holds fewer
than ngpio names, the walk reaches the end of the block after the last
name, and the next iteration starts strlen() at the byte after the
allocation. With a block that holds one name for four lines, KASAN
reports:
BUG: KASAN: slab-out-of-bounds in strlen+0x57/0x70
Read of size 1 at addr ffff8880026687c0 by task swapper/0/1
Call Trace:
strlen+0x57/0x70
virtio_gpio_probe+0xcb4/0xfc0
virtio_dev_probe+0xa7a/0xc50
Allocated by task 1:
devm_kmalloc+0x6e/0x280
virtio_gpio_probe+0xc06/0xfc0
The buggy address is located 0 bytes to the right of
allocated 64-byte region [ffff888002668780, ffff8880026687c0)
Check that a name starts inside the block before reading it.
This patch is assisted by Claude Opus 5.5.
Fixes: 3a29355a22c0 ("gpio: Add virtio-gpio driver")
Cc: stable@vger.kernel.org
Signed-off-by: Lianjie Wang <lian@is.s.u-tokyo.ac.jp>
---
drivers/gpio/gpio-virtio.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpio-virtio.c b/drivers/gpio/gpio-virtio.c
index ed6e0e90fa8aa..32326d91f33d6 100644
--- a/drivers/gpio/gpio-virtio.c
+++ b/drivers/gpio/gpio-virtio.c
@@ -520,13 +520,13 @@ static const char **virtio_gpio_get_names(struct virtio_gpio *vgpio,
gpio_names[gpio_names_size - 1] = '\0';
for (i = 0, str = gpio_names; i < ngpio; i++) {
- names[i] = str;
- str += strlen(str) + 1; /* zero-length strings are allowed */
-
- if (str > gpio_names + gpio_names_size) {
+ if (str >= gpio_names + gpio_names_size) {
dev_err(dev, "gpio_names block is too short (%d)\n", i);
return NULL;
}
+
+ names[i] = str;
+ str += strlen(str) + 1; /* zero-length strings are allowed */
}
return names;
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] gpio: virtio: compute the line names size in a size_t
2026-11-04 19:56 [PATCH 1/2] gpio: virtio: bound the line names block by its configured size Lianjie Wang
@ 2026-11-04 19:56 ` Lianjie Wang
2026-11-04 20:01 ` sashiko-bot
2026-11-04 20:03 ` [PATCH 1/2] gpio: virtio: bound the line names block by its configured size sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Lianjie Wang @ 2026-11-04 19:56 UTC (permalink / raw)
To: Enrico Weigelt, metux IT consult, Viresh Kumar, Linus Walleij,
Bartosz Golaszewski
Cc: Lianjie Wang, linux-gpio, virtualization, linux-kernel,
Takahiro Shinagawa, stable
virtio_gpio_get_names() computes the size of the GET_LINE_NAMES response
as sizeof(*res) + gpio_names_size in an int, where gpio_names_size is a
u32 from the config space. A gpio_names_size of 0xffffffff makes the
size 0, devm_kzalloc() returns ZERO_SIZE_PTR, and reading the status
byte of the response through it oopses:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000002: 0000 [#1] SMP KASAN PTI
KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017]
RIP: 0010:_virtio_gpio_req+0x2b8/0x550
Call Trace:
virtio_gpio_probe+0xc2a/0xfc0
virtio_dev_probe+0xa7a/0xc50
Compute the size with struct_size() into a size_t.
This patch is assisted by Claude Opus 5.5.
Fixes: 3a29355a22c0 ("gpio: Add virtio-gpio driver")
Cc: stable@vger.kernel.org
Signed-off-by: Lianjie Wang <lian@is.s.u-tokyo.ac.jp>
---
drivers/gpio/gpio-virtio.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-virtio.c b/drivers/gpio/gpio-virtio.c
index 32326d91f33d6..fb7b40eff37dd 100644
--- a/drivers/gpio/gpio-virtio.c
+++ b/drivers/gpio/gpio-virtio.c
@@ -494,12 +494,13 @@ static const char **virtio_gpio_get_names(struct virtio_gpio *vgpio,
struct device *dev = &vgpio->vdev->dev;
u8 *gpio_names, *str;
const char **names;
- int i, ret, len;
+ size_t len;
+ int i, ret;
if (!gpio_names_size)
return NULL;
- len = sizeof(*res) + gpio_names_size;
+ len = struct_size(res, value, gpio_names_size);
res = devm_kzalloc(dev, len, GFP_KERNEL);
if (!res)
return NULL;
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] gpio: virtio: compute the line names size in a size_t
2026-11-04 19:56 ` [PATCH 2/2] gpio: virtio: compute the line names size in a size_t Lianjie Wang
@ 2026-11-04 20:01 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-04 20:01 UTC (permalink / raw)
To: Lianjie Wang; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
> virtio_gpio_get_names() computes the size of the GET_LINE_NAMES response
> as sizeof(*res) + gpio_names_size in an int, where gpio_names_size is a
> u32 from the config space. A gpio_names_size of 0xffffffff makes the
> size 0, devm_kzalloc() returns ZERO_SIZE_PTR, and reading the status
> byte of the response through it oopses:
>
> Oops: general protection fault, probably for non-canonical address 0xdffffc0000000002: 0000 [#1] SMP KASAN PTI
> KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017]
> RIP: 0010:_virtio_gpio_req+0x2b8/0x550
> Call Trace:
> virtio_gpio_probe+0xc2a/0xfc0
> virtio_dev_probe+0xa7a/0xc50
>
> Compute the size with struct_size() into a size_t.
>
> This patch is assisted by Claude Opus 5.5.
>
> Fixes: 3a29355a22c0 ("gpio: Add virtio-gpio driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Lianjie Wang <lian@is.s.u-tokyo.ac.jp>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261104195632.1702765-1-lian@is.s.u-tokyo.ac.jp?part=2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] gpio: virtio: bound the line names block by its configured size
2026-11-04 19:56 [PATCH 1/2] gpio: virtio: bound the line names block by its configured size Lianjie Wang
2026-11-04 19:56 ` [PATCH 2/2] gpio: virtio: compute the line names size in a size_t Lianjie Wang
@ 2026-11-04 20:03 ` sashiko-bot
1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-04 20:03 UTC (permalink / raw)
To: Lianjie Wang; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
> virtio_gpio_get_names() walks the line names that the device returns in
> a block of gpio_names_size bytes, which the driver ends with a NUL, and
> checks each name only after stepping past it. If the block holds fewer
> than ngpio names, the walk reaches the end of the block after the last
> name, and the next iteration starts strlen() at the byte after the
> allocation. With a block that holds one name for four lines, KASAN
> reports:
>
> BUG: KASAN: slab-out-of-bounds in strlen+0x57/0x70
> Read of size 1 at addr ffff8880026687c0 by task swapper/0/1
> Call Trace:
> strlen+0x57/0x70
> virtio_gpio_probe+0xcb4/0xfc0
> virtio_dev_probe+0xa7a/0xc50
> Allocated by task 1:
> devm_kmalloc+0x6e/0x280
> virtio_gpio_probe+0xc06/0xfc0
> The buggy address is located 0 bytes to the right of
> allocated 64-byte region [ffff888002668780, ffff8880026687c0)
>
> Check that a name starts inside the block before reading it.
>
> This patch is assisted by Claude Opus 5.5.
>
> Fixes: 3a29355a22c0 ("gpio: Add virtio-gpio driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Lianjie Wang <lian@is.s.u-tokyo.ac.jp>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261104195632.1702765-1-lian@is.s.u-tokyo.ac.jp?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-04 20:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04 19:56 [PATCH 1/2] gpio: virtio: bound the line names block by its configured size Lianjie Wang
2026-11-04 19:56 ` [PATCH 2/2] gpio: virtio: compute the line names size in a size_t Lianjie Wang
2026-11-04 20:01 ` sashiko-bot
2026-11-04 20:03 ` [PATCH 1/2] gpio: virtio: bound the line names block by its configured size sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox