Skip to content

Commit 570b914

Browse files
Li Lingfengliu-song-6
authored andcommitted
md: use RCU lock to protect traversal in md_spares_need_change()
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: [email protected] # 6.7+ Signed-off-by: Li Lingfeng <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9cfcf99 commit 570b914

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/md/md.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9240,9 +9240,14 @@ static bool md_spares_need_change(struct mddev *mddev)
92409240
{
92419241
struct md_rdev *rdev;
92429242

9243-
rdev_for_each(rdev, mddev)
9244-
if (rdev_removeable(rdev) || rdev_addable(rdev))
9243+
rcu_read_lock();
9244+
rdev_for_each_rcu(rdev, mddev) {
9245+
if (rdev_removeable(rdev) || rdev_addable(rdev)) {
9246+
rcu_read_unlock();
92459247
return true;
9248+
}
9249+
}
9250+
rcu_read_unlock();
92469251
return false;
92479252
}
92489253

0 commit comments

Comments
 (0)