Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

brd: Refuse improperly aligned discard requests

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>

authored by

Jan Kara and committed by
Jens Axboe
2dbe5495 c5a37883

+3
+3
drivers/block/brd.c
··· 337 337 goto io_error; 338 338 339 339 if (unlikely(bio->bi_rw & REQ_DISCARD)) { 340 + if (sector & ((PAGE_SIZE >> SECTOR_SHIFT) - 1) || 341 + bio->bi_iter.bi_size & PAGE_MASK) 342 + goto io_error; 340 343 discard_from_brd(brd, sector, bio->bi_iter.bi_size); 341 344 goto out; 342 345 }