4.18-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <[email protected]>

commit b88aef36b87c9787a4db724923ec4f57dfd513f3 upstream.

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 <[email protected]>
Tested-by: Zdenek Kabelac <[email protected]>
Cc: [email protected]
Signed-off-by: Jens Axboe <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
 block/blk-lib.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -68,6 +68,8 @@ int __blkdev_issue_discard(struct block_
                 */
                req_sects = min_t(sector_t, nr_sects,
                                        q->limits.max_discard_sectors);
+               if (!req_sects)
+                       goto fail;
                if (req_sects > UINT_MAX >> 9)
                        req_sects = UINT_MAX >> 9;
 
@@ -105,6 +107,14 @@ int __blkdev_issue_discard(struct block_
 
        *biop = bio;
        return 0;
+
+fail:
+       if (bio) {
+               submit_bio_wait(bio);
+               bio_put(bio);
+       }
+       *biop = NULL;
+       return -EOPNOTSUPP;
 }
 EXPORT_SYMBOL(__blkdev_issue_discard);
 


Reply via email to