linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
To: linux-nvme@lists.infradead.org
Cc: hch@lst.de, Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>,
	sagi@grimberg.me
Subject: [PATCH V2 3/4] nvmet: check sscanf value for subsys serial attr
Date: Wed,  8 Jan 2020 21:02:43 -0800	[thread overview]
Message-ID: <20200109050244.5493-4-chaitanya.kulkarni@wdc.com> (raw)
In-Reply-To: <20200109050244.5493-1-chaitanya.kulkarni@wdc.com>

For nvmet in configfs.c we check return values for all the sscanf()
calls. Add similar check into the nvmet_subsys_attr_serial_store().

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
Changes from V1:-

1. Use temp variable to scan the new serial value and retain original
   value if sscanf() fails.
---
 drivers/nvme/target/configfs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index b3237c2a1858..6ae6e5c9c2ca 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -852,10 +852,13 @@ static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item,
 static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
 					      const char *page, size_t count)
 {
-	struct nvmet_subsys *subsys = to_subsys(item);
+	u64 serial;
+
+	if (sscanf(page, "%llx\n", &serial) != 1)
+		return -EINVAL;
 
 	down_write(&nvmet_config_sem);
-	sscanf(page, "%llx\n", &subsys->serial);
+	to_subsys(item)->serial = serial;
 	up_write(&nvmet_config_sem);
 
 	return count;
-- 
2.22.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  parent reply	other threads:[~2020-01-09  5:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-09  5:02 [PATCH 0/4] nvmet: misc model, ctrl-id and AEN fixes Chaitanya Kulkarni
2020-01-09  5:02 ` [PATCH V4 1/4] nvmet: make ctrl-id configurable Chaitanya Kulkarni
2020-01-16 16:37   ` Christoph Hellwig
2020-01-09  5:02 ` [PATCH V5 2/4] nvmet: make ctrl model configurable Chaitanya Kulkarni
2020-01-16 16:40   ` Christoph Hellwig
2020-01-09  5:02 ` Chaitanya Kulkarni [this message]
2020-01-09  5:02 ` [PATCH V2 4/4] nvmet: update AEN list and array at one place Chaitanya Kulkarni
2020-01-16 16:55   ` Christoph Hellwig
2020-01-13 23:52 ` [PATCH 0/4] nvmet: misc model, ctrl-id and AEN fixes Chaitanya Kulkarni
2020-01-19 21:23 Chaitanya Kulkarni
2020-01-19 21:23 ` [PATCH V2 3/4] nvmet: check sscanf value for subsys serial attr Chaitanya Kulkarni
2020-01-30 18:29 [PATCH 0/4] nvmet: misc model, ctrl-id and AEN fixes Chaitanya Kulkarni
2020-01-30 18:29 ` [PATCH V2 3/4] nvmet: check sscanf value for subsys serial attr Chaitanya Kulkarni

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=20200109050244.5493-4-chaitanya.kulkarni@wdc.com \
    --to=chaitanya.kulkarni@wdc.com \
    --cc=hch@lst.de \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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;
as well as URLs for NNTP newsgroup(s).