xen/blkback: fix reference counting
authorVegard Nossum <vegard.nossum@oracle.com>
Thu, 5 Sep 2013 11:00:14 +0000 (13:00 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Dec 2013 18:56:25 +0000 (10:56 -0800)
commit ea5ec76d76da9279d12027c1828544c5ccbe7932 upstream.

If the permission check fails, we drop a reference to the blkif without
having taken it in the first place. The bug was introduced in commit
604c499cbbcc3d5fe5fb8d53306aa0fae1990109 (xen/blkback: Check device
permissions before allowing OP_DISCARD).

Cc: Jan Beulich <JBeulich@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/block/xen-blkback/blkback.c

index d81dfca755d15f2ad655596ed607fbe2f2fd891a..03dd4aa612dbf2a34a7b38b8c199da372a0cb6a3 100644 (file)
@@ -649,6 +649,8 @@ static int dispatch_discard_io(struct xen_blkif *blkif,
        unsigned long secure;
        struct phys_req preq;
 
+       xen_blkif_get(blkif);
+
        preq.sector_number = req->u.discard.sector_number;
        preq.nr_sects      = req->u.discard.nr_sectors;
 
@@ -661,7 +663,6 @@ static int dispatch_discard_io(struct xen_blkif *blkif,
        }
        blkif->st_ds_req++;
 
-       xen_blkif_get(blkif);
        secure = (blkif->vbd.discard_secure &&
                 (req->u.discard.flag & BLKIF_DISCARD_SECURE)) ?
                 BLKDEV_DISCARD_SECURE : 0;