From: Stefan Haberland <sth@linux.vnet.ibm.com>
To: hch@infradead.org, damien.lemoal@wdc.com, axboe@kernel.dk,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: hoeppner@linux.vnet.ibm.com, sebott@linux.vnet.ibm.com
Subject: [v2] block: check partition alignment
Date: Mon, 19 Dec 2016 17:15:50 +0100 [thread overview]
Message-ID: <20161219161550.55414-2-sth@linux.vnet.ibm.com> (raw)
In-Reply-To: <20161219161550.55414-1-sth@linux.vnet.ibm.com>
In-Reply-To: <88308b2d-de52-b97a-2001-96da7e9f5d1f@wdc.com>
Partitions that are not aligned to the blocksize of a device may cause
invalid I/O requests because the blocklayer cares only about alignment
within the partition when building requests on partitions.
device
|--------4096--------|--------4096--------|--------4096--------|
partition offset 512byte
|-512-|--------4096--------|--------4096--------|--------4096--------|
When reading/writing one 4k block of the partition this maps to
reading/writing with an offset of 512 byte of the device leading to
unaligned requests for the device which in turn may cause unexpected
behavior of the device driver.
For DASD devices we have to translate the block number into a cylinder,
head, record format. The unaligned requests lead to wrong calculation
and therefore to misdirected I/O. In a "good" case this leads to I/O
errors because the underlying hardware detects the wrong addressing.
In a worst case scenario this might destroy data on the device.
To prevent partitions that are not aligned to the physical blocksize
of a device check for the alignment in the blkpg_ioctl.
Signed-off-by: Stefan Haberland <sth@linux.vnet.ibm.com>
---
block/ioctl.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/block/ioctl.c b/block/ioctl.c
index 755119c..36b5c21 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -45,6 +45,9 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
|| pstart < 0 || plength < 0 || partno > 65535)
return -EINVAL;
}
+ /* check if partition is aligned to blocksize */
+ if (p.start & (bdev_logical_block_size(bdev) - 1))
+ return -EINVAL;
mutex_lock(&bdev->bd_mutex);
--
2.8.4
next prev parent reply other threads:[~2016-12-19 16:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-14 16:47 [RFC] block: check partition alignment Stefan Haberland
2016-12-14 17:07 ` Christoph Hellwig
2016-12-15 1:33 ` Damien Le Moal
2016-12-15 8:45 ` Christoph Hellwig
2016-12-15 8:56 ` Damien Le Moal
2016-12-19 16:15 ` Stefan Haberland
2016-12-19 16:15 ` Stefan Haberland [this message]
2016-12-19 16:18 ` [v2] " Christoph Hellwig
2016-12-15 0:29 ` [RFC] " Damien Le Moal
2016-12-15 0:55 ` Damien Le Moal
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=20161219161550.55414-2-sth@linux.vnet.ibm.com \
--to=sth@linux.vnet.ibm.com \
--cc=axboe@kernel.dk \
--cc=damien.lemoal@wdc.com \
--cc=hch@infradead.org \
--cc=hoeppner@linux.vnet.ibm.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sebott@linux.vnet.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox