linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Aleksandr Miloserdov <a.miloserdov@yadro.com>
To: Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Chaitanya Kulkarni <kch@nvidia.com>
Cc: <linux-nvme@lists.infradead.org>, <linux@yadro.com>,
	Aleksandr Miloserdov <a.miloserdov@yadro.com>,
	Konstantin Shelekhin <k.shelekhin@yadro.com>,
	Dmitriy Bogdanov <d.bogdanov@yadro.com>
Subject: [PATCH 1/3] nvmet: fix memory leak in configfs
Date: Wed, 26 Oct 2022 12:31:33 +0400	[thread overview]
Message-ID: <20221026083135.77125-2-a.miloserdov@yadro.com> (raw)
In-Reply-To: <20221026083135.77125-1-a.miloserdov@yadro.com>

Since model_number is allocated before it needs to be freed before kmemdump_nul.

Reviewed-by: Konstantin Shelekhin <k.shelekhin@yadro.com>
Reviewed-by: Dmitriy Bogdanov <d.bogdanov@yadro.com>
Signed-off-by: Aleksandr Miloserdov <a.miloserdov@yadro.com>
---
 drivers/nvme/target/configfs.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index e34a2896fedb..89242b0f8614 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -1215,6 +1215,7 @@ static ssize_t nvmet_subsys_attr_model_store_locked(struct nvmet_subsys *subsys,
 		const char *page, size_t count)
 {
 	int pos = 0, len;
+	char *val;
 
 	if (subsys->subsys_discovered) {
 		pr_err("Can't set model number. %s is already assigned\n",
@@ -1237,9 +1238,14 @@ static ssize_t nvmet_subsys_attr_model_store_locked(struct nvmet_subsys *subsys,
 			return -EINVAL;
 	}
 
-	subsys->model_number = kmemdup_nul(page, len, GFP_KERNEL);
-	if (!subsys->model_number)
+	val = kmemdup_nul(page, len, GFP_KERNEL);
+	if (!val)
 		return -ENOMEM;
+
+	kfree(subsys->model_number);
+
+	subsys->model_number = val;
+
 	return count;
 }
 
-- 
2.37.0



  reply	other threads:[~2022-10-26  8:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26  8:31 [PATCH 0/3] Allow user to set nvmet firmware revision and IEEE OUI Aleksandr Miloserdov
2022-10-26  8:31 ` Aleksandr Miloserdov [this message]
2022-10-26 10:49   ` [PATCH 1/3] nvmet: fix memory leak in configfs Sagi Grimberg
2022-11-01  7:52   ` Christoph Hellwig
2022-10-26  8:31 ` [PATCH 2/3] nvmet: expose IEEE OUI to configfs Aleksandr Miloserdov
2022-10-26 10:49   ` Sagi Grimberg
2022-10-27 12:48     ` Aleksandr Miloserdov
2022-10-28 11:33     ` Konstantin Shelekhin
2022-10-30  8:29       ` Christoph Hellwig
2022-10-26  8:31 ` [PATCH 3/3] nvmet: expose firmware revision " Aleksandr Miloserdov

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=20221026083135.77125-2-a.miloserdov@yadro.com \
    --to=a.miloserdov@yadro.com \
    --cc=d.bogdanov@yadro.com \
    --cc=hch@lst.de \
    --cc=k.shelekhin@yadro.com \
    --cc=kch@nvidia.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux@yadro.com \
    --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).