[PATCH] nvmet: fix one-byte overflow in configfs string show callbacks
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Mon Nov 30 03:59:49 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] nvmet: snprintf() in nvmet_passthru_device_path_show()
mismatches changelog
--
commit 439334c02309f8c7dc424a02bda5bf34576398b8
Author: Lin Tzu Yang <rongh7426 at gmail.com>
nvmet: fix one-byte overflow in configfs string show callbacks
This commit replaces sprintf() with scnprintf(..., PAGE_SIZE, ...) in
nvmet_ns_device_path_show(), nvmet_host_dhchap_key_show(), and
nvmet_host_dhchap_ctrl_key_show() to prevent a one-byte buffer overflow on
4095-byte attribute values.
> 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.
[Severity: Low]
Does nvmet_passthru_device_path_show() need to be converted to scnprintf()
as well, or should the commit message be adjusted?
drivers/nvme/target/configfs.c:nvmet_passthru_device_path_show() {
...
ret = snprintf(page, PAGE_SIZE, "%s\n",
subsys->passthru && subsys->passthru->ctrl_path ?
subsys->passthru->ctrl_path : "");
...
}
nvmet_passthru_device_path_show() currently uses snprintf() rather than
scnprintf(). When ctrl_path is 4095 bytes long, snprintf() drops the
newline, writes a NUL terminator at page[4095], and returns 4096, which
fill_read_buffer() accepts (count <= SIMPLE_ATTR_SIZE) so configfs copies
the trailing NUL byte to userspace instead of returning 4095 bytes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130114711.842577-1-rongh7426@gmail.com?part=1
More information about the Linux-nvme
mailing list