]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
nvme: fix inconsistent RCU list manipulation in nvme_ns_add_to_ctrl_list()
authorZheng Qixing <zhengqixing@huawei.com>
Tue, 1 Jul 2025 07:17:17 +0000 (15:17 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 24 Jul 2025 06:53:17 +0000 (08:53 +0200)
commit5d95fbbfaa8fbdd5db73cae1438464e32681158f
tree96ceccd7806c82c7a52f68591b5b9a0b7e33ef97
parent2baaf5bbab2ac474c4f92c10fcb3310f824db995
nvme: fix inconsistent RCU list manipulation in nvme_ns_add_to_ctrl_list()

[ Upstream commit 80d7762e0a42307ee31b21f090e21349b98c14f6 ]

When inserting a namespace into the controller's namespace list, the
function uses list_add_rcu() when the namespace is inserted in the middle
of the list, but falls back to a regular list_add() when adding at the
head of the list.

This inconsistency could lead to race conditions during concurrent
access, as users might observe a partially updated list. Fix this by
consistently using list_add_rcu() in both code paths to ensure proper
RCU protection throughout the entire function.

Fixes: be647e2c76b2 ("nvme: use srcu for iterating namespace list")
Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/host/core.c