Skip to content

Commit 2d93540

Browse files
SevenQCrafaeljw
authored andcommitted
powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue
When value < time_unit, the parameter of ilog2() will be zero and the return value is -1. u64(-1) is too large for shift exponent and then will trigger shift-out-of-bounds: shift exponent 18446744073709551615 is too large for 32-bit type 'int' Call Trace: rapl_compute_time_window_core rapl_write_data_raw set_time_window store_constraint_time_window_us Signed-off-by: Chao Qin <[email protected]> Acked-by: Zhang Rui <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 0d7a23b commit 2d93540

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/powercap/intel_rapl_common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,9 @@ static u64 rapl_compute_time_window_core(struct rapl_package *rp, u64 value,
994994
y = value & 0x1f;
995995
value = (1 << y) * (4 + f) * rp->time_unit / 4;
996996
} else {
997+
if (value < rp->time_unit)
998+
return 0;
999+
9971000
do_div(value, rp->time_unit);
9981001
y = ilog2(value);
9991002
f = div64_u64(4 * (value - (1 << y)), 1 << y);

0 commit comments

Comments
 (0)