]> Git Repo - linux.git/commitdiff
blk-throttle: check for overflow in calculate_bytes_allowed
authorKhazhismel Kumykov <[email protected]>
Fri, 20 Oct 2023 22:36:17 +0000 (15:36 -0700)
committerJens Axboe <[email protected]>
Sat, 21 Oct 2023 00:38:17 +0000 (18:38 -0600)
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: e8368b57c006 ("blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()")
Fixes: 8d6bbaada2e0 ("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]>
block/blk-throttle.c

index 38a881cf97d0b4d4f8cd6b321ead22d055c46aa7..13e4377a8b2865f527019830074e0febbd7a766e 100644 (file)
@@ -723,6 +723,12 @@ static unsigned int calculate_io_allowed(u32 iops_limit,
 
 static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
 {
+       /*
+        * Can result be wider than 64 bits?
+        * We check against 62, not 64, due to ilog2 truncation.
+        */
+       if (ilog2(bps_limit) + ilog2(jiffy_elapsed) - ilog2(HZ) > 62)
+               return U64_MAX;
        return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
 }
 
This page took 0.059213 seconds and 4 git commands to generate.