Skip to content

Commit

Permalink
timekeeping: Prevent 32bit truncation in scale64_check_overflow()
Browse files Browse the repository at this point in the history
[ Upstream commit 4cbbc3a ]

While unlikely the divisor in scale64_check_overflow() could be >= 32bit in
scale64_check_overflow(). do_div() truncates the divisor to 32bit at least
on 32bit platforms.

Use div64_u64() instead to avoid the truncation to 32-bit.

[ tglx: Massaged changelog ]

Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200120100523.45656-1-wenyang@linux.alibaba.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
taskset authored and gregkh committed Oct 1, 2020
1 parent e500a98 commit 61f27ba
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions kernel/time/timekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,8 @@ static int scale64_check_overflow(u64 mult, u64 div, u64 *base)
((int)sizeof(u64)*8 - fls64(mult) < fls64(rem)))
return -EOVERFLOW;
tmp *= mult;
rem *= mult;

do_div(rem, div);
rem = div64_u64(rem * mult, div);
*base = tmp + rem;
return 0;
}
Expand Down

0 comments on commit 61f27ba

Please sign in to comment.