[patch 1/9] sys: Fix missing rcu protection for __task_cred() access

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Thomas Gleixner
Date: Wednesday, December 9, 2009 - 5:52 pm

commit c69e8d9 (CRED: Use RCU to access another task's creds and to
release a task's own creds) added non rcu_read_lock() protected access
to task creds of the target task in set_prio_one().

The comment above the function says:
 * - the caller must hold the RCU read lock

The calling code in sys_setpriority does read_lock(&tasklist_lock) but
not rcu_read_lock(). This works only when CONFIG_TREE_PREEMPT_RCU=n.
With CONFIG_TREE_PREEMPT_RCU=y the rcu_callbacks can run in the tick
interrupt when they see no read side critical section.

There is another instance of __task_cred() in sys_setpriority() itself
which is equally unprotected.

Wrap the whole code section into a rcu read side critical section to
fix this quick and dirty.

Will be revisited in course of the read_lock(&tasklist_lock) -> rcu
crusade.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: David Howells <dhowells@redhat.com>
Cc: James Morris <jmorris@namei.org>
Cc: linux-security-module@vger.kernel.org
---
 kernel/sys.c |    2 ++
 1 file changed, 2 insertions(+)

Index: linux-2.6-tip/kernel/sys.c
===================================================================
--- linux-2.6-tip.orig/kernel/sys.c
+++ linux-2.6-tip/kernel/sys.c
@@ -163,6 +163,7 @@ SYSCALL_DEFINE3(setpriority, int, which,
 	if (niceval > 19)
 		niceval = 19;
 
+	rcu_read_lock();
 	read_lock(&tasklist_lock);
 	switch (which) {
 		case PRIO_PROCESS:
@@ -200,6 +201,7 @@ SYSCALL_DEFINE3(setpriority, int, which,
 	}
 out_unlock:
 	read_unlock(&tasklist_lock);
+	rcu_read_unlock();
 out:
 	return error;
 }


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 1/9] sys: Fix missing rcu protection for __task_cre ..., Thomas Gleixner, (Wed Dec 9, 5:52 pm)
[tip:core/urgent] sys: Fix missing rcu protection for __ta ..., tip-bot for Thomas G ..., (Thu Dec 10, 3:09 pm)
[PATCH] Update comment on find_task_by_pid_ns, Tetsuo Handa, (Mon Feb 8, 5:30 am)
Re: [PATCH] Update comment on find_task_by_pid_ns, Oleg Nesterov, (Mon Feb 8, 6:21 am)
Re: [PATCH] Update comment on find_task_by_pid_ns, Thomas Gleixner, (Mon Feb 8, 10:07 am)
Re: [PATCH] Update comment on find_task_by_pid_ns, Oleg Nesterov, (Mon Feb 8, 10:16 am)
Re: [PATCH] Update comment on find_task_by_pid_ns, Tetsuo Handa, (Mon Feb 8, 2:42 pm)
Re: [PATCH] Update comment on find_task_by_pid_ns, Andrew Morton, (Tue Feb 9, 3:08 pm)
Re: [PATCH] Update comment on find_task_by_pid_ns, Serge E. Hallyn, (Wed Feb 10, 9:30 am)
Re: [PATCH] Update comment on find_task_by_pid_ns, Andrew Morton, (Wed Feb 10, 10:57 am)
Re: [PATCH] Update comment on find_task_by_pid_ns, Thomas Gleixner, (Wed Feb 10, 11:39 am)
Re: [PATCH] Update comment on find_task_by_pid_ns, Serge E. Hallyn, (Wed Feb 10, 1:18 pm)
Re: [PATCH] Update comment on find_task_by_pid_ns, Paul E. McKenney, (Wed Feb 10, 1:30 pm)
Re: [PATCH] Update comment on find_task_by_pid_ns, Tetsuo Handa, (Wed Feb 10, 6:21 pm)