Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932551AbbKDJTK (ORCPT ); Wed, 4 Nov 2015 04:19:10 -0500 Received: from mx2.suse.de ([195.135.220.15]:47974 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932241AbbKDJS6 (ORCPT ); Wed, 4 Nov 2015 04:18:58 -0500 From: Jan Kara To: axboe@kernel.dk Cc: LKML , linux-fsdevel@vger.kernel.org, Jan Kara Subject: [PATCH] block: Don't allow illegal discard requests Date: Wed, 4 Nov 2015 10:18:41 +0100 Message-Id: <1446628721-11030-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: 1301 Lines: 38 Currently blkdev_issue_discard() doesn't check that submitted discard request matches granularity required by the underlying device. Submitting such requests to the device can have unexpected consequences (e.g. brd driver just discards more / less data depending on how exactly the request is aligned). So test that submitted discard request has the granularity required by the driver. Signed-off-by: Jan Kara --- block/blk-lib.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/blk-lib.c b/block/blk-lib.c index bd40292e5009..7170d02e9e9a 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -61,6 +61,13 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, if (!blk_queue_discard(q)) return -EOPNOTSUPP; + if (q->limits.discard_granularity) { + unsigned int gran_sect = q->limits.discard_granularity >> 9; + + if (sector % gran_sect || nr_sects % gran_sect) + return -EINVAL; + } + if (flags & BLKDEV_DISCARD_SECURE) { if (!blk_queue_secdiscard(q)) return -EOPNOTSUPP; -- 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/