]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
drbd: fix regression: potential NULL pointer dereference
authorPhilipp Reisner <philipp.reisner@linbit.com>
Fri, 19 Oct 2012 12:19:23 +0000 (14:19 +0200)
committerPhilipp Reisner <philipp.reisner@linbit.com>
Fri, 9 Nov 2012 13:11:42 +0000 (14:11 +0100)
recent commit
    drbd: always write bitmap on detach
introduced a bitmap writeout during detach,
which obviously needs some meta data device to write to.

Unfortunately, that same error path may be taken if we fail to attach,
e.g. due to UUID mismatch, after we changed state to D_ATTACHING,
but before the lower level device pointer is even assigned.

We need to test for presence of mdev->ldev.

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
drivers/block/drbd/drbd_int.h
drivers/block/drbd/drbd_main.c

index 32a9ab67a5f6406f72de2dc940545165ff85d4a4..057ffed6eb7e2e4ea8b95db964f51e7be6f26e99 100644 (file)
@@ -2318,6 +2318,11 @@ static inline void drbd_md_flush(struct drbd_conf *mdev)
 {
        int r;
 
+       if (mdev->ldev == NULL) {
+               dev_warn(DEV, "mdev->ldev == NULL in drbd_md_flush\n");
+               return;
+       }
+
        if (test_bit(MD_NO_FUA, &mdev->flags))
                return;
 
index 0f73e157dee024b5a4670530c25a2d8069c21b1e..be4f58277124071c950d9b596b4ad9fa0b893ec2 100644 (file)
@@ -3235,8 +3235,12 @@ static int w_go_diskless(struct drbd_work *w, int unused)
         * (Do we want a specific meta data flag for this?)
         *
         * If that does not make it to stable storage either,
-        * we cannot do anything about that anymore.  */
-       if (mdev->bitmap) {
+        * we cannot do anything about that anymore.
+        *
+        * We still need to check if both bitmap and ldev are present, we may
+        * end up here after a failed attach, before ldev was even assigned.
+        */
+       if (mdev->bitmap && mdev->ldev) {
                if (drbd_bitmap_io_from_worker(mdev, drbd_bm_write,
                                        "detach", BM_LOCKED_MASK)) {
                        if (test_bit(WAS_READ_ERROR, &mdev->flags)) {