[PATCH] nvmet: fix one-byte overflow in configfs string show callbacks
Hannes Reinecke
hare at suse.de
Wed Dec 2 02:42:20 PST 2026
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 at vger.kernel.org
> Signed-off-by: Lin Tzu Yang <rongh7426 at 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 at kernel.org>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare at 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
More information about the Linux-nvme
mailing list