Skip to content

Commit ee37e62

Browse files
Yufen Yuliu-song-6
authored andcommitted
md: add mddev->pers to avoid potential NULL pointer dereference
When doing re-add, we need to ensure rdev->mddev->pers is not NULL, which can avoid potential NULL pointer derefence in fallowing add_bound_rdev(). Fixes: a6da4ef ("md: re-add a failed disk") Cc: Xiao Ni <xni@redhat.com> Cc: NeilBrown <neilb@suse.com> Cc: <stable@vger.kernel.org> # 4.4+ Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: Yufen Yu <yuyufen@huawei.com> Signed-off-by: Song Liu <songliubraving@fb.com>
1 parent 0d41382 commit ee37e62

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎drivers/md/md.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,8 +2850,10 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
28502850
err = 0;
28512851
}
28522852
} else if (cmd_match(buf, "re-add")) {
2853-
if (test_bit(Faulty, &rdev->flags) && (rdev->raid_disk == -1) &&
2854-
rdev->saved_raid_disk >= 0) {
2853+
if (!rdev->mddev->pers)
2854+
err = -EINVAL;
2855+
else if (test_bit(Faulty, &rdev->flags) && (rdev->raid_disk == -1) &&
2856+
rdev->saved_raid_disk >= 0) {
28552857
/* clear_bit is performed _after_ all the devices
28562858
* have their local Faulty bit cleared. If any writes
28572859
* happen in the meantime in the local node, they

0 commit comments

Comments
 (0)