From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96FDF79C0 for ; Wed, 30 Nov 2022 18:43:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AD07C433D6; Wed, 30 Nov 2022 18:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669833835; bh=4lX1t1cAeiLv1956HblOOtIbXsiwCn351BBNmASwhU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BgWSDqTUXJoEy8Kcfg3fL9BcvyitDtj8weQ/pfQRLEleyNcD4dKW84u9WOWf7N3x0 V7ikxbcmGFetlRQH4/pMzzysWWzyH2Lnp4/K7BKDuV2i1VlnIjodMxktTXT9XJbqM9 maupXuesWTibxm7VIcnbiBaV/mzr5GQC5Lzs8VZs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Konstantin Shelekhin , Dmitriy Bogdanov , Aleksandr Miloserdov , Sagi Grimberg , Christoph Hellwig , Sasha Levin Subject: [PATCH 6.0 032/289] nvmet: fix memory leak in nvmet_subsys_attr_model_store_locked Date: Wed, 30 Nov 2022 19:20:17 +0100 Message-Id: <20221130180544.861376240@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221130180544.105550592@linuxfoundation.org> References: <20221130180544.105550592@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Aleksandr Miloserdov [ Upstream commit becc4cac309dc867571f0080fde4426a6c2222e0 ] Since model_number is allocated before it needs to be freed before kmemdump_nul. Reviewed-by: Konstantin Shelekhin Reviewed-by: Dmitriy Bogdanov Signed-off-by: Aleksandr Miloserdov Reviewed-by: Sagi Grimberg Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- 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 7f52d9dac443..a79eadb953de 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,11 @@ 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.35.1