Skip to content

Commit f7b58a6

Browse files
author
Mike Snitzer
committed
dm: fix improper splitting for abnormal bios
"Abnormal" bios include discards, write zeroes and secure erase. By no longer passing the calculated 'len' pointer, commit 7dd06a2 ("dm: allow dm_accept_partial_bio() for dm_io without duplicate bios") took a senseless approach to disallowing dm_accept_partial_bio() from working for duplicate bios processed using __send_duplicate_bios(). It inadvertently and incorrectly stopped the use of 'len' when initializing a target's io (in alloc_tio). As such the resulting tio could address more area of a device than it should. For example, when discarding an entire DM striped device with the following DM table: vg-lvol0: 0 159744 striped 2 128 7:0 2048 7:1 2048 vg-lvol0: 159744 45056 striped 2 128 7:2 2048 7:3 2048 Before this fix: device-mapper: striped: target_stripe=0, bdev=7:0, start=2048 len=102400 blkdiscard: attempt to access beyond end of device loop0: rw=2051, sector=2048, nr_sectors = 102400 limit=81920 device-mapper: striped: target_stripe=1, bdev=7:1, start=2048 len=102400 blkdiscard: attempt to access beyond end of device loop1: rw=2051, sector=2048, nr_sectors = 102400 limit=81920 After this fix; device-mapper: striped: target_stripe=0, bdev=7:0, start=2048 len=79872 device-mapper: striped: target_stripe=1, bdev=7:1, start=2048 len=79872 Fixes: 7dd06a2 ("dm: allow dm_accept_partial_bio() for dm_io without duplicate bios") Cc: [email protected] Reported-by: Orange Kao <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 197b6b6 commit f7b58a6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/md/dm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,8 @@ static void setup_split_accounting(struct clone_info *ci, unsigned int len)
14671467
}
14681468

14691469
static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci,
1470-
struct dm_target *ti, unsigned int num_bios)
1470+
struct dm_target *ti, unsigned int num_bios,
1471+
unsigned *len)
14711472
{
14721473
struct bio *bio;
14731474
int try;
@@ -1478,7 +1479,7 @@ static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci,
14781479
if (try)
14791480
mutex_lock(&ci->io->md->table_devices_lock);
14801481
for (bio_nr = 0; bio_nr < num_bios; bio_nr++) {
1481-
bio = alloc_tio(ci, ti, bio_nr, NULL,
1482+
bio = alloc_tio(ci, ti, bio_nr, len,
14821483
try ? GFP_NOIO : GFP_NOWAIT);
14831484
if (!bio)
14841485
break;
@@ -1514,7 +1515,7 @@ static int __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti,
15141515
break;
15151516
default:
15161517
/* dm_accept_partial_bio() is not supported with shared tio->len_ptr */
1517-
alloc_multiple_bios(&blist, ci, ti, num_bios);
1518+
alloc_multiple_bios(&blist, ci, ti, num_bios, len);
15181519
while ((clone = bio_list_pop(&blist))) {
15191520
dm_tio_set_flag(clone_to_tio(clone), DM_TIO_IS_DUPLICATE_BIO);
15201521
__map_bio(clone);

0 commit comments

Comments
 (0)