All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boaz Harrosh <boaz@plexistor.com>
To: Jens Axboe <axboe@kernel.dk>,
	Ross Zwisler <ross.zwisler@linux.intel.com>,
	Matthew Wilcox <willy@linux.intel.com>
Cc: linux-scsi <linux-scsi@vger.kernel.org>,
	Nick Piggin <npiggin@gmail.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] brd: Fix brd_direct_access with partitions
Date: Wed, 30 Jul 2014 17:18:47 +0300	[thread overview]
Message-ID: <53D8FEC7.8020804@plexistor.com> (raw)
In-Reply-To: <53D8FE1F.1060009@plexistor.com>


When brd_direct_access() is called on a partition-bdev
it would access the wrong sector. And caller would then
corrupt the device's data.

This is a preliminary fix, Matthew Wilcox has a patch
in his DAX patchset which will define a global wrapper
to bdev->bd_disk->fops->direct_access that will do the
proper checks and translations before calling a driver
global member. (The way it is done at the rest of the
block stack)

CC: Matthew Wilcox <matthew.r.wilcox@intel.com>
Signed-off-by: Boaz Harrosh <boaz@plexistor.com>
---
 drivers/block/brd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 92334f6..7506864 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -378,9 +378,10 @@ static int brd_direct_access(struct block_device *bdev, sector_t sector,
 
 	if (!brd)
 		return -ENODEV;
+	sector += get_start_sect(bdev);
 	if (sector & (PAGE_SECTORS-1))
 		return -EINVAL;
-	if (sector + PAGE_SECTORS > get_capacity(bdev->bd_disk))
+	if (unlikely(sector + PAGE_SECTORS > part_nr_sects_read(bdev->bd_part)))
 		return -ERANGE;
 	page = brd_insert_page(brd, sector);
 	if (!page)
-- 
1.9.3

  reply	other threads:[~2014-07-30 14:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-29 16:37 [RFD] brd.ko Never supported partitions should we remove the dead code ? Boaz Harrosh
2014-07-29 16:56 ` Matthew Wilcox
2014-07-29 17:13   ` Boaz Harrosh
2014-07-29 17:19 ` Ross Zwisler
2014-07-30 11:11   ` Boaz Harrosh
2014-07-30 14:15     ` [PATCH 1/2] brd: Fix the partitions BUG Boaz Harrosh
2014-07-30 14:18       ` Boaz Harrosh [this message]
2014-07-30 15:34         ` [PATCH 2/2] brd: Fix brd_direct_access with partitions Matthew Wilcox
2014-07-30 15:37           ` Boaz Harrosh
2014-07-30 16:50       ` [PATCH 1/2] brd: Fix the partitions BUG Ross Zwisler
2014-07-30 18:37         ` Boaz Harrosh

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=53D8FEC7.8020804@plexistor.com \
    --to=boaz@plexistor.com \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=npiggin@gmail.com \
    --cc=ross.zwisler@linux.intel.com \
    --cc=willy@linux.intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.