Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1262150

[PATCH] block: Don't allow illegal discard requests

From Jan Kara <jack@suse.com>
Newsgroups linux.kernel
Subject [PATCH] block: Don't allow illegal discard requests
Date 2015-11-04 10:20 +0100
Message-ID <qr2oy-6Ys-7@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


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 <jack@suse.com>
---
 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/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] block: Don't allow illegal discard requests Jan Kara <jack@suse.com> - 2015-11-04 10:20 +0100
  Re: [PATCH] block: Don't allow illegal discard requests kbuild test robot <lkp@intel.com> - 2015-11-04 11:50 +0100
  Re: [PATCH] block: Don't allow illegal discard requests kbuild test robot <lkp@intel.com> - 2015-11-04 11:50 +0100
  Re: [PATCH] block: Don't allow illegal discard requests kbuild test robot <lkp@intel.com> - 2015-11-04 12:00 +0100
  Re: [PATCH] block: Don't allow illegal discard requests Christoph Hellwig <hch@infradead.org> - 2015-11-04 12:40 +0100
    Re: [PATCH] block: Don't allow illegal discard requests Jan Kara <jack@suse.cz> - 2015-11-04 15:20 +0100

csiph-web