* [PATCH] scsi: target: fix one-byte overflow in dbroot show
@ 2026-12-01 6:06 Lin Tzu Yang
0 siblings, 0 replies; only message in thread
From: Lin Tzu Yang @ 2026-12-01 6:06 UTC (permalink / raw)
To: Martin K . Petersen; +Cc: target-devel, linux-scsi, linux-kernel, stable
dbroot_store() accepts up to DB_ROOT_LEN - 1 = 4095 bytes, as long
as the string names an existing directory. A path made of 4095
slashes resolves to "/", so it is accepted and stored as is.
dbroot_show() then prints it with sprintf(page, "%s\n", db_root),
which writes 4095 characters, the newline and the terminating NUL
into the PAGE_SIZE configfs buffer: 4097 bytes. KASAN reports it on
the first read:
BUG: KASAN: slab-out-of-bounds in vsnprintf+0xdd8/0xdfc
Write of size 1 at addr ffff000012a37000 by task cat/109
...
sprintf+0xb0/0xec
target_core_item_dbroot_show+0x28/0x40
configfs_read_iter+0x284/0x46c
Use sysfs_emit(), which is bounded by PAGE_SIZE. It is already used
elsewhere in this file.
Fixes: a96e9783e058 ("target: make target db location configurable")
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.
The patch is against scsi for-next; it was tested in QEMU (arm64,
KASAN) on configfs-next (2e0fad9d2eae), where this function is
identical. Before: KASAN report on reading back a 4095-byte dbroot.
After: no report, the read returns the 4095 characters.
drivers/target/target_core_configfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 2b19a95600..199e5e79b7 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -101,7 +101,7 @@ static char db_root_stage[DB_ROOT_LEN];
static ssize_t target_core_item_dbroot_show(struct config_item *item,
char *page)
{
- return sprintf(page, "%s\n", db_root);
+ return sysfs_emit(page, "%s\n", db_root);
}
static ssize_t target_core_item_dbroot_store(struct config_item *item,
--
2.47.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-01 6:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 6:06 [PATCH] scsi: target: fix one-byte overflow in dbroot show Lin Tzu Yang
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®