Skip to contentSkip to conversation

sched/uclamp: reject negative values in cpu_uclamp_write

PATCH Superseded Qais Yousef 2 participants 3 messages Jan 12, 2020 – Jan 29, 2020 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 }

Cast req.percent into u64 to force the comparison to be unsigned and work as intended in capacity_from_percent().

Fixes 2480c093130f ("sched/uclamp: Extend CPU's cgroup controller")
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index 90e4b00ace89..e66b131e3aeb 100644
@@ -7254,7 +7254,7 @@ capacity_from_percent(char *buf)
 					     &req.percent);
 		if (req.ret)
 			return req;
-		if (req.percent > UCLAMP_PERCENT_SCALE) {
+		if ((u64)req.percent > UCLAMP_PERCENT_SCALE) {
 			req.ret = -ERANGE;
 			return req;
 		}
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/1 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 2480c093130f ("sched/uclamp: Extend CPU's cgroup controller")

---

Changes in v2:
- Improve the commit message as suggested by T. Zhou

 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index 90e4b00ace89..e66b131e3aeb 100644
@@ -7254,7 +7254,7 @@ capacity_from_percent(char *buf)
 					     &req.percent);
 		if (req.ret)
 			return req;
-		if (req.percent > UCLAMP_PERCENT_SCALE) {
+		if ((u64)req.percent > UCLAMP_PERCENT_SCALE) {
 			req.ret = -ERANGE;
 			return req;
 		}
Signature · 1 line
2.17.1
merge bot Applied
#2 lore raw

[tip: sched/core] sched/uclamp: Reject negative values in cpu_uclamp_write()

The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     b562d140649966d4daedd0483a8fe59ad3bb465a
Gitweb:        https://git.kernel.org/tip/b562d140649966d4daedd0483a8fe59ad3bb465a
Author:        Qais Yousef <[email protected]>
AuthorDate:    Tue, 14 Jan 2020 21:09:47 
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Tue, 28 Jan 2020 21:36:56 +01:00

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 2480c093130f ("sched/uclamp: Extend CPU's cgroup controller")
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index 4ff03c2..55b9a9c 100644
@@ -7264,7 +7264,7 @@ capacity_from_percent(char *buf)
 					     &req.percent);
 		if (req.ret)
 			return req;
-		if (req.percent > UCLAMP_PERCENT_SCALE) {
+		if ((u64)req.percent > UCLAMP_PERCENT_SCALE) {
 			req.ret = -ERANGE;
 			return req;
 		}