Skip to content

Commit b562d14

Browse files
Qais YousefIngo Molnar
authored andcommitted
sched/uclamp: Reject negative values in cpu_uclamp_write()
The check to ensure that the new written value into cpu.uclamp.{min,max} is within range, [0:100], wasn't working because of the signed comparison 7301 if (req.percent > UCLAMP_PERCENT_SCALE) { 7302 req.ret = -ERANGE; 7303 return req; 7304 } # echo -1 > cpu.uclamp.min # cat cpu.uclamp.min 42949671.96 Cast req.percent into u64 to force the comparison to be unsigned and work as intended in capacity_from_percent(). # echo -1 > cpu.uclamp.min sh: write error: Numerical result out of range Fixes: 2480c09 ("sched/uclamp: Extend CPU's cgroup controller") Signed-off-by: Qais Yousef <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b396f52 commit b562d14

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/sched/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7264,7 +7264,7 @@ capacity_from_percent(char *buf)
72647264
&req.percent);
72657265
if (req.ret)
72667266
return req;
7267-
if (req.percent > UCLAMP_PERCENT_SCALE) {
7267+
if ((u64)req.percent > UCLAMP_PERCENT_SCALE) {
72687268
req.ret = -ERANGE;
72697269
return req;
72707270
}

0 commit comments

Comments
 (0)