From: Changyul Lee <lcy8047@gmail.com>
To: Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <kch@nvidia.com>
Cc: Logan Gunthorpe <logang@deltatee.com>,
Stephen Bates <sbates@raithlin.com>,
Bjorn Helgaas <bhelgaas@google.com>,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
Changyul Lee <lcy8047@gmail.com>
Subject: [PATCH] nvmet: look up the P2P device under rcu_read_lock()
Date: Sun, 15 Nov 2026 21:25:58 -0500 [thread overview]
Message-ID: <20261116022558.560013-1-lcy8047@gmail.com> (raw)
nvmet_req_find_p2p_dev() looks up ctrl->p2p_ns_map in the I/O path
without subsys->lock and outside an RCU read-side critical section.
nvmet_ns_disable() can meanwhile delete an entry from the same radix
tree, and radix_tree_delete() frees the nodes that become empty with
call_rcu(). With preemptible RCU, the grace period can end while the
lookup still walks such a node, and the lookup reads freed memory.
radix_tree_lookup() without the tree lock must be called under
rcu_read_lock(). Take it around the lookup.
Fixes: c6925093d0b2 ("nvmet: Optionally use PCI P2P memory")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.
Compile-tested only, with x86_64_defconfig plus NVME_TARGET_RDMA,
PCI_P2PDMA and W=1.
drivers/nvme/target/core.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index e31d65228c11..1b34fc5549f6 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -1341,10 +1341,17 @@ static int nvmet_req_alloc_p2pmem_sgls(struct pci_dev *p2p_dev,
static struct pci_dev *nvmet_req_find_p2p_dev(struct nvmet_req *req)
{
+ struct pci_dev *p2p_dev;
+
if (!IS_ENABLED(CONFIG_PCI_P2PDMA) ||
!req->sq->ctrl || !req->sq->qid || !req->ns)
return NULL;
- return radix_tree_lookup(&req->sq->ctrl->p2p_ns_map, req->ns->nsid);
+
+ rcu_read_lock();
+ p2p_dev = radix_tree_lookup(&req->sq->ctrl->p2p_ns_map, req->ns->nsid);
+ rcu_read_unlock();
+
+ return p2p_dev;
}
int nvmet_req_alloc_sgls(struct nvmet_req *req)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.43.0
reply other threads:[~2026-11-16 2:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261116022558.560013-1-lcy8047@gmail.com \
--to=lcy8047@gmail.com \
--cc=bhelgaas@google.com \
--cc=hch@lst.de \
--cc=kch@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=logang@deltatee.com \
--cc=sagi@grimberg.me \
--cc=sbates@raithlin.com \
/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
all inboxes | Powered by JetHome®