lkml.org 
[lkml]   [2014]   [Jul]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 2/2] brd: Fix brd_direct_access with partitions

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



\
 
 \ /
  Last update: 2014-07-30 21:21    [W:0.056 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site