md: add mddev->pers to avoid potential NULL pointer dereference
authorYufen Yu <yuyufen@huawei.com>
Tue, 2 Apr 2019 06:22:14 +0000 (14:22 +0800)
committerSong Liu <songliubraving@fb.com>
Wed, 10 Apr 2019 22:26:08 +0000 (15:26 -0700)
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: a6da4ef85cef ("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>
drivers/md/md.c

index 1fa2682951f1f5ea2499a00ebf0ffd6ad17bb664..664b77ceaf2d9c886f98add203d878b25e6d1ce4 100644 (file)
@@ -2850,8 +2850,10 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
                        err = 0;
                }
        } else if (cmd_match(buf, "re-add")) {
-               if (test_bit(Faulty, &rdev->flags) && (rdev->raid_disk == -1) &&
-                       rdev->saved_raid_disk >= 0) {
+               if (!rdev->mddev->pers)
+                       err = -EINVAL;
+               else if (test_bit(Faulty, &rdev->flags) && (rdev->raid_disk == -1) &&
+                               rdev->saved_raid_disk >= 0) {
                        /* clear_bit is performed _after_ all the devices
                         * have their local Faulty bit cleared. If any writes
                         * happen in the meantime in the local node, they