]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blobdiff - kernel/sched.c
[PATCH] sched_setscheduler: fix? policy checks
[mirror_ubuntu-kernels.git] / kernel / sched.c
index c3c718aea618c505247631ccde8ccd1c0c31d3b0..155a33da7aa76ca733977c9b934042551ca2e7f0 100644 (file)
@@ -4116,27 +4116,25 @@ recheck:
         * Allow unprivileged RT tasks to decrease priority:
         */
        if (!capable(CAP_SYS_NICE)) {
-               unsigned long rlim_rtprio;
-               unsigned long flags;
-
-               if (!lock_task_sighand(p, &flags))
-                       return -ESRCH;
-               rlim_rtprio = p->signal->rlim[RLIMIT_RTPRIO].rlim_cur;
-               unlock_task_sighand(p, &flags);
+               if (is_rt_policy(policy)) {
+                       unsigned long rlim_rtprio;
+                       unsigned long flags;
+
+                       if (!lock_task_sighand(p, &flags))
+                               return -ESRCH;
+                       rlim_rtprio = p->signal->rlim[RLIMIT_RTPRIO].rlim_cur;
+                       unlock_task_sighand(p, &flags);
+
+                       /* can't set/change the rt policy */
+                       if (policy != p->policy && !rlim_rtprio)
+                               return -EPERM;
+
+                       /* can't increase priority */
+                       if (param->sched_priority > p->rt_priority &&
+                           param->sched_priority > rlim_rtprio)
+                               return -EPERM;
+               }
 
-               /*
-                * can't change policy, except between SCHED_NORMAL
-                * and SCHED_BATCH:
-                */
-               if (((policy != SCHED_NORMAL && p->policy != SCHED_BATCH) &&
-                       (policy != SCHED_BATCH && p->policy != SCHED_NORMAL)) &&
-                               !rlim_rtprio)
-                       return -EPERM;
-               /* can't increase priority */
-               if (is_rt_policy(policy) &&
-                   param->sched_priority > p->rt_priority &&
-                   param->sched_priority > rlim_rtprio)
-                       return -EPERM;
                /* can't change other user's priorities */
                if ((current->euid != p->euid) &&
                    (current->euid != p->uid))