Skip to content

Commit 274295c

Browse files
committed
Merge tag 'for-5.19/dm-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mike Snitzer: - Fix a race in DM core's dm_start_io_acct that could result in double accounting for abnormal IO (e.g. discards, write zeroes, etc). - Fix a use-after-free in DM core's dm_put_live_table_bio. - Fix a race for REQ_NOWAIT bios being issued despite no support from underlying DM targets (due to DM table reload at an "unlucky" time) - Fix access beyond allocated bitmap in DM mirror's log. * tag 'for-5.19/dm-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm mirror log: round up region bitmap size to BITS_PER_LONG dm: fix narrow race for REQ_NOWAIT bios being issued despite no support dm: fix use-after-free in dm_put_live_table_bio dm: fix race in dm_start_io_acct
2 parents a96e902 + 85e123c commit 274295c

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

drivers/md/dm-log.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
415415
/*
416416
* Work out how many "unsigned long"s we need to hold the bitset.
417417
*/
418-
bitset_size = dm_round_up(region_count,
419-
sizeof(*lc->clean_bits) << BYTE_SHIFT);
418+
bitset_size = dm_round_up(region_count, BITS_PER_LONG);
420419
bitset_size >>= BYTE_SHIFT;
421420

422421
lc->bitset_uint32_count = bitset_size / sizeof(*lc->clean_bits);

drivers/md/dm.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ static void dm_start_io_acct(struct dm_io *io, struct bio *clone)
555555
unsigned long flags;
556556
/* Can afford locking given DM_TIO_IS_DUPLICATE_BIO */
557557
spin_lock_irqsave(&io->lock, flags);
558+
if (dm_io_flagged(io, DM_IO_ACCOUNTED)) {
559+
spin_unlock_irqrestore(&io->lock, flags);
560+
return;
561+
}
558562
dm_io_set_flag(io, DM_IO_ACCOUNTED);
559563
spin_unlock_irqrestore(&io->lock, flags);
560564
}
@@ -711,18 +715,18 @@ static void dm_put_live_table_fast(struct mapped_device *md) __releases(RCU)
711715
}
712716

713717
static inline struct dm_table *dm_get_live_table_bio(struct mapped_device *md,
714-
int *srcu_idx, struct bio *bio)
718+
int *srcu_idx, unsigned bio_opf)
715719
{
716-
if (bio->bi_opf & REQ_NOWAIT)
720+
if (bio_opf & REQ_NOWAIT)
717721
return dm_get_live_table_fast(md);
718722
else
719723
return dm_get_live_table(md, srcu_idx);
720724
}
721725

722726
static inline void dm_put_live_table_bio(struct mapped_device *md, int srcu_idx,
723-
struct bio *bio)
727+
unsigned bio_opf)
724728
{
725-
if (bio->bi_opf & REQ_NOWAIT)
729+
if (bio_opf & REQ_NOWAIT)
726730
dm_put_live_table_fast(md);
727731
else
728732
dm_put_live_table(md, srcu_idx);
@@ -1609,7 +1613,12 @@ static blk_status_t __split_and_process_bio(struct clone_info *ci)
16091613
ti = dm_table_find_target(ci->map, ci->sector);
16101614
if (unlikely(!ti))
16111615
return BLK_STS_IOERR;
1612-
else if (unlikely(ci->is_abnormal_io))
1616+
1617+
if (unlikely((ci->bio->bi_opf & REQ_NOWAIT) != 0) &&
1618+
unlikely(!dm_target_supports_nowait(ti->type)))
1619+
return BLK_STS_NOTSUPP;
1620+
1621+
if (unlikely(ci->is_abnormal_io))
16131622
return __process_abnormal_io(ci, ti);
16141623

16151624
/*
@@ -1711,8 +1720,9 @@ static void dm_submit_bio(struct bio *bio)
17111720
struct mapped_device *md = bio->bi_bdev->bd_disk->private_data;
17121721
int srcu_idx;
17131722
struct dm_table *map;
1723+
unsigned bio_opf = bio->bi_opf;
17141724

1715-
map = dm_get_live_table_bio(md, &srcu_idx, bio);
1725+
map = dm_get_live_table_bio(md, &srcu_idx, bio_opf);
17161726

17171727
/* If suspended, or map not yet available, queue this IO for later */
17181728
if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) ||
@@ -1728,7 +1738,7 @@ static void dm_submit_bio(struct bio *bio)
17281738

17291739
dm_split_and_process_bio(md, map, bio);
17301740
out:
1731-
dm_put_live_table_bio(md, srcu_idx, bio);
1741+
dm_put_live_table_bio(md, srcu_idx, bio_opf);
17321742
}
17331743

17341744
static bool dm_poll_dm_io(struct dm_io *io, struct io_comp_batch *iob,

0 commit comments

Comments
 (0)