aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sys.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/sys.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/sys.c')
-rw-r--r--kernel/sys.c54
1 files changed, 33 insertions, 21 deletions
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;