aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/futex.c
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2007-10-19 02:40:14 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-19 14:53:40 -0400
commitb488893a390edfe027bae7a46e9af8083e740668 (patch)
treec469a7f99ad01005a73011c029eb5e5d15454559 /kernel/futex.c
parent3eb07c8c8adb6f0572baba844ba2d9e501654316 (diff)
pid namespaces: changes to show virtual ids to user
This is the largest patch in the set. Make all (I hope) the places where the pid is shown to or get from user operate on the virtual pids. The idea is: - all in-kernel data structures must store either struct pid itself or the pid's global nr, obtained with pid_nr() call; - when seeking the task from kernel code with the stored id one should use find_task_by_pid() call that works with global pids; - when showing pid's numerical value to the user the virtual one should be used, but however when one shows task's pid outside this task's namespace the global one is to be used; - when getting the pid from userspace one need to consider this as the virtual one and use appropriate task/pid-searching functions. [akpm@linux-foundation.org: build fix] [akpm@linux-foundation.org: nuther build fix] [akpm@linux-foundation.org: yet nuther build fix] [akpm@linux-foundation.org: remove unneeded casts] Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: Alexey Dobriyan <adobriyan@openvz.org> Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com> Cc: Oleg Nesterov <oleg@tv-sign.ru> Cc: Paul Menage <menage@google.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/futex.c')
-rw-r--r--kernel/futex.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/kernel/futex.c b/kernel/futex.c
index e45a65e41686..86b2600381b6 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -53,6 +53,9 @@
53#include <linux/signal.h> 53#include <linux/signal.h>
54#include <linux/module.h> 54#include <linux/module.h>
55#include <linux/magic.h> 55#include <linux/magic.h>
56#include <linux/pid.h>
57#include <linux/nsproxy.h>
58
56#include <asm/futex.h> 59#include <asm/futex.h>
57 60
58#include "rtmutex_common.h" 61#include "rtmutex_common.h"
@@ -443,7 +446,8 @@ static struct task_struct * futex_find_get_task(pid_t pid)
443 struct task_struct *p; 446 struct task_struct *p;
444 447
445 rcu_read_lock(); 448 rcu_read_lock();
446 p = find_task_by_pid(pid); 449 p = find_task_by_pid_ns(pid,
450 current->nsproxy->pid_ns);
447 451
448 if (!p || ((current->euid != p->euid) && (current->euid != p->uid))) 452 if (!p || ((current->euid != p->euid) && (current->euid != p->uid)))
449 p = ERR_PTR(-ESRCH); 453 p = ERR_PTR(-ESRCH);
@@ -653,7 +657,7 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this)
653 if (!(uval & FUTEX_OWNER_DIED)) { 657 if (!(uval & FUTEX_OWNER_DIED)) {
654 int ret = 0; 658 int ret = 0;
655 659
656 newval = FUTEX_WAITERS | new_owner->pid; 660 newval = FUTEX_WAITERS | task_pid_vnr(new_owner);
657 661
658 curval = cmpxchg_futex_value_locked(uaddr, uval, newval); 662 curval = cmpxchg_futex_value_locked(uaddr, uval, newval);
659 663
@@ -1106,7 +1110,7 @@ static void unqueue_me_pi(struct futex_q *q)
1106static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, 1110static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
1107 struct task_struct *curr) 1111 struct task_struct *curr)
1108{ 1112{
1109 u32 newtid = curr->pid | FUTEX_WAITERS; 1113 u32 newtid = task_pid_vnr(curr) | FUTEX_WAITERS;
1110 struct futex_pi_state *pi_state = q->pi_state; 1114 struct futex_pi_state *pi_state = q->pi_state;
1111 u32 uval, curval, newval; 1115 u32 uval, curval, newval;
1112 int ret; 1116 int ret;
@@ -1368,7 +1372,7 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared,
1368 * (by doing a 0 -> TID atomic cmpxchg), while holding all 1372 * (by doing a 0 -> TID atomic cmpxchg), while holding all
1369 * the locks. It will most likely not succeed. 1373 * the locks. It will most likely not succeed.
1370 */ 1374 */
1371 newval = current->pid; 1375 newval = task_pid_vnr(current);
1372 1376
1373 curval = cmpxchg_futex_value_locked(uaddr, 0, newval); 1377 curval = cmpxchg_futex_value_locked(uaddr, 0, newval);
1374 1378
@@ -1379,7 +1383,7 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared,
1379 * Detect deadlocks. In case of REQUEUE_PI this is a valid 1383 * Detect deadlocks. In case of REQUEUE_PI this is a valid
1380 * situation and we return success to user space. 1384 * situation and we return success to user space.
1381 */ 1385 */
1382 if (unlikely((curval & FUTEX_TID_MASK) == current->pid)) { 1386 if (unlikely((curval & FUTEX_TID_MASK) == task_pid_vnr(current))) {
1383 ret = -EDEADLK; 1387 ret = -EDEADLK;
1384 goto out_unlock_release_sem; 1388 goto out_unlock_release_sem;
1385 } 1389 }
@@ -1408,7 +1412,7 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared,
1408 */ 1412 */
1409 if (unlikely(ownerdied || !(curval & FUTEX_TID_MASK))) { 1413 if (unlikely(ownerdied || !(curval & FUTEX_TID_MASK))) {
1410 /* Keep the OWNER_DIED bit */ 1414 /* Keep the OWNER_DIED bit */
1411 newval = (curval & ~FUTEX_TID_MASK) | current->pid; 1415 newval = (curval & ~FUTEX_TID_MASK) | task_pid_vnr(current);
1412 ownerdied = 0; 1416 ownerdied = 0;
1413 lock_taken = 1; 1417 lock_taken = 1;
1414 } 1418 }
@@ -1587,7 +1591,7 @@ retry:
1587 /* 1591 /*
1588 * We release only a lock we actually own: 1592 * We release only a lock we actually own:
1589 */ 1593 */
1590 if ((uval & FUTEX_TID_MASK) != current->pid) 1594 if ((uval & FUTEX_TID_MASK) != task_pid_vnr(current))
1591 return -EPERM; 1595 return -EPERM;
1592 /* 1596 /*
1593 * First take all the futex related locks: 1597 * First take all the futex related locks:
@@ -1608,7 +1612,7 @@ retry_unlocked:
1608 * anyone else up: 1612 * anyone else up:
1609 */ 1613 */
1610 if (!(uval & FUTEX_OWNER_DIED)) 1614 if (!(uval & FUTEX_OWNER_DIED))
1611 uval = cmpxchg_futex_value_locked(uaddr, current->pid, 0); 1615 uval = cmpxchg_futex_value_locked(uaddr, task_pid_vnr(current), 0);
1612 1616
1613 1617
1614 if (unlikely(uval == -EFAULT)) 1618 if (unlikely(uval == -EFAULT))
@@ -1617,7 +1621,7 @@ retry_unlocked:
1617 * Rare case: we managed to release the lock atomically, 1621 * Rare case: we managed to release the lock atomically,
1618 * no need to wake anyone else up: 1622 * no need to wake anyone else up:
1619 */ 1623 */
1620 if (unlikely(uval == current->pid)) 1624 if (unlikely(uval == task_pid_vnr(current)))
1621 goto out_unlock; 1625 goto out_unlock;
1622 1626
1623 /* 1627 /*
@@ -1854,7 +1858,8 @@ sys_get_robust_list(int pid, struct robust_list_head __user * __user *head_ptr,
1854 1858
1855 ret = -ESRCH; 1859 ret = -ESRCH;
1856 rcu_read_lock(); 1860 rcu_read_lock();
1857 p = find_task_by_pid(pid); 1861 p = find_task_by_pid_ns(pid,
1862 current->nsproxy->pid_ns);
1858 if (!p) 1863 if (!p)
1859 goto err_unlock; 1864 goto err_unlock;
1860 ret = -EPERM; 1865 ret = -EPERM;
@@ -1887,7 +1892,7 @@ retry:
1887 if (get_user(uval, uaddr)) 1892 if (get_user(uval, uaddr))
1888 return -1; 1893 return -1;
1889 1894
1890 if ((uval & FUTEX_TID_MASK) == curr->pid) { 1895 if ((uval & FUTEX_TID_MASK) == task_pid_vnr(curr)) {
1891 /* 1896 /*
1892 * Ok, this dying thread is truly holding a futex 1897 * Ok, this dying thread is truly holding a futex
1893 * of interest. Set the OWNER_DIED bit atomically 1898 * of interest. Set the OWNER_DIED bit atomically