aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/exit.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/exit.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/exit.c')
-rw-r--r--kernel/exit.c31
1 files changed, 20 insertions, 11 deletions
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,