Skip to contentSkip to conversation

Patch for mapping bug in drivers/md/dm-unstripe.c

PATCH Matt Whitlock 3 participants 5 messages Jan 18 – Jan 20 Device mapper

lore
Share & tools
lore
#0 lore raw

The "unstriped" device-mapper target incorrectly calculates the sector offset on the mapped device when the target's origin is not zero.

Take for example this hypothetical concatenation of the members of a two-disk RAID0:

linearized: 0 2097152 unstriped 2 128 0 /dev/md/raid0 0
linearized: 2097152 2097152 unstriped 2 128 1 /dev/md/raid0 0

The intent in this example is to create a single device named /dev/mapper/linearized that comprises all of the chunks of the first disk of the RAID0 set, followed by all of the chunks of the second disk of the RAID0 set.

This fails because dm-unstripe.c's map_to_core function does its computations based on the sector number within the mapper device rather than the sector number within the target. The bug turns invisible when the target's origin is at sector zero of the mapper device, as is the common case. In the example above, however, what happens is that the first half of the mapper device gets mapped correctly to the first disk of the RAID0, but the second half of the mapper device gets mapped past the end of the RAID0 device, and accesses to any of those sectors return errors.

Here is a very simple (tested) patch that corrects the problem:

md/dm-unstripe.c renamed from md/dm-unstripe.c~ +1 -1
@@ -117,7 +117,7 @@
 static sector_t map_to_core(struct dm_target *ti, struct bio *bio)
 {
 	struct unstripe_c *uc = ti->private;
-	sector_t sector = bio->bi_iter.bi_sector;
+	sector_t sector = dm_target_offset(ti, bio->bi_iter.bi_sector);
 	sector_t tmp_sector = sector;
 
 	/* Shift us up to the right "row" on the stripe */
maintainer
#1 lore raw

Hi

The patch is OK. Please re-send it with the "Signed-off-by: Matt Whitlock <[email protected]>" line inserted - this line indicates that you have legal right to send the patch.

Mikulas

Quoted 37 lines · Matt Whitlock

The "unstriped" device-mapper target incorrectly calculates the sector offset on the mapped device when the target's origin is not zero.

Take for example this hypothetical concatenation of the members of a two-disk RAID0:

linearized: 0 2097152 unstriped 2 128 0 /dev/md/raid0 0
linearized: 2097152 2097152 unstriped 2 128 1 /dev/md/raid0 0

The intent in this example is to create a single device named /dev/mapper/linearized that comprises all of the chunks of the first disk of the RAID0 set, followed by all of the chunks of the second disk of the RAID0 set.

This fails because dm-unstripe.c's map_to_core function does its computations based on the sector number within the mapper device rather than the sector number within the target. The bug turns invisible when the target's origin is at sector zero of the mapper device, as is the common case. In the example above, however, what happens is that the first half of the mapper device gets mapped correctly to the first disk of the RAID0, but the second half of the mapper device gets mapped past the end of the RAID0 device, and accesses to any of those sectors return errors.

Here is a very simple (tested) patch that corrects the problem:

md/dm-unstripe.c renamed from md/dm-unstripe.c~ +1 -1
@@ -117,7 +117,7 @@
 static sector_t map_to_core(struct dm_target *ti, struct bio *bio)
 {
 	struct unstripe_c *uc = ti->private;
-	sector_t sector = bio->bi_iter.bi_sector;
+	sector_t sector = dm_target_offset(ti, bio->bi_iter.bi_sector);
 	sector_t tmp_sector = sector;
 
 	/* Shift us up to the right "row" on the stripe */
#2 lore raw
Quoted 3 lines · Mikulas Patocka

The patch is OK. Please re-send it with the "Signed-off-by: Matt Whitlock <[email protected]>" line inserted - this line indicates that you have legal right to send the patch.

I'll never understand the obsession with this one redundant snippet of text. It's not as though my hitting Copy+Paste on it changes anything. Did I discover this bug? Did I write this one-liner to fix it? As it happens, yes and yes, but suppose I didn't: would you then really be legally barred from fixing this bug, forever doomed to preserve the incorrect behavior in the kernel because someone who didn't have the "right" to tell you how to fix it told you how to fix it? Good grief.

--- resending ---

The "unstriped" device-mapper target incorrectly calculates the sector offset on the mapped device when the target's origin is not zero.

Take for example this hypothetical concatenation of the members of a two-disk RAID0:

linearized: 0 2097152 unstriped 2 128 0 /dev/md/raid0 0
linearized: 2097152 2097152 unstriped 2 128 1 /dev/md/raid0 0

The intent in this example is to create a single device named /dev/mapper/linearized that comprises all of the chunks of the first disk of the RAID0 set, followed by all of the chunks of the second disk of the RAID0 set.

This fails because dm-unstripe.c's map_to_core function does its computations based on the sector number within the mapper device rather than the sector number within the target. The bug turns invisible when the target's origin is at sector zero of the mapper device, as is the common case. In the example above, however, what happens is that the first half of the mapper device gets mapped correctly to the first disk of the RAID0, but the second half of the mapper device gets mapped past the end of the RAID0 device, and accesses to any of those sectors return errors.

Here is a very simple (tested) patch that corrects the problem:

md/dm-unstripe.c renamed from md/dm-unstripe.c~ +1 -1
@@ -117,7 +117,7 @@
 static sector_t map_to_core(struct dm_target *ti, struct bio *bio)
 {
 	struct unstripe_c *uc = ti->private;
-	sector_t sector = bio->bi_iter.bi_sector;
+	sector_t sector = dm_target_offset(ti, bio->bi_iter.bi_sector);
 	sector_t tmp_sector = sector;
 
 	/* Shift us up to the right "row" on the stripe */

And here are your magical 56 characters:

maintainer
#3 lore raw
Quoted 5 lines · Matt Whitlock
Quoted 3 lines · Mikulas Patocka

The patch is OK. Please re-send it with the "Signed-off-by: Matt Whitlock <[email protected]>" line inserted - this line indicates that you have legal right to send the patch.

Quoted 7 lines

I'll never understand the obsession with this one redundant snippet of text. It's not as though my hitting Copy+Paste on it changes anything. Did I discover this bug? Did I write this one-liner to fix it? As it happens, yes and yes, but suppose I didn't: would you then really be legally barred from fixing this bug, forever doomed to preserve the incorrect behavior in the kernel because someone who didn't have the "right" to tell you how to fix it told you how to fix it? Good grief.

I think that this requirement was added after the SCO lawsuit where SCO made baseless claims that Linux contains code that was copied from Unix. So, the purpose is to just have a record of who-changed-what, so that it would be easier to defend in cases like that.

Mikulas

#4 lore raw
In reply to Matt Whitlock
Quoted 6 lines · Matt Whitlock
Quoted 3 lines · Mikulas Patocka

The patch is OK. Please re-send it with the "Signed-off-by: Matt Whitlock <[email protected]>" line inserted - this line indicates that you have legal right to send the patch.

I'll never understand the obsession with this one redundant snippet of text. It's not as though my hitting Copy+Paste on it changes anything. Did I discover this bug? Did I write this one-liner to fix it? As it happens, yes and yes, but suppose I didn't: would you then really be legally barred from fixing this bug, forever doomed to preserve the incorrect behavior in the kernel because someone who didn't have the "right" to tell you how to fix it told you how to fix it? Good grief.

It seems like you are unaware of this part of history:
https://en.wikipedia.org/wiki/SCO%E2%80%93Linux_disputes

Bart.