Skip to content

Commit 1071d56

Browse files
author
Mikulas Patocka
committed
dm-stripe: fix a possible integer overflow
There's a possible integer overflow in stripe_io_hints if we have too large chunk size. Test if the overflow happened, and if it did, don't set limits->io_min and limits->io_opt; Signed-off-by: Mikulas Patocka <[email protected]> Reviewed-by: John Garry <[email protected]> Suggested-by: Dongsheng Yang <[email protected]> Cc: [email protected]
1 parent 8f5ae30 commit 1071d56

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/md/dm-stripe.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,15 @@ static void stripe_io_hints(struct dm_target *ti,
456456
struct queue_limits *limits)
457457
{
458458
struct stripe_c *sc = ti->private;
459-
unsigned int chunk_size = sc->chunk_size << SECTOR_SHIFT;
459+
unsigned int io_min, io_opt;
460460

461461
limits->chunk_sectors = sc->chunk_size;
462-
limits->io_min = chunk_size;
463-
limits->io_opt = chunk_size * sc->stripes;
462+
463+
if (!check_shl_overflow(sc->chunk_size, SECTOR_SHIFT, &io_min) &&
464+
!check_mul_overflow(io_min, sc->stripes, &io_opt)) {
465+
limits->io_min = io_min;
466+
limits->io_opt = io_opt;
467+
}
464468
}
465469

466470
static struct target_type stripe_target = {

0 commit comments

Comments
 (0)