]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
block: fix infinite loop if the device loses discard capability
authorMikulas Patocka <mpatocka@redhat.com>
Tue, 3 Jul 2018 17:34:22 +0000 (13:34 -0400)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1837257
[ Upstream commit b88aef36b87c9787a4db724923ec4f57dfd513f3 ]

If __blkdev_issue_discard is in progress and a device mapper device is
reloaded with a table that doesn't support discard,
q->limits.max_discard_sectors is set to zero. This results in infinite
loop in __blkdev_issue_discard.

This patch checks if max_discard_sectors is zero and aborts with
-EOPNOTSUPP.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Zdenek Kabelac <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
block/blk-lib.c

index 061ab54561405e49029847b99aa88ff420912eae..012425f5bd8c5e01e22e1cd2a146221f4e25a260 100644 (file)
@@ -54,6 +54,8 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
                sector_t end_sect;
 
                req_sects = min(req_sects, bio_allowed_max_sectors(q));
+               if (!req_sects)
+                       goto fail;
 
                end_sect = sector + req_sects;
 
@@ -77,6 +79,14 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 
        *biop = bio;
        return 0;
+
+fail:
+       if (bio) {
+               submit_bio_wait(bio);
+               bio_put(bio);
+       }
+       *biop = NULL;
+       return -EOPNOTSUPP;
 }
 EXPORT_SYMBOL(__blkdev_issue_discard);