Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755950AbbKDQNp (ORCPT ); Wed, 4 Nov 2015 11:13:45 -0500 Received: from mx2.suse.de ([195.135.220.15]:33431 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751836AbbKDQNn (ORCPT ); Wed, 4 Nov 2015 11:13:43 -0500 From: Jan Kara To: axboe@kernel.dk Cc: LKML , linux-fsdevel@vger.kernel.org, Christoph Hellwig , Jan Kara Subject: [PATCH] brd: Refuse improperly aligned discard requests Date: Wed, 4 Nov 2015 17:13:39 +0100 Message-Id: <1446653619-22880-1-git-send-email-jack@suse.com> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1045 Lines: 31 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 --- drivers/block/brd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index b9794aeeb878..4ef4cdf67ede 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -337,6 +337,9 @@ static void 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; } -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/