Commit 8dc3e909 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

[PATCH] sched_setscheduler: fix? policy checks

I am not sure this patch is correct: I can't understand what the current
code does, and I don't know what it was supposed to do.

The comment says:

		 * can't change policy, except between SCHED_NORMAL
		 * and SCHED_BATCH:

The code:

		if (((policy != SCHED_NORMAL && p->policy != SCHED_BATCH) &&
			(policy != SCHED_BATCH && p->policy != SCHED_NORMAL)) &&

But this is equivalent to:

		if ( (is_rt_policy(policy) && has_rt_policy(p)) &&

which means something different.  We can't _decrease_ the current
->rt_priority with such a check (if rlim[RLIMIT_RTPRIO] == 0).

Probably, it was supposed to be:

		if (	!(policy == SCHED_NORMAL && p->policy == SCHED_BATCH)  &&
			!(policy == SCHED_BATCH  && p->policy == SCHED_NORMAL)

this matches the comment, but strange: it doesn't allow to _drop_ the
realtime priority when rlim[RLIMIT_RTPRIO] == 0.

I think the right check would be:

		/* can't set/change rt policy */
		if (is_rt_policy(policy) &&
				policy != p->policy &&
				!rlim_rtprio)
			return -EPERM;
Signed-off-by: default avatarOleg Nesterov <oleg@tv-sign.ru>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 57a6f51c
...@@ -4116,6 +4116,7 @@ recheck: ...@@ -4116,6 +4116,7 @@ recheck:
* Allow unprivileged RT tasks to decrease priority: * Allow unprivileged RT tasks to decrease priority:
*/ */
if (!capable(CAP_SYS_NICE)) { if (!capable(CAP_SYS_NICE)) {
if (is_rt_policy(policy)) {
unsigned long rlim_rtprio; unsigned long rlim_rtprio;
unsigned long flags; unsigned long flags;
...@@ -4124,19 +4125,16 @@ recheck: ...@@ -4124,19 +4125,16 @@ recheck:
rlim_rtprio = p->signal->rlim[RLIMIT_RTPRIO].rlim_cur; rlim_rtprio = p->signal->rlim[RLIMIT_RTPRIO].rlim_cur;
unlock_task_sighand(p, &flags); unlock_task_sighand(p, &flags);
/* /* can't set/change the rt policy */
* can't change policy, except between SCHED_NORMAL if (policy != p->policy && !rlim_rtprio)
* and SCHED_BATCH:
*/
if (((policy != SCHED_NORMAL && p->policy != SCHED_BATCH) &&
(policy != SCHED_BATCH && p->policy != SCHED_NORMAL)) &&
!rlim_rtprio)
return -EPERM; return -EPERM;
/* can't increase priority */ /* can't increase priority */
if (is_rt_policy(policy) && if (param->sched_priority > p->rt_priority &&
param->sched_priority > p->rt_priority &&
param->sched_priority > rlim_rtprio) param->sched_priority > rlim_rtprio)
return -EPERM; return -EPERM;
}
/* can't change other user's priorities */ /* can't change other user's priorities */
if ((current->euid != p->euid) && if ((current->euid != p->euid) &&
(current->euid != p->uid)) (current->euid != p->uid))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment