aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
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
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')
-rw-r--r--kernel/capability.c14
-rw-r--r--kernel/exit.c31
-rw-r--r--kernel/fork.c2
-rw-r--r--kernel/futex.c27
-rw-r--r--kernel/futex_compat.c4
-rw-r--r--kernel/ptrace.c4
-rw-r--r--kernel/sched.c6
-rw-r--r--kernel/signal.c52
-rw-r--r--kernel/sys.c54
-rw-r--r--kernel/sysctl.c2
-rw-r--r--kernel/timer.c7
11 files changed, 132 insertions, 71 deletions
diff --git a/kernel/capability.c b/kernel/capability.c
index f02ad47320b9..d4377c5a36c9 100644
--- a/kernel/capability.c
+++ b/kernel/capability.c
@@ -62,8 +62,9 @@ asmlinkage long sys_capget(cap_user_header_t header, cap_user_data_t dataptr)
62 spin_lock(&task_capability_lock); 62 spin_lock(&task_capability_lock);
63 read_lock(&tasklist_lock); 63 read_lock(&tasklist_lock);
64 64
65 if (pid && pid != current->pid) { 65 if (pid && pid != task_pid_vnr(current)) {
66 target = find_task_by_pid(pid); 66 target = find_task_by_pid_ns(pid,
67 current->nsproxy->pid_ns);
67 if (!target) { 68 if (!target) {
68 ret = -ESRCH; 69 ret = -ESRCH;
69 goto out; 70 goto out;
@@ -96,7 +97,7 @@ static inline int cap_set_pg(int pgrp_nr, kernel_cap_t *effective,
96 int found = 0; 97 int found = 0;
97 struct pid *pgrp; 98 struct pid *pgrp;
98 99
99 pgrp = find_pid(pgrp_nr); 100 pgrp = find_pid_ns(pgrp_nr, current->nsproxy->pid_ns);
100 do_each_pid_task(pgrp, PIDTYPE_PGID, g) { 101 do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
101 target = g; 102 target = g;
102 while_each_thread(g, target) { 103 while_each_thread(g, target) {
@@ -185,7 +186,7 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data)
185 if (get_user(pid, &header->pid)) 186 if (get_user(pid, &header->pid))
186 return -EFAULT; 187 return -EFAULT;
187 188
188 if (pid && pid != current->pid && !capable(CAP_SETPCAP)) 189 if (pid && pid != task_pid_vnr(current) && !capable(CAP_SETPCAP))
189 return -EPERM; 190 return -EPERM;
190 191
191 if (copy_from_user(&effective, &data->effective, sizeof(effective)) || 192 if (copy_from_user(&effective, &data->effective, sizeof(effective)) ||
@@ -196,8 +197,9 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data)
196 spin_lock(&task_capability_lock); 197 spin_lock(&task_capability_lock);
197 read_lock(&tasklist_lock); 198 read_lock(&tasklist_lock);
198 199
199 if (pid > 0 && pid != current->pid) { 200 if (pid > 0 && pid != task_pid_vnr(current)) {
200 target = find_task_by_pid(pid); 201 target = find_task_by_pid_ns(pid,
202 current->nsproxy->pid_ns);
201 if (!target) { 203 if (!target) {
202 ret = -ESRCH; 204 ret = -ESRCH;
203 goto out; 205 goto out;
diff --git a/kernel/exit.c b/kernel/exit.c
index 567909fd6be4..68d27039ef7d 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1112,15 +1112,17 @@ asmlinkage void sys_exit_group(int error_code)
1112static int eligible_child(pid_t pid, int options, struct task_struct *p) 1112static int eligible_child(pid_t pid, int options, struct task_struct *p)
1113{ 1113{
1114 int err; 1114 int err;
1115 struct pid_namespace *ns;
1115 1116
1117 ns = current->nsproxy->pid_ns;
1116 if (pid > 0) { 1118 if (pid > 0) {
1117 if (p->pid != pid) 1119 if (task_pid_nr_ns(p, ns) != pid)
1118 return 0; 1120 return 0;
1119 } else if (!pid) { 1121 } else if (!pid) {
1120 if (task_pgrp_nr(p) != task_pgrp_nr(current)) 1122 if (task_pgrp_nr_ns(p, ns) != task_pgrp_vnr(current))
1121 return 0; 1123 return 0;
1122 } else if (pid != -1) { 1124 } else if (pid != -1) {
1123 if (task_pgrp_nr(p) != -pid) 1125 if (task_pgrp_nr_ns(p, ns) != -pid)
1124 return 0; 1126 return 0;
1125 } 1127 }
1126 1128
@@ -1190,9 +1192,12 @@ static int wait_task_zombie(struct task_struct *p, int noreap,
1190{ 1192{
1191 unsigned long state; 1193 unsigned long state;
1192 int retval, status, traced; 1194 int retval, status, traced;
1195 struct pid_namespace *ns;
1196
1197 ns = current->nsproxy->pid_ns;
1193 1198
1194 if (unlikely(noreap)) { 1199 if (unlikely(noreap)) {
1195 pid_t pid = p->pid; 1200 pid_t pid = task_pid_nr_ns(p, ns);
1196 uid_t uid = p->uid; 1201 uid_t uid = p->uid;
1197 int exit_code = p->exit_code; 1202 int exit_code = p->exit_code;
1198 int why, status; 1203 int why, status;
@@ -1311,11 +1316,11 @@ static int wait_task_zombie(struct task_struct *p, int noreap,
1311 retval = put_user(status, &infop->si_status); 1316 retval = put_user(status, &infop->si_status);
1312 } 1317 }
1313 if (!retval && infop) 1318 if (!retval && infop)
1314 retval = put_user(p->pid, &infop->si_pid); 1319 retval = put_user(task_pid_nr_ns(p, ns), &infop->si_pid);
1315 if (!retval && infop) 1320 if (!retval && infop)
1316 retval = put_user(p->uid, &infop->si_uid); 1321 retval = put_user(p->uid, &infop->si_uid);
1317 if (!retval) 1322 if (!retval)
1318 retval = p->pid; 1323 retval = task_pid_nr_ns(p, ns);
1319 1324
1320 if (traced) { 1325 if (traced) {
1321 write_lock_irq(&tasklist_lock); 1326 write_lock_irq(&tasklist_lock);
@@ -1352,6 +1357,7 @@ static int wait_task_stopped(struct task_struct *p, int delayed_group_leader,
1352 int __user *stat_addr, struct rusage __user *ru) 1357 int __user *stat_addr, struct rusage __user *ru)
1353{ 1358{
1354 int retval, exit_code; 1359 int retval, exit_code;
1360 struct pid_namespace *ns;
1355 1361
1356 if (!p->exit_code) 1362 if (!p->exit_code)
1357 return 0; 1363 return 0;
@@ -1370,11 +1376,12 @@ static int wait_task_stopped(struct task_struct *p, int delayed_group_leader,
1370 * keep holding onto the tasklist_lock while we call getrusage and 1376 * keep holding onto the tasklist_lock while we call getrusage and
1371 * possibly take page faults for user memory. 1377 * possibly take page faults for user memory.
1372 */ 1378 */
1379 ns = current->nsproxy->pid_ns;
1373 get_task_struct(p); 1380 get_task_struct(p);
1374 read_unlock(&tasklist_lock); 1381 read_unlock(&tasklist_lock);
1375 1382
1376 if (unlikely(noreap)) { 1383 if (unlikely(noreap)) {
1377 pid_t pid = p->pid; 1384 pid_t pid = task_pid_nr_ns(p, ns);
1378 uid_t uid = p->uid; 1385 uid_t uid = p->uid;
1379 int why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED; 1386 int why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED;
1380 1387
@@ -1445,11 +1452,11 @@ bail_ref:
1445 if (!retval && infop) 1452 if (!retval && infop)
1446 retval = put_user(exit_code, &infop->si_status); 1453 retval = put_user(exit_code, &infop->si_status);
1447 if (!retval && infop) 1454 if (!retval && infop)
1448 retval = put_user(p->pid, &infop->si_pid); 1455 retval = put_user(task_pid_nr_ns(p, ns), &infop->si_pid);
1449 if (!retval && infop) 1456 if (!retval && infop)
1450 retval = put_user(p->uid, &infop->si_uid); 1457 retval = put_user(p->uid, &infop->si_uid);
1451 if (!retval) 1458 if (!retval)
1452 retval = p->pid; 1459 retval = task_pid_nr_ns(p, ns);
1453 put_task_struct(p); 1460 put_task_struct(p);
1454 1461
1455 BUG_ON(!retval); 1462 BUG_ON(!retval);
@@ -1469,6 +1476,7 @@ static int wait_task_continued(struct task_struct *p, int noreap,
1469 int retval; 1476 int retval;
1470 pid_t pid; 1477 pid_t pid;
1471 uid_t uid; 1478 uid_t uid;
1479 struct pid_namespace *ns;
1472 1480
1473 if (!(p->signal->flags & SIGNAL_STOP_CONTINUED)) 1481 if (!(p->signal->flags & SIGNAL_STOP_CONTINUED))
1474 return 0; 1482 return 0;
@@ -1483,7 +1491,8 @@ static int wait_task_continued(struct task_struct *p, int noreap,
1483 p->signal->flags &= ~SIGNAL_STOP_CONTINUED; 1491 p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
1484 spin_unlock_irq(&p->sighand->siglock); 1492 spin_unlock_irq(&p->sighand->siglock);
1485 1493
1486 pid = p->pid; 1494 ns = current->nsproxy->pid_ns;
1495 pid = task_pid_nr_ns(p, ns);
1487 uid = p->uid; 1496 uid = p->uid;
1488 get_task_struct(p); 1497 get_task_struct(p);
1489 read_unlock(&tasklist_lock); 1498 read_unlock(&tasklist_lock);
@@ -1494,7 +1503,7 @@ static int wait_task_continued(struct task_struct *p, int noreap,
1494 if (!retval && stat_addr) 1503 if (!retval && stat_addr)
1495 retval = put_user(0xffff, stat_addr); 1504 retval = put_user(0xffff, stat_addr);
1496 if (!retval) 1505 if (!retval)
1497 retval = p->pid; 1506 retval = task_pid_nr_ns(p, ns);
1498 } else { 1507 } else {
1499 retval = wait_noreap_copyout(p, pid, uid, 1508 retval = wait_noreap_copyout(p, pid, uid,
1500 CLD_CONTINUED, SIGCONT, 1509 CLD_CONTINUED, SIGCONT,
diff --git a/kernel/fork.c b/kernel/fork.c
index ce9297e4e7d4..a794bfcf6003 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -950,7 +950,7 @@ asmlinkage long sys_set_tid_address(int __user *tidptr)
950{ 950{
951 current->clear_child_tid = tidptr; 951 current->clear_child_tid = tidptr;
952 952
953 return current->pid; 953 return task_pid_vnr(current);
954} 954}
955 955
956static inline void rt_mutex_init_task(struct task_struct *p) 956static inline void rt_mutex_init_task(struct task_struct *p)
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
diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
index 2c2e2954b713..cc098e1de960 100644
--- a/kernel/futex_compat.c
+++ b/kernel/futex_compat.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/linkage.h> 9#include <linux/linkage.h>
10#include <linux/compat.h> 10#include <linux/compat.h>
11#include <linux/nsproxy.h>
11#include <linux/futex.h> 12#include <linux/futex.h>
12 13
13#include <asm/uaccess.h> 14#include <asm/uaccess.h>
@@ -124,7 +125,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
124 125
125 ret = -ESRCH; 126 ret = -ESRCH;
126 read_lock(&tasklist_lock); 127 read_lock(&tasklist_lock);
127 p = find_task_by_pid(pid); 128 p = find_task_by_pid_ns(pid,
129 current->nsproxy->pid_ns);
128 if (!p) 130 if (!p)
129 goto err_unlock; 131 goto err_unlock;
130 ret = -EPERM; 132 ret = -EPERM;
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index a73ebd3b9d4c..66e99eb2d8a6 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -19,6 +19,7 @@
19#include <linux/security.h> 19#include <linux/security.h>
20#include <linux/signal.h> 20#include <linux/signal.h>
21#include <linux/audit.h> 21#include <linux/audit.h>
22#include <linux/pid_namespace.h>
22 23
23#include <asm/pgtable.h> 24#include <asm/pgtable.h>
24#include <asm/uaccess.h> 25#include <asm/uaccess.h>
@@ -443,7 +444,8 @@ struct task_struct *ptrace_get_task_struct(pid_t pid)
443 return ERR_PTR(-EPERM); 444 return ERR_PTR(-EPERM);
444 445
445 read_lock(&tasklist_lock); 446 read_lock(&tasklist_lock);
446 child = find_task_by_pid(pid); 447 child = find_task_by_pid_ns(pid,
448 current->nsproxy->pid_ns);
447 if (child) 449 if (child)
448 get_task_struct(child); 450 get_task_struct(child);
449 451
diff --git a/kernel/sched.c b/kernel/sched.c
index 72a2a16e2214..4ac56fe3c394 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -44,6 +44,7 @@
44#include <linux/vmalloc.h> 44#include <linux/vmalloc.h>
45#include <linux/blkdev.h> 45#include <linux/blkdev.h>
46#include <linux/delay.h> 46#include <linux/delay.h>
47#include <linux/pid_namespace.h>
47#include <linux/smp.h> 48#include <linux/smp.h>
48#include <linux/threads.h> 49#include <linux/threads.h>
49#include <linux/timer.h> 50#include <linux/timer.h>
@@ -1876,7 +1877,7 @@ asmlinkage void schedule_tail(struct task_struct *prev)
1876 preempt_enable(); 1877 preempt_enable();
1877#endif 1878#endif
1878 if (current->set_child_tid) 1879 if (current->set_child_tid)
1879 put_user(current->pid, current->set_child_tid); 1880 put_user(task_pid_vnr(current), current->set_child_tid);
1880} 1881}
1881 1882
1882/* 1883/*
@@ -4167,7 +4168,8 @@ struct task_struct *idle_task(int cpu)
4167 */ 4168 */
4168static struct task_struct *find_process_by_pid(pid_t pid) 4169static struct task_struct *find_process_by_pid(pid_t pid)
4169{ 4170{
4170 return pid ? find_task_by_pid(pid) : current; 4171 return pid ?
4172 find_task_by_pid_ns(pid, current->nsproxy->pid_ns) : current;
4171} 4173}
4172 4174
4173/* Actually do priority change: must hold rq lock. */ 4175/* Actually do priority change: must hold rq lock. */
diff --git a/kernel/signal.c b/kernel/signal.c
index 98923882ba57..d809cdd6c0f1 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -694,7 +694,7 @@ static int send_signal(int sig, struct siginfo *info, struct task_struct *t,
694 q->info.si_signo = sig; 694 q->info.si_signo = sig;
695 q->info.si_errno = 0; 695 q->info.si_errno = 0;
696 q->info.si_code = SI_USER; 696 q->info.si_code = SI_USER;
697 q->info.si_pid = current->pid; 697 q->info.si_pid = task_pid_vnr(current);
698 q->info.si_uid = current->uid; 698 q->info.si_uid = current->uid;
699 break; 699 break;
700 case (unsigned long) SEND_SIG_PRIV: 700 case (unsigned long) SEND_SIG_PRIV:
@@ -1089,7 +1089,7 @@ kill_proc_info(int sig, struct siginfo *info, pid_t pid)
1089{ 1089{
1090 int error; 1090 int error;
1091 rcu_read_lock(); 1091 rcu_read_lock();
1092 error = kill_pid_info(sig, info, find_pid(pid)); 1092 error = kill_pid_info(sig, info, find_vpid(pid));
1093 rcu_read_unlock(); 1093 rcu_read_unlock();
1094 return error; 1094 return error;
1095} 1095}
@@ -1160,9 +1160,9 @@ static int kill_something_info(int sig, struct siginfo *info, int pid)
1160 read_unlock(&tasklist_lock); 1160 read_unlock(&tasklist_lock);
1161 ret = count ? retval : -ESRCH; 1161 ret = count ? retval : -ESRCH;
1162 } else if (pid < 0) { 1162 } else if (pid < 0) {
1163 ret = kill_pgrp_info(sig, info, find_pid(-pid)); 1163 ret = kill_pgrp_info(sig, info, find_vpid(-pid));
1164 } else { 1164 } else {
1165 ret = kill_pid_info(sig, info, find_pid(pid)); 1165 ret = kill_pid_info(sig, info, find_vpid(pid));
1166 } 1166 }
1167 rcu_read_unlock(); 1167 rcu_read_unlock();
1168 return ret; 1168 return ret;
@@ -1266,7 +1266,12 @@ EXPORT_SYMBOL(kill_pid);
1266int 1266int
1267kill_proc(pid_t pid, int sig, int priv) 1267kill_proc(pid_t pid, int sig, int priv)
1268{ 1268{
1269 return kill_proc_info(sig, __si_special(priv), pid); 1269 int ret;
1270
1271 rcu_read_lock();
1272 ret = kill_pid_info(sig, __si_special(priv), find_pid(pid));
1273 rcu_read_unlock();
1274 return ret;
1270} 1275}
1271 1276
1272/* 1277/*
@@ -1443,7 +1448,22 @@ void do_notify_parent(struct task_struct *tsk, int sig)
1443 1448
1444 info.si_signo = sig; 1449 info.si_signo = sig;
1445 info.si_errno = 0; 1450 info.si_errno = 0;
1446 info.si_pid = tsk->pid; 1451 /*
1452 * we are under tasklist_lock here so our parent is tied to
1453 * us and cannot exit and release its namespace.
1454 *
1455 * the only it can is to switch its nsproxy with sys_unshare,
1456 * bu uncharing pid namespaces is not allowed, so we'll always
1457 * see relevant namespace
1458 *
1459 * write_lock() currently calls preempt_disable() which is the
1460 * same as rcu_read_lock(), but according to Oleg, this is not
1461 * correct to rely on this
1462 */
1463 rcu_read_lock();
1464 info.si_pid = task_pid_nr_ns(tsk, tsk->parent->nsproxy->pid_ns);
1465 rcu_read_unlock();
1466
1447 info.si_uid = tsk->uid; 1467 info.si_uid = tsk->uid;
1448 1468
1449 /* FIXME: find out whether or not this is supposed to be c*time. */ 1469 /* FIXME: find out whether or not this is supposed to be c*time. */
@@ -1508,7 +1528,13 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, int why)
1508 1528
1509 info.si_signo = SIGCHLD; 1529 info.si_signo = SIGCHLD;
1510 info.si_errno = 0; 1530 info.si_errno = 0;
1511 info.si_pid = tsk->pid; 1531 /*
1532 * see comment in do_notify_parent() abot the following 3 lines
1533 */
1534 rcu_read_lock();
1535 info.si_pid = task_pid_nr_ns(tsk, tsk->parent->nsproxy->pid_ns);
1536 rcu_read_unlock();
1537
1512 info.si_uid = tsk->uid; 1538 info.si_uid = tsk->uid;
1513 1539
1514 /* FIXME: find out whether or not this is supposed to be c*time. */ 1540 /* FIXME: find out whether or not this is supposed to be c*time. */
@@ -1634,7 +1660,7 @@ void ptrace_notify(int exit_code)
1634 memset(&info, 0, sizeof info); 1660 memset(&info, 0, sizeof info);
1635 info.si_signo = SIGTRAP; 1661 info.si_signo = SIGTRAP;
1636 info.si_code = exit_code; 1662 info.si_code = exit_code;
1637 info.si_pid = current->pid; 1663 info.si_pid = task_pid_vnr(current);
1638 info.si_uid = current->uid; 1664 info.si_uid = current->uid;
1639 1665
1640 /* Let the debugger run. */ 1666 /* Let the debugger run. */
@@ -1804,7 +1830,7 @@ relock:
1804 info->si_signo = signr; 1830 info->si_signo = signr;
1805 info->si_errno = 0; 1831 info->si_errno = 0;
1806 info->si_code = SI_USER; 1832 info->si_code = SI_USER;
1807 info->si_pid = current->parent->pid; 1833 info->si_pid = task_pid_vnr(current->parent);
1808 info->si_uid = current->parent->uid; 1834 info->si_uid = current->parent->uid;
1809 } 1835 }
1810 1836
@@ -2191,7 +2217,7 @@ sys_kill(int pid, int sig)
2191 info.si_signo = sig; 2217 info.si_signo = sig;
2192 info.si_errno = 0; 2218 info.si_errno = 0;
2193 info.si_code = SI_USER; 2219 info.si_code = SI_USER;
2194 info.si_pid = current->tgid; 2220 info.si_pid = task_tgid_vnr(current);
2195 info.si_uid = current->uid; 2221 info.si_uid = current->uid;
2196 2222
2197 return kill_something_info(sig, &info, pid); 2223 return kill_something_info(sig, &info, pid);
@@ -2207,12 +2233,12 @@ static int do_tkill(int tgid, int pid, int sig)
2207 info.si_signo = sig; 2233 info.si_signo = sig;
2208 info.si_errno = 0; 2234 info.si_errno = 0;
2209 info.si_code = SI_TKILL; 2235 info.si_code = SI_TKILL;
2210 info.si_pid = current->tgid; 2236 info.si_pid = task_tgid_vnr(current);
2211 info.si_uid = current->uid; 2237 info.si_uid = current->uid;
2212 2238
2213 read_lock(&tasklist_lock); 2239 read_lock(&tasklist_lock);
2214 p = find_task_by_pid(pid); 2240 p = find_task_by_pid_ns(pid, current->nsproxy->pid_ns);
2215 if (p && (tgid <= 0 || p->tgid == tgid)) { 2241 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
2216 error = check_kill_permission(sig, &info, p); 2242 error = check_kill_permission(sig, &info, p);
2217 /* 2243 /*
2218 * The null signal is a permissions and process existence 2244 * The null signal is a permissions and process existence
diff --git a/kernel/sys.c b/kernel/sys.c
index 4cfa213a5ac2..23620d52cf37 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -152,7 +152,8 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
152 switch (which) { 152 switch (which) {
153 case PRIO_PROCESS: 153 case PRIO_PROCESS:
154 if (who) 154 if (who)
155 p = find_task_by_pid(who); 155 p = find_task_by_pid_ns(who,
156 current->nsproxy->pid_ns);
156 else 157 else
157 p = current; 158 p = current;
158 if (p) 159 if (p)
@@ -160,7 +161,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
160 break; 161 break;
161 case PRIO_PGRP: 162 case PRIO_PGRP:
162 if (who) 163 if (who)
163 pgrp = find_pid(who); 164 pgrp = find_vpid(who);
164 else 165 else
165 pgrp = task_pgrp(current); 166 pgrp = task_pgrp(current);
166 do_each_pid_task(pgrp, PIDTYPE_PGID, p) { 167 do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
@@ -209,7 +210,8 @@ asmlinkage long sys_getpriority(int which, int who)
209 switch (which) { 210 switch (which) {
210 case PRIO_PROCESS: 211 case PRIO_PROCESS:
211 if (who) 212 if (who)
212 p = find_task_by_pid(who); 213 p = find_task_by_pid_ns(who,
214 current->nsproxy->pid_ns);
213 else 215 else
214 p = current; 216 p = current;
215 if (p) { 217 if (p) {
@@ -220,7 +222,7 @@ asmlinkage long sys_getpriority(int which, int who)
220 break; 222 break;
221 case PRIO_PGRP: 223 case PRIO_PGRP:
222 if (who) 224 if (who)
223 pgrp = find_pid(who); 225 pgrp = find_vpid(who);
224 else 226 else
225 pgrp = task_pgrp(current); 227 pgrp = task_pgrp(current);
226 do_each_pid_task(pgrp, PIDTYPE_PGID, p) { 228 do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
@@ -917,9 +919,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
917 struct task_struct *p; 919 struct task_struct *p;
918 struct task_struct *group_leader = current->group_leader; 920 struct task_struct *group_leader = current->group_leader;
919 int err = -EINVAL; 921 int err = -EINVAL;
922 struct pid_namespace *ns;
920 923
921 if (!pid) 924 if (!pid)
922 pid = group_leader->pid; 925 pid = task_pid_vnr(group_leader);
923 if (!pgid) 926 if (!pgid)
924 pgid = pid; 927 pgid = pid;
925 if (pgid < 0) 928 if (pgid < 0)
@@ -928,10 +931,12 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
928 /* From this point forward we keep holding onto the tasklist lock 931 /* From this point forward we keep holding onto the tasklist lock
929 * so that our parent does not change from under us. -DaveM 932 * so that our parent does not change from under us. -DaveM
930 */ 933 */
934 ns = current->nsproxy->pid_ns;
935
931 write_lock_irq(&tasklist_lock); 936 write_lock_irq(&tasklist_lock);
932 937
933 err = -ESRCH; 938 err = -ESRCH;
934 p = find_task_by_pid(pid); 939 p = find_task_by_pid_ns(pid, ns);
935 if (!p) 940 if (!p)
936 goto out; 941 goto out;
937 942
@@ -957,9 +962,9 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
957 goto out; 962 goto out;
958 963
959 if (pgid != pid) { 964 if (pgid != pid) {
960 struct task_struct *g = 965 struct task_struct *g;
961 find_task_by_pid_type(PIDTYPE_PGID, pgid);
962 966
967 g = find_task_by_pid_type_ns(PIDTYPE_PGID, pgid, ns);
963 if (!g || task_session(g) != task_session(group_leader)) 968 if (!g || task_session(g) != task_session(group_leader))
964 goto out; 969 goto out;
965 } 970 }
@@ -968,10 +973,13 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
968 if (err) 973 if (err)
969 goto out; 974 goto out;
970 975
971 if (task_pgrp_nr(p) != pgid) { 976 if (task_pgrp_nr_ns(p, ns) != pgid) {
977 struct pid *pid;
978
972 detach_pid(p, PIDTYPE_PGID); 979 detach_pid(p, PIDTYPE_PGID);
973 p->signal->pgrp = pgid; 980 pid = find_vpid(pgid);
974 attach_pid(p, PIDTYPE_PGID, find_pid(pgid)); 981 attach_pid(p, PIDTYPE_PGID, pid);
982 p->signal->pgrp = pid_nr(pid);
975 } 983 }
976 984
977 err = 0; 985 err = 0;
@@ -984,19 +992,21 @@ out:
984asmlinkage long sys_getpgid(pid_t pid) 992asmlinkage long sys_getpgid(pid_t pid)
985{ 993{
986 if (!pid) 994 if (!pid)
987 return task_pgrp_nr(current); 995 return task_pgrp_vnr(current);
988 else { 996 else {
989 int retval; 997 int retval;
990 struct task_struct *p; 998 struct task_struct *p;
999 struct pid_namespace *ns;
991 1000
992 read_lock(&tasklist_lock); 1001 ns = current->nsproxy->pid_ns;
993 p = find_task_by_pid(pid);
994 1002
1003 read_lock(&tasklist_lock);
1004 p = find_task_by_pid_ns(pid, ns);
995 retval = -ESRCH; 1005 retval = -ESRCH;
996 if (p) { 1006 if (p) {
997 retval = security_task_getpgid(p); 1007 retval = security_task_getpgid(p);
998 if (!retval) 1008 if (!retval)
999 retval = task_pgrp_nr(p); 1009 retval = task_pgrp_nr_ns(p, ns);
1000 } 1010 }
1001 read_unlock(&tasklist_lock); 1011 read_unlock(&tasklist_lock);
1002 return retval; 1012 return retval;
@@ -1008,7 +1018,7 @@ asmlinkage long sys_getpgid(pid_t pid)
1008asmlinkage long sys_getpgrp(void) 1018asmlinkage long sys_getpgrp(void)
1009{ 1019{
1010 /* SMP - assuming writes are word atomic this is fine */ 1020 /* SMP - assuming writes are word atomic this is fine */
1011 return task_pgrp_nr(current); 1021 return task_pgrp_vnr(current);
1012} 1022}
1013 1023
1014#endif 1024#endif
@@ -1016,19 +1026,21 @@ asmlinkage long sys_getpgrp(void)
1016asmlinkage long sys_getsid(pid_t pid) 1026asmlinkage long sys_getsid(pid_t pid)
1017{ 1027{
1018 if (!pid) 1028 if (!pid)
1019 return task_session_nr(current); 1029 return task_session_vnr(current);
1020 else { 1030 else {
1021 int retval; 1031 int retval;
1022 struct task_struct *p; 1032 struct task_struct *p;
1033 struct pid_namespace *ns;
1023 1034
1024 read_lock(&tasklist_lock); 1035 ns = current->nsproxy->pid_ns;
1025 p = find_task_by_pid(pid);
1026 1036
1037 read_lock(&tasklist_lock);
1038 p = find_task_by_pid_ns(pid, ns);
1027 retval = -ESRCH; 1039 retval = -ESRCH;
1028 if (p) { 1040 if (p) {
1029 retval = security_task_getsid(p); 1041 retval = security_task_getsid(p);
1030 if (!retval) 1042 if (!retval)
1031 retval = task_session_nr(p); 1043 retval = task_session_nr_ns(p, ns);
1032 } 1044 }
1033 read_unlock(&tasklist_lock); 1045 read_unlock(&tasklist_lock);
1034 return retval; 1046 return retval;
@@ -1065,7 +1077,7 @@ asmlinkage long sys_setsid(void)
1065 group_leader->signal->tty = NULL; 1077 group_leader->signal->tty = NULL;
1066 spin_unlock(&group_leader->sighand->siglock); 1078 spin_unlock(&group_leader->sighand->siglock);
1067 1079
1068 err = task_pgrp_nr(group_leader); 1080 err = task_pgrp_vnr(group_leader);
1069out: 1081out:
1070 write_unlock_irq(&tasklist_lock); 1082 write_unlock_irq(&tasklist_lock);
1071 return err; 1083 return err;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 44868e4df1d3..3b4efbe26445 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2278,7 +2278,7 @@ static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp
2278 pid_t tmp; 2278 pid_t tmp;
2279 int r; 2279 int r;
2280 2280
2281 tmp = pid_nr(cad_pid); 2281 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
2282 2282
2283 r = __do_proc_dointvec(&tmp, table, write, filp, buffer, 2283 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2284 lenp, ppos, NULL, NULL); 2284 lenp, ppos, NULL, NULL);
diff --git a/kernel/timer.c b/kernel/timer.c
index 8521d10fbb27..fb4e67d5dd60 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -26,6 +26,7 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/mm.h> 27#include <linux/mm.h>
28#include <linux/swap.h> 28#include <linux/swap.h>
29#include <linux/pid_namespace.h>
29#include <linux/notifier.h> 30#include <linux/notifier.h>
30#include <linux/thread_info.h> 31#include <linux/thread_info.h>
31#include <linux/time.h> 32#include <linux/time.h>
@@ -956,7 +957,7 @@ asmlinkage unsigned long sys_alarm(unsigned int seconds)
956 */ 957 */
957asmlinkage long sys_getpid(void) 958asmlinkage long sys_getpid(void)
958{ 959{
959 return current->tgid; 960 return task_tgid_vnr(current);
960} 961}
961 962
962/* 963/*
@@ -970,7 +971,7 @@ asmlinkage long sys_getppid(void)
970 int pid; 971 int pid;
971 972
972 rcu_read_lock(); 973 rcu_read_lock();
973 pid = rcu_dereference(current->real_parent)->tgid; 974 pid = task_ppid_nr_ns(current, current->nsproxy->pid_ns);
974 rcu_read_unlock(); 975 rcu_read_unlock();
975 976
976 return pid; 977 return pid;
@@ -1102,7 +1103,7 @@ EXPORT_SYMBOL(schedule_timeout_uninterruptible);
1102/* Thread ID - the internal kernel "pid" */ 1103/* Thread ID - the internal kernel "pid" */
1103asmlinkage long sys_gettid(void) 1104asmlinkage long sys_gettid(void)
1104{ 1105{
1105 return current->pid; 1106 return task_pid_vnr(current);
1106} 1107}
1107 1108
1108/** 1109/**