* [PATCH] nvmet: fix one-byte overflow in configfs string show callbacks
@ 2026-11-30 11:47 Lin Tzu Yang
2026-12-01 8:01 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Lin Tzu Yang @ 2026-11-30 11:47 UTC (permalink / raw)
To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni
Cc: Keith Busch, Hannes Reinecke, linux-nvme, linux-kernel
The show callbacks for the namespace attribute device_path and the
host attributes dhchap_key and dhchap_ctrl_key print the stored string
with sprintf(page, "%s\n", ...). configfs accepts up to 4095 bytes in a
store, and the store side keeps them all, so with a 4095-byte value the
show writes the string, the newline and the terminating NUL, one byte
past the PAGE_SIZE buffer.
KASAN in a QEMU arm64 guest, after writing 4095 bytes to
namespaces/1/device_path and reading it back:
BUG: KASAN: slab-out-of-bounds in vsnprintf+0xdd8/0xdfc
Write of size 1 at addr ffff0000127cf000 by task cat/4329
vsnprintf+0xdd8/0xdfc
sprintf+0xb0/0xec
nvmet_ns_device_path_show+0x44/0x68
configfs_read_iter+0x284/0x46c
The buggy address is located 0 bytes to the right of
allocated 4096-byte region
dhchap_key and dhchap_ctrl_key with "DHHC-1:00:" followed by 4085
bytes give the same report.
Use scnprintf() with PAGE_SIZE, as the passthru device_path show
already does. A value that does not fit loses its trailing newline
instead of overflowing the buffer.
Fixes: a07b4970f464 ("nvmet: add a generic NVMe target")
Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication")
Cc: stable@vger.kernel.org
Signed-off-by: Lin Tzu Yang <rongh7426@gmail.com>
---
Tested on configfs-next 2e0fad9d2eae in a QEMU/KVM arm64 guest with
KASAN and kasan_multi_shot. Writing 4095 bytes to each of the three
attributes and reading it back gave one KASAN report per attribute
before the patch, and none after; reads return 4095 bytes. Normal
values such as /dev/nullb0 and DHHC-1:00:abcd: still read back with
their newline, and enabling the namespace still works. Build-tested
with W=1 on nvme-7.4.
Found by writing boundary values to every nvmet configfs attribute.
This patch was written with the help of an AI coding assistant
(Claude). I ran the tests above and reviewed the change.
drivers/nvme/target/configfs.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 27c50fa533..f88a295bc1 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -531,7 +531,8 @@ CONFIGFS_ATTR(nvmet_, addr_tsas);
*/
static ssize_t nvmet_ns_device_path_show(struct config_item *item, char *page)
{
- return sprintf(page, "%s\n", to_nvmet_ns(item)->device_path);
+ return scnprintf(page, PAGE_SIZE, "%s\n",
+ to_nvmet_ns(item)->device_path);
}
static ssize_t nvmet_ns_device_path_store(struct config_item *item,
@@ -2242,7 +2243,7 @@ static ssize_t nvmet_host_dhchap_key_show(struct config_item *item,
if (!dhchap_secret)
ret = sprintf(page, "\n");
else
- ret = sprintf(page, "%s\n", dhchap_secret);
+ ret = scnprintf(page, PAGE_SIZE, "%s\n", dhchap_secret);
up_read(&nvmet_config_sem);
return ret;
}
@@ -2275,7 +2276,7 @@ static ssize_t nvmet_host_dhchap_ctrl_key_show(struct config_item *item,
if (!dhchap_secret)
ret = sprintf(page, "\n");
else
- ret = sprintf(page, "%s\n", dhchap_secret);
+ ret = scnprintf(page, PAGE_SIZE, "%s\n", dhchap_secret);
up_read(&nvmet_config_sem);
return ret;
}
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nvmet: fix one-byte overflow in configfs string show callbacks
2026-11-30 11:47 [PATCH] nvmet: fix one-byte overflow in configfs string show callbacks Lin Tzu Yang
@ 2026-12-01 8:01 ` Christoph Hellwig
2026-12-02 10:42 ` Hannes Reinecke
2026-12-02 15:15 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-12-01 8:01 UTC (permalink / raw)
To: Lin Tzu Yang
Cc: Sagi Grimberg, Chaitanya Kulkarni, Keith Busch, Hannes Reinecke,
linux-nvme, linux-kernel
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
Sashiko reports some additional attributes that might need a similar
treatment, can you look into those as well?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nvmet: fix one-byte overflow in configfs string show callbacks
2026-11-30 11:47 [PATCH] nvmet: fix one-byte overflow in configfs string show callbacks Lin Tzu Yang
2026-12-01 8:01 ` Christoph Hellwig
@ 2026-12-02 10:42 ` Hannes Reinecke
2026-12-02 15:15 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Hannes Reinecke @ 2026-12-02 10:42 UTC (permalink / raw)
To: Lin Tzu Yang, Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni
Cc: Keith Busch, linux-nvme, linux-kernel
On 11/30/26 12:47 PM, Lin Tzu Yang wrote:
> The show callbacks for the namespace attribute device_path and the
> host attributes dhchap_key and dhchap_ctrl_key print the stored string
> with sprintf(page, "%s\n", ...). configfs accepts up to 4095 bytes in a
> store, and the store side keeps them all, so with a 4095-byte value the
> show writes the string, the newline and the terminating NUL, one byte
> past the PAGE_SIZE buffer.
>
> KASAN in a QEMU arm64 guest, after writing 4095 bytes to
> namespaces/1/device_path and reading it back:
>
> BUG: KASAN: slab-out-of-bounds in vsnprintf+0xdd8/0xdfc
> Write of size 1 at addr ffff0000127cf000 by task cat/4329
> vsnprintf+0xdd8/0xdfc
> sprintf+0xb0/0xec
> nvmet_ns_device_path_show+0x44/0x68
> configfs_read_iter+0x284/0x46c
> The buggy address is located 0 bytes to the right of
> allocated 4096-byte region
>
> dhchap_key and dhchap_ctrl_key with "DHHC-1:00:" followed by 4085
> bytes give the same report.
>
> Use scnprintf() with PAGE_SIZE, as the passthru device_path show
> already does. A value that does not fit loses its trailing newline
> instead of overflowing the buffer.
>
> Fixes: a07b4970f464 ("nvmet: add a generic NVMe target")
> Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication")
> Cc: stable@vger.kernel.org
> Signed-off-by: Lin Tzu Yang <rongh7426@gmail.com>
> ---
> Tested on configfs-next 2e0fad9d2eae in a QEMU/KVM arm64 guest with
> KASAN and kasan_multi_shot. Writing 4095 bytes to each of the three
> attributes and reading it back gave one KASAN report per attribute
> before the patch, and none after; reads return 4095 bytes. Normal
> values such as /dev/nullb0 and DHHC-1:00:abcd: still read back with
> their newline, and enabling the namespace still works. Build-tested
> with W=1 on nvme-7.4.
>
> Found by writing boundary values to every nvmet configfs attribute.
>
> This patch was written with the help of an AI coding assistant
> (Claude). I ran the tests above and reviewed the change.
>
> drivers/nvme/target/configfs.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nvmet: fix one-byte overflow in configfs string show callbacks
2026-11-30 11:47 [PATCH] nvmet: fix one-byte overflow in configfs string show callbacks Lin Tzu Yang
2026-12-01 8:01 ` Christoph Hellwig
2026-12-02 10:42 ` Hannes Reinecke
@ 2026-12-02 15:15 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2026-12-02 15:15 UTC (permalink / raw)
To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni, Lin Tzu Yang
Cc: Hannes Reinecke, linux-nvme, linux-kernel
On Mon, 30 Nov 2026 19:47:11 +0800, Lin Tzu Yang wrote:
> The show callbacks for the namespace attribute device_path and the
> host attributes dhchap_key and dhchap_ctrl_key print the stored string
> with sprintf(page, "%s\n", ...). configfs accepts up to 4095 bytes in a
> store, and the store side keeps them all, so with a 4095-byte value the
> show writes the string, the newline and the terminating NUL, one byte
> past the PAGE_SIZE buffer.
>
> [...]
Thanks, applied to nvme-7.4.
[1/1] nvmet: fix one-byte overflow in configfs string show callbacks
commit: da4d3b7a809a62d230d05aea80272f7682e890e2
--
Keith Busch <kbusch@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 15:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 11:47 [PATCH] nvmet: fix one-byte overflow in configfs string show callbacks Lin Tzu Yang
2026-12-01 8:01 ` Christoph Hellwig
2026-12-02 10:42 ` Hannes Reinecke
2026-12-02 15:15 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®