From: Zijie Zhao via B4 Relay <devnull+zzjas98.gmail.com@kernel.org>
To: Josef Bacik <josef@toxicpanda.com>, Jens Axboe <axboe@kernel.dk>
Cc: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>,
Xiubo Li <xiubli@redhat.com>, Ming Lei <ming.lei@redhat.com>,
linux-block@vger.kernel.org, nbd@other.debian.org,
linux-kernel@vger.kernel.org, Zijie Zhao <zzjas98@gmail.com>
Subject: [PATCH] nbd: use sysfs_emit() in backend_show()
Date: Tue, 01 Dec 2026 21:42:05 -0600 [thread overview]
Message-ID: <20261201-kbug-l951-v1-1-71c8ab366542@gmail.com> (raw)
From: Zijie Zhao <zzjas98@gmail.com>
backend_show() prints nbd->backend into the sysfs buffer with an
unbounded sprintf(). The string is a copy of the
NBD_ATTR_BACKEND_IDENTIFIER netlink attribute made by nla_strdup() in
nbd_genl_connect(), and the attribute policy is a plain NLA_STRING
without a length limit. With an identifier longer than PAGE_SIZE - 2
bytes, each time sysfs formats /sys/block/nbdX/backend by calling
backend_show(), it writes past the end of the PAGE_SIZE buffer that
sysfs passes to the show callback.
Use sysfs_emit(), which bounds the output to PAGE_SIZE.
Found by a static analysis tool.
The fix and this changelog were drafted with AI assistance (Claude Code,
with a second review by OpenAI Codex), then reviewed by the submitter.
Fixes: 6497ef8df568 ("nbd: provide a way for userspace processes to identify device backends")
Signed-off-by: Zijie Zhao <zzjas98@gmail.com>
---
Testing:
- Compile-tested on x86_64 (allmodconfig, W=1): drivers/block/nbd.o; no
new warnings.
- checkpatch.pl --strict: no errors or warnings.
---
drivers/block/nbd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index b2b27f90a7ed..f213ccd69463 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -254,7 +254,7 @@ static ssize_t backend_show(struct device *dev,
struct gendisk *disk = dev_to_disk(dev);
struct nbd_device *nbd = disk->private_data;
- return sprintf(buf, "%s\n", nbd->backend ?: "");
+ return sysfs_emit(buf, "%s\n", nbd->backend ?: "");
}
static const struct device_attribute backend_attr = {
---
base-commit: 348d25516523c3edfec477d56abde2b2491dbf9d
change-id: 20261201-kbug-l951-6ff3b7ee1deb
Best regards,
--
Zijie Zhao <zzjas98@gmail.com>
next reply other threads:[~2026-12-02 3:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 3:42 Zijie Zhao via B4 Relay [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-12-02 3:41 Anh Nguyen Hoang via B4 Relay
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=20261201-kbug-l951-v1-1-71c8ab366542@gmail.com \
--to=devnull+zzjas98.gmail.com@kernel.org \
--cc=axboe@kernel.dk \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=nbd@other.debian.org \
--cc=prasanna.kalever@redhat.com \
--cc=xiubli@redhat.com \
--cc=zzjas98@gmail.com \
/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
all inboxes | Powered by JetHome®