Linux-NVME Archive on lore.kernel.org
 help / color / 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>
Subject: [PATCH V2 3/3] nvmet: check sscanf value for subsys serial attr
Date: Wed, 27 Nov 2019 01:40:34 -0800
Message-ID: <20191127094034.12334-4-chaitanya.kulkarni@wdc.com> (raw)
In-Reply-To: <20191127094034.12334-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().

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 4dea77a7da3e..0a19fd73979d 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 index

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27  9:40 [PATCH 0/3] nvmet: make model/ctrl-id configurable, configfs fix Chaitanya Kulkarni
2019-11-27  9:40 ` [PATCH V3 1/3] nvmet: make ctrl-id configurable Chaitanya Kulkarni
2019-12-12  0:45   ` Sagi Grimberg
2019-12-12  9:22     ` Christoph Hellwig
2019-12-12  9:26   ` Christoph Hellwig
2019-12-16 20:40     ` Chaitanya Kulkarni
2019-11-27  9:40 ` [PATCH V4 2/3] nvmet: make ctrl model configurable Chaitanya Kulkarni
2019-12-12  0:45   ` Sagi Grimberg
2019-12-12  9:28   ` Christoph Hellwig
2019-12-12  9:46     ` Christoph Hellwig
2019-12-17  4:53     ` Chaitanya Kulkarni
2019-11-27  9:40 ` Chaitanya Kulkarni [this message]
2019-12-12  0:46   ` [PATCH V2 3/3] nvmet: check sscanf value for subsys serial attr Sagi Grimberg
2019-12-12  9:29   ` Christoph Hellwig
2019-12-11  5:35 ` [PATCH 0/3] nvmet: make model/ctrl-id configurable, configfs fix Chaitanya Kulkarni

Reply instructions:

You may reply publically 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=20191127094034.12334-4-chaitanya.kulkarni@wdc.com \
    --to=chaitanya.kulkarni@wdc.com \
    --cc=hch@lst.de \
    --cc=linux-nvme@lists.infradead.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

Linux-NVME Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nvme/0 linux-nvme/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nvme linux-nvme/ https://lore.kernel.org/linux-nvme \
		linux-nvme@lists.infradead.org
	public-inbox-index linux-nvme

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-nvme


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git