brd: Refuse improperly aligned discard requests
authorJan Kara <jack@suse.com>
Wed, 4 Nov 2015 16:13:39 +0000 (17:13 +0100)
committerJens Axboe <axboe@fb.com>
Wed, 11 Nov 2015 16:36:56 +0000 (09:36 -0700)
Currently when improperly aligned discard request is submitted, we just
silently discard more / less data which results in filesystem corruption
in some cases. Refuse such misaligned requests.

Signed-off-by: Jan Kara <jack@suse.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/block/brd.c

index c9f9c30d646756296e0e4bdd212a33ba28a479b6..a5880f4ab40eb069bda60d6403b223d61ff1db80 100644 (file)
@@ -337,6 +337,9 @@ static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
                goto io_error;
 
        if (unlikely(bio->bi_rw & REQ_DISCARD)) {
+               if (sector & ((PAGE_SIZE >> SECTOR_SHIFT) - 1) ||
+                   bio->bi_iter.bi_size & PAGE_MASK)
+                       goto io_error;
                discard_from_brd(brd, sector, bio->bi_iter.bi_size);
                goto out;
        }