block: xen-blkfront: Fix possible NULL ptr dereference
authorFelipe Pena <felipensp@gmail.com>
Sat, 9 Nov 2013 15:36:09 +0000 (13:36 -0200)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tue, 26 Nov 2013 16:24:01 +0000 (11:24 -0500)
In the blkif_release function the bdget_disk() call might returns
a NULL ptr which might be dereferenced on bdev->bd_openers checking

Signed-off-by: Felipe Pena <felipensp@gmail.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
[v2: Added WARN per Roger's suggestion]

drivers/block/xen-blkfront.c

index 5f926de61950622cf13aec6dea1f8aa670bad391..c4a4c900628891c31fec541277cb7ffea9a3e68b 100644 (file)
@@ -2011,6 +2011,10 @@ static void blkif_release(struct gendisk *disk, fmode_t mode)
 
        bdev = bdget_disk(disk, 0);
 
+       if (!bdev) {
+               WARN(1, "Block device %s yanked out from us!\n", disk->disk_name);
+               goto out_mutex;
+       }
        if (bdev->bd_openers)
                goto out;
 
@@ -2041,6 +2045,7 @@ static void blkif_release(struct gendisk *disk, fmode_t mode)
 
 out:
        bdput(bdev);
+out_mutex:
        mutex_unlock(&blkfront_mutex);
 }