sched: Fix __sched_setscheduler() nice test
authorPeter Zijlstra <peterz@infradead.org>
Thu, 16 Jan 2014 16:54:25 +0000 (17:54 +0100)
committerIngo Molnar <mingo@kernel.org>
Thu, 16 Jan 2014 17:07:08 +0000 (18:07 +0100)
With the introduction of sched_attr::sched_nice we need to check
if we've got permission to actually change the nice value.

Daniel found that can_nice() would always fail; and upon
inspection it turns out that can_nice() only tests to see if we
can lower the nice value, but it doesn't validate if we're
lowering or not.

Therefore amend the test to only call can_nice() when we lower
the nice value.

Reported-and-Tested-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: raistlin@linux.it
Cc: juri.lelli@gmail.com
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Fixes: d50dde5a10f3 ("sched: Add new scheduler syscalls to support an extended scheduling parameters ABI")
Link: http://lkml.kernel.org/r/20140116165425.GA9481@laptop.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/sched/core.c

index 93a2836b62205d6264c3271d5521264870ca5f5e..36c951b7eef87d88056b484814c379245d39c1fb 100644 (file)
@@ -3296,7 +3296,8 @@ recheck:
         */
        if (user && !capable(CAP_SYS_NICE)) {
                if (fair_policy(policy)) {
-                       if (!can_nice(p, attr->sched_nice))
+                       if (attr->sched_nice < TASK_NICE(p) &&
+                           !can_nice(p, attr->sched_nice))
                                return -EPERM;
                }