linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] block: check partition alignment
@ 2016-12-14 16:47 Stefan Haberland
  2016-12-14 17:07 ` Christoph Hellwig
  2016-12-15  0:29 ` [RFC] " Damien Le Moal
  0 siblings, 2 replies; 10+ messages in thread
From: Stefan Haberland @ 2016-12-14 16:47 UTC (permalink / raw)
  To: axboe, linux-block, linux-kernel; +Cc: hoeppner, sebott

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..8b83afee 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_physical_block_size(bdev) != 0)
+				return -EINVAL;
 
 			mutex_lock(&bdev->bd_mutex);
 
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-12-19 16:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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         ` [v2] " Stefan Haberland
2016-12-19 16:18           ` Christoph Hellwig
2016-12-15  0:29 ` [RFC] " Damien Le Moal
2016-12-15  0:55   ` Damien Le Moal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).