block: avoid null pointer dereference on null disk
authorColin Ian King <colin.king@canonical.com>
Mon, 6 Nov 2017 17:53:53 +0000 (17:53 +0000)
committerJens Axboe <axboe@kernel.dk>
Sat, 11 Nov 2017 02:55:57 +0000 (19:55 -0700)
It is possible that the pointer disk can be null and hence
we can get a null pointer deference when accessing disk->flags.
Add a null pointer check to avoid the dereference.

Detected by CoverityScan, CID#1461133 ("Explicit null dereferenced")

Fixes: 8ddcd653257c ("block: introduce GENHD_FL_HIDDEN")
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/genhd.c

index 3de1671631bfd632c5f6bc6deeafc58fe0786feb..997e598f3b86e92864fbb1694a01c6bda66e80e5 100644 (file)
@@ -798,7 +798,7 @@ struct gendisk *get_gendisk(dev_t devt, int *partno)
                spin_unlock_bh(&ext_devt_lock);
        }
 
-       if (unlikely(disk->flags & GENHD_FL_HIDDEN)) {
+       if (disk && unlikely(disk->flags & GENHD_FL_HIDDEN)) {
                put_disk(disk);
                disk = NULL;
        }