Skip to content

Commit 9319b64

Browse files
zokeefeakpm00
authored andcommitted
mm/writeback: fix possible divide-by-zero in wb_dirty_limits(), again
(struct dirty_throttle_control *)->thresh is an unsigned long, but is passed as the u32 divisor argument to div_u64(). On architectures where unsigned long is 64 bytes, the argument will be implicitly truncated. Use div64_u64() instead of div_u64() so that the value used in the "is this a safe division" check is the same as the divisor. Also, remove redundant cast of the numerator to u64, as that should happen implicitly. This would be difficult to exploit in memcg domain, given the ratio-based arithmetic domain_drity_limits() uses, but is much easier in global writeback domain with a BDI_CAP_STRICTLIMIT-backing device, using e.g. vm.dirty_bytes=(1<<32)*PAGE_SIZE so that dtc->thresh == (1<<32) Link: https://lkml.kernel.org/r/[email protected] Fixes: f678959 ("mm/page-writeback.c: fix divide by zero in bdi_dirty_limits()") Signed-off-by: Zach O'Keefe <[email protected]> Cc: Maxim Patlasov <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent bc29036 commit 9319b64

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/page-writeback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ static inline void wb_dirty_limits(struct dirty_throttle_control *dtc)
16381638
*/
16391639
dtc->wb_thresh = __wb_calc_thresh(dtc);
16401640
dtc->wb_bg_thresh = dtc->thresh ?
1641-
div_u64((u64)dtc->wb_thresh * dtc->bg_thresh, dtc->thresh) : 0;
1641+
div64_u64(dtc->wb_thresh * dtc->bg_thresh, dtc->thresh) : 0;
16421642

16431643
/*
16441644
* In order to avoid the stacked BDI deadlock we need

0 commit comments

Comments
 (0)