Skip to content

Commit 2dd710d

Browse files
khazhykaxboe
authored andcommitted
blk-throttle: check for overflow in calculate_bytes_allowed
Inexact, we may reject some not-overflowing values incorrectly, but they'll be on the order of exabytes allowed anyways. This fixes divide error crash on x86 if bps_limit is not configured or is set too high in the rare case that jiffy_elapsed is greater than HZ. Fixes: e8368b5 ("blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()") Fixes: 8d6bbaa ("blk-throttle: prevent overflow while calculating wait time") Signed-off-by: Khazhismel Kumykov <[email protected]> Acked-by: Tejun Heo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent c341455 commit 2dd710d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

block/blk-throttle.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,12 @@ static unsigned int calculate_io_allowed(u32 iops_limit,
723723

724724
static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
725725
{
726+
/*
727+
* Can result be wider than 64 bits?
728+
* We check against 62, not 64, due to ilog2 truncation.
729+
*/
730+
if (ilog2(bps_limit) + ilog2(jiffy_elapsed) - ilog2(HZ) > 62)
731+
return U64_MAX;
726732
return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
727733
}
728734

0 commit comments

Comments
 (0)