Re: [PATCH] Changing RT priority in kernel 2.6 without CAP_SYS_NICE

From: Ingo Molnar (mingo_at_elte.hu)
Date: 04/18/05

  • Next message: Catalin Marinas: "Re: New SCM and commit list"
    Date:	Mon, 18 Apr 2005 10:07:50 +0200
    To: Olivier Croquette <ocroquette@free.fr>
    
    

    looks fine to me, only minor nits:

    - this area of code changed since 2.6.8 so it needed merging.

    - whitespace damage: your patch had all tabs as spaces.

    - whitespace style: stuff like "if(" should be "if (".

    i've reworked and tested the patch (attached below) to apply against the
    latest scheduler queue in -mm.

            Ingo

    --
    From: Olivier Croquette <ocroquette@free.fr>
    Presently, a process without the capability CAP_SYS_NICE can not change 
    its own policy, which is OK.
    But it can also not decrease its RT priority (if scheduled with policy 
    SCHED_RR or SCHED_FIFO), which is what this patch changes.
    The rationale is the same as for the nice value: a process should be 
    able to require less priority for itself. Increasing the priority is 
    still not allowed.
    This is for example useful if you give a multithreaded user process a RT 
    priority, and the process would like to organize its internal threads 
    using priorities also. Then you can give the process the highest 
    priority needed N, and the process starts its threads with lower 
    priorities: N-1, N-2...
    The POSIX norm says that the permissions are implementation specific, so 
    I think we can do that.
    In a sense, it makes the permissions consistent whatever the policy is: 
    with this patch, process scheduled by SCHED_FIFO, SCHED_RR and 
    SCHED_OTHER can all decrease their priority.
    From: Ingo Molnar <mingo@elte.hu>
    cleaned up and merged to -mm.
    Signed-off-by: Ingo Molnar <mingo@elte.hu>
    --- kernel/sched.c.orig
    +++ kernel/sched.c
    @@ -3436,12 +3436,22 @@ recheck:
     	if ((policy == SCHED_NORMAL) != (param->sched_priority == 0))
     		return -EINVAL;
     
    -	if ((policy == SCHED_FIFO || policy == SCHED_RR) &&
    -	    !capable(CAP_SYS_NICE))
    -		return -EPERM;
    -	if ((current->euid != p->euid) && (current->euid != p->uid) &&
    -	    !capable(CAP_SYS_NICE))
    -		return -EPERM;
    +	/*
    +	 * Allow unprivileged RT tasks to decrease priority:
    +	 */
    +	if (!capable(CAP_SYS_NICE)) {
    +		/* can't change policy */
    +		if (policy != p->policy)
    +			return -EPERM;
    +		/* can't increase priority */
    +		if (policy != SCHED_NORMAL &&
    +		    param->sched_priority > p->rt_priority)
    +			return -EPERM;
    +		/* can't change other user's priorities */
    +		if ((current->euid != p->euid) &&
    +		    (current->euid != p->uid))
    +			return -EPERM;
    +	}
     
     	retval = security_task_setscheduler(p, policy, param);
     	if (retval)
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: Catalin Marinas: "Re: New SCM and commit list"

    Relevant Pages

    • [RFC PATCH -rt] RCU priority boosting that survives mild testing
      ... This patch allows transitive boosting (e.g., ... boosting its priority for the duration of the ... level of recursion in face of nested preemptions (e.g., ...
      (Linux-Kernel)
    • Format string bug in awhttpd (Re: [AP] awhttpd v2.2 local DoS)
      ... While testing a buffer overflow in you patch (tpbuf is only 210 bytes, ... classical exploitable syslogformat string in this extremely secure ... Priority is 1-4, with 1 being the highest priority. ...
      (Bugtraq)
    • [RFC][PATCH 0/2] Swap token re-tuned
      ... PATCH 1: ... The idea is to guarantee that a high priority process gets the token. ... This way, its a matter of simple comparison of task priorities, to ... sys 0m0.940s ...
      (Linux-Kernel)
    • Re: NPTL mutex and the scheduling priority
      ... another one is to keep the queue sorted by priority (and adjust whenever ... priority changes - one thread can be waiting on at most one futex at a ... I'll look at the plist patch. ... With the plist patch, I can get desired behavior. ...
      (Linux-Kernel)
    • [PATCH] Changing RT priority in kernel 2.6 without CAP_SYS_NICE
      ... Here is a patch on the permission scheme when changing RT priorities. ... But it can also not decrease its RT priority (if scheduled with policy ... The POSIX norm says that the permissions are implementation specific, ...
      (Linux-Kernel)