Skip to content

Commit 7030661

Browse files
gormanmPeter Zijlstra
authored andcommitted
sched/fair: Null terminate buffer when updating tunable_scaling
This patch null-terminates the temporary buffer in sched_scaling_write() so kstrtouint() does not return failure and checks the value is valid. Before: $ cat /sys/kernel/debug/sched/tunable_scaling 1 $ echo 0 > /sys/kernel/debug/sched/tunable_scaling -bash: echo: write error: Invalid argument $ cat /sys/kernel/debug/sched/tunable_scaling 1 After: $ cat /sys/kernel/debug/sched/tunable_scaling 1 $ echo 0 > /sys/kernel/debug/sched/tunable_scaling $ cat /sys/kernel/debug/sched/tunable_scaling 0 $ echo 3 > /sys/kernel/debug/sched/tunable_scaling -bash: echo: write error: Invalid argument Fixes: 8a99b68 ("sched: Move SCHED_DEBUG sysctl to debugfs") Signed-off-by: Mel Gorman <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Vincent Guittot <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2630cde commit 7030661

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kernel/sched/debug.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,22 @@ static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf,
173173
size_t cnt, loff_t *ppos)
174174
{
175175
char buf[16];
176+
unsigned int scaling;
176177

177178
if (cnt > 15)
178179
cnt = 15;
179180

180181
if (copy_from_user(&buf, ubuf, cnt))
181182
return -EFAULT;
183+
buf[cnt] = '\0';
182184

183-
if (kstrtouint(buf, 10, &sysctl_sched_tunable_scaling))
185+
if (kstrtouint(buf, 10, &scaling))
184186
return -EINVAL;
185187

188+
if (scaling >= SCHED_TUNABLESCALING_END)
189+
return -EINVAL;
190+
191+
sysctl_sched_tunable_scaling = scaling;
186192
if (sched_update_scaling())
187193
return -EINVAL;
188194

0 commit comments

Comments
 (0)