mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.com>
To: axboe@kernel.dk
Cc: LKML <linux-kernel@vger.kernel.org>,
	linux-fsdevel@vger.kernel.org, Jan Kara <jack@suse.com>
Subject: [PATCH] block: Don't allow illegal discard requests
Date: Wed,  4 Nov 2015 10:18:41 +0100	[thread overview]
Message-ID: <1446628721-11030-1-git-send-email-jack@suse.com> (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


             reply	other threads:[~2015-11-04  9:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-04  9:18 Jan Kara [this message]
2015-11-04 10:46 ` kbuild test robot
2015-11-04 10:48 ` kbuild test robot
2015-11-04 10:53 ` kbuild test robot
2015-11-04 11:30 ` Christoph Hellwig
2015-11-04 14:17   ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446628721-11030-1-git-send-email-jack@suse.com \
    --to=jack@suse.com \
    --cc=axboe@kernel.dk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®