From: Denis Arefev <arefev@swemel.ru>
To: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <kch@nvidia.com>,
Hannes Reinecke <hare@kernel.org>,
Keith Busch <kbusch@kernel.org>,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
syzbot+a84181c81389771eb46a@syzkaller.appspotmail.com
Subject: [PATCH] nvme: Enter string size calculation “subsysnqn”
Date: Thu, 26 Dec 2024 13:45:35 +0300 [thread overview]
Message-ID: <20241226104546.13705-1-arefev@swemel.ru> (raw)
When memory is allocated, the size of the string
is calculated nvmet_subsys_alloc(...).
When memory was accessed, constant size was used.
Fixes: 95409e277d83 ("nvmet: implement unique discovery NQN")
Reported-by: syzbot+a84181c81389771eb46a@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a84181c81389771eb46a
Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
drivers/nvme/target/configfs.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index eeee9e9b854c..2f74204d000e 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -2247,14 +2247,15 @@ static struct config_group nvmet_hosts_group;
static ssize_t nvmet_root_discovery_nqn_show(struct config_item *item,
char *page)
{
- return snprintf(page, PAGE_SIZE, "%s\n", nvmet_disc_subsys->subsysnqn);
+ return snprintf(page, strnlen(nvmet_disc_subsys->subsysnqn, PAGE_SIZE),
+ "%s\n", nvmet_disc_subsys->subsysnqn);
}
static ssize_t nvmet_root_discovery_nqn_store(struct config_item *item,
const char *page, size_t count)
{
struct list_head *entry;
- size_t len;
+ size_t len, nqn_len;
len = strcspn(page, "\n");
if (!len || len > NVMF_NQN_FIELD_LEN - 1)
@@ -2271,8 +2272,9 @@ static ssize_t nvmet_root_discovery_nqn_store(struct config_item *item,
return -EINVAL;
}
}
- memset(nvmet_disc_subsys->subsysnqn, 0, NVMF_NQN_FIELD_LEN);
- memcpy(nvmet_disc_subsys->subsysnqn, page, len);
+ nqn_len = strnlen(nvmet_disc_subsys->subsysnqn, NVMF_NQN_SIZE);
+ memset(nvmet_disc_subsys->subsysnqn, 0, nqn_len);
+ memcpy(nvmet_disc_subsys->subsysnqn, page, nqn_len);
up_write(&nvmet_config_sem);
return len;
--
2.43.0
next reply other threads:[~2024-12-26 10:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-26 10:45 Denis Arefev [this message]
2025-01-03 7:01 ` [PATCH] nvme: Enter string size calculation “subsysnqn” Christoph Hellwig
2025-01-03 17:50 ` Caleb Sander
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=20241226104546.13705-1-arefev@swemel.ru \
--to=arefev@swemel.ru \
--cc=hare@kernel.org \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=syzbot+a84181c81389771eb46a@syzkaller.appspotmail.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