From: Lin Tzu Yang <rongh7426@gmail.com>
To: "Martin K . Petersen" <mkp@kernel.org>
Cc: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] scsi: target: fix one-byte overflow in dbroot show
Date: Tue, 1 Dec 2026 14:06:32 +0800 [thread overview]
Message-ID: <20261201060632.880022-1-rongh7426@gmail.com> (raw)
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
reply other threads:[~2026-12-01 6:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201060632.880022-1-rongh7426@gmail.com \
--to=rongh7426@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=stable@vger.kernel.org \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox