public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Keith Busch <kbusch@kernel.org>, Christoph Hellwig <hch@lst.de>,
	Sasha Levin <sashal@kernel.org>,
	sagi@grimberg.me, linux-nvme@lists.infradead.org
Subject: [PATCH AUTOSEL 6.8 11/11] nvme: clear caller pointer on identify failure
Date: Sun, 24 Mar 2024 13:05:46 -0400	[thread overview]
Message-ID: <20240324170552.545730-11-sashal@kernel.org> (raw)
In-Reply-To: <20240324170552.545730-1-sashal@kernel.org>

From: Keith Busch <kbusch@kernel.org>

[ Upstream commit 7e80eb792bd7377a20f204943ac31c77d859be89 ]

The memory allocated for the identification is freed on failure. Set
it to NULL so the caller doesn't have a pointer to that freed address.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/nvme/host/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 0a96362912ced..39ee3036bd516 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1398,8 +1398,10 @@ static int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id)
 
 	error = nvme_submit_sync_cmd(dev->admin_q, &c, *id,
 			sizeof(struct nvme_id_ctrl));
-	if (error)
+	if (error) {
 		kfree(*id);
+		*id = NULL;
+	}
 	return error;
 }
 
@@ -1528,6 +1530,7 @@ int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid,
 	if (error) {
 		dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error);
 		kfree(*id);
+		*id = NULL;
 	}
 	return error;
 }
-- 
2.43.0


      parent reply	other threads:[~2024-03-24 17:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-24 17:05 [PATCH AUTOSEL 6.8 01/11] sysv: don't call sb_bread() with pointers_lock held Sasha Levin
2024-03-24 17:05 ` [PATCH AUTOSEL 6.8 02/11] rcu-tasks: Repair RCU Tasks Trace quiescence check Sasha Levin
2024-03-24 17:05 ` [PATCH AUTOSEL 6.8 03/11] rcu-tasks: Add data to eliminate RCU-tasks/do_exit() deadlocks Sasha Levin
2024-03-24 17:05 ` [PATCH AUTOSEL 6.8 04/11] rcu-tasks: Initialize " Sasha Levin
2024-03-24 17:05 ` [PATCH AUTOSEL 6.8 05/11] rcu-tasks: Maintain lists " Sasha Levin
2024-03-24 17:05 ` [PATCH AUTOSEL 6.8 06/11] rcu-tasks: Eliminate deadlocks involving do_exit() and RCU tasks Sasha Levin
2024-03-24 17:05 ` [PATCH AUTOSEL 6.8 07/11] rcu-tasks: Maintain real-time response in rcu_tasks_postscan() Sasha Levin
2024-03-24 17:05 ` [PATCH AUTOSEL 6.8 08/11] block: prevent division by zero in blk_rq_stat_sum() Sasha Levin
2024-03-24 17:05 ` [PATCH AUTOSEL 6.8 09/11] fs: improve dump_mapping() robustness Sasha Levin
2024-03-24 17:05 ` [PATCH AUTOSEL 6.8 10/11] rcu/nocb: Fix WARN_ON_ONCE() in the rcu_nocb_bypass_lock() Sasha Levin
2024-03-24 17:05 ` Sasha Levin [this message]

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=20240324170552.545730-11-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    --cc=stable@vger.kernel.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
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