Skip to content

Commit

Permalink
md: use RCU lock to protect traversal in md_spares_need_change()
Browse files Browse the repository at this point in the history
[ Upstream commit 570b914 ]

Since md_start_sync() will be called without the protect of mddev_lock,
and it can run concurrently with array reconfiguration, traversal of rdev
in it should be protected by RCU lock.
Commit bc08041 ("md: suspend array in md_start_sync() if array need
reconfiguration") added md_spares_need_change() to md_start_sync(),
casusing use of rdev without any protection.
Fix this by adding RCU lock in md_spares_need_change().

Fixes: bc08041 ("md: suspend array in md_start_sync() if array need reconfiguration")
Cc: stable@vger.kernel.org # 6.7+
Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com>
Signed-off-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20240104133629.1277517-1-lilingfeng@huaweicloud.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Li Lingfeng authored and gregkh committed Apr 3, 2024
1 parent c245767 commit 186cade
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/md/md.c
Expand Up @@ -9302,9 +9302,14 @@ static bool md_spares_need_change(struct mddev *mddev)
{
struct md_rdev *rdev;

rdev_for_each(rdev, mddev)
if (rdev_removeable(rdev) || rdev_addable(rdev))
rcu_read_lock();
rdev_for_each_rcu(rdev, mddev) {
if (rdev_removeable(rdev) || rdev_addable(rdev)) {
rcu_read_unlock();
return true;
}
}
rcu_read_unlock();
return false;
}

Expand Down

0 comments on commit 186cade

Please sign in to comment.