Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754210AbaG3OSz (ORCPT ); Wed, 30 Jul 2014 10:18:55 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:39435 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753385AbaG3OSx (ORCPT ); Wed, 30 Jul 2014 10:18:53 -0400 Message-ID: <53D8FEC7.8020804@plexistor.com> Date: Wed, 30 Jul 2014 17:18:47 +0300 From: Boaz Harrosh User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: Jens Axboe , Ross Zwisler , Matthew Wilcox CC: linux-scsi , Nick Piggin , linux-kernel Subject: [PATCH 2/2] brd: Fix brd_direct_access with partitions References: <53D7CDDD.1000302@gmail.com> <1406654379.2767.1.camel@rzwisler-mobl1.amr.corp.intel.com> <53D8D2C4.1030101@gmail.com> <53D8FE1F.1060009@plexistor.com> In-Reply-To: <53D8FE1F.1060009@plexistor.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Boaz Harrosh --- 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 -- 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/