aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/pid_namespace.h10
-rw-r--r--include/linux/sched.h12
-rw-r--r--kernel/pid.c21
3 files changed, 25 insertions, 18 deletions
diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index 416d4e4ce94e..0135c76c76c6 100644
--- a/include/linux/pid_namespace.h
+++ b/include/linux/pid_namespace.h
@@ -4,7 +4,6 @@
4#include <linux/sched.h> 4#include <linux/sched.h>
5#include <linux/mm.h> 5#include <linux/mm.h>
6#include <linux/threads.h> 6#include <linux/threads.h>
7#include <linux/pid.h>
8#include <linux/nsproxy.h> 7#include <linux/nsproxy.h>
9#include <linux/kref.h> 8#include <linux/kref.h>
10 9
@@ -32,7 +31,8 @@ extern struct pid_namespace init_pid_ns;
32 31
33static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) 32static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
34{ 33{
35 kref_get(&ns->kref); 34 if (ns != &init_pid_ns)
35 kref_get(&ns->kref);
36 return ns; 36 return ns;
37} 37}
38 38
@@ -41,7 +41,8 @@ extern void free_pid_ns(struct kref *kref);
41 41
42static inline void put_pid_ns(struct pid_namespace *ns) 42static inline void put_pid_ns(struct pid_namespace *ns)
43{ 43{
44 kref_put(&ns->kref, free_pid_ns); 44 if (ns != &init_pid_ns)
45 kref_put(&ns->kref, free_pid_ns);
45} 46}
46 47
47static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk) 48static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk)
@@ -51,7 +52,8 @@ static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk)
51 52
52static inline struct task_struct *task_child_reaper(struct task_struct *tsk) 53static inline struct task_struct *task_child_reaper(struct task_struct *tsk)
53{ 54{
54 return init_pid_ns.child_reaper; 55 BUG_ON(tsk != current);
56 return tsk->nsproxy->pid_ns->child_reaper;
55} 57}
56 58
57#endif /* _LINUX_PID_NS_H */ 59#endif /* _LINUX_PID_NS_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 511cc4549f58..b0bf326143a9 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1329,19 +1329,17 @@ static inline int pid_alive(struct task_struct *p)
1329 * @tsk: Task structure to be checked. 1329 * @tsk: Task structure to be checked.
1330 * 1330 *
1331 * Check if a task structure is the first user space task the kernel created. 1331 * Check if a task structure is the first user space task the kernel created.
1332 *
1333 * TODO: We should inline this function after some cleanups in pid_namespace.h
1334 */ 1332 */
1335extern int is_global_init(struct task_struct *tsk); 1333static inline int is_global_init(struct task_struct *tsk)
1334{
1335 return tsk->pid == 1;
1336}
1336 1337
1337/* 1338/*
1338 * is_container_init: 1339 * is_container_init:
1339 * check whether in the task is init in its own pid namespace. 1340 * check whether in the task is init in its own pid namespace.
1340 */ 1341 */
1341static inline int is_container_init(struct task_struct *tsk) 1342extern int is_container_init(struct task_struct *tsk);
1342{
1343 return tsk->pid == 1;
1344}
1345 1343
1346extern struct pid *cad_pid; 1344extern struct pid *cad_pid;
1347 1345
diff --git a/kernel/pid.c b/kernel/pid.c
index a2b4cbbdd63d..4b17acdb862f 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -73,10 +73,20 @@ struct pid_namespace init_pid_ns = {
73}; 73};
74EXPORT_SYMBOL_GPL(init_pid_ns); 74EXPORT_SYMBOL_GPL(init_pid_ns);
75 75
76int is_global_init(struct task_struct *tsk) 76int is_container_init(struct task_struct *tsk)
77{ 77{
78 return tsk == init_pid_ns.child_reaper; 78 int ret = 0;
79 struct pid *pid;
80
81 rcu_read_lock();
82 pid = task_pid(tsk);
83 if (pid != NULL && pid->numbers[pid->level].nr == 1)
84 ret = 1;
85 rcu_read_unlock();
86
87 return ret;
79} 88}
89EXPORT_SYMBOL(is_container_init);
80 90
81/* 91/*
82 * Note: disable interrupts while the pidmap_lock is held as an 92 * Note: disable interrupts while the pidmap_lock is held as an
@@ -192,8 +202,7 @@ fastcall void put_pid(struct pid *pid)
192 if ((atomic_read(&pid->count) == 1) || 202 if ((atomic_read(&pid->count) == 1) ||
193 atomic_dec_and_test(&pid->count)) { 203 atomic_dec_and_test(&pid->count)) {
194 kmem_cache_free(ns->pid_cachep, pid); 204 kmem_cache_free(ns->pid_cachep, pid);
195 if (ns != &init_pid_ns) 205 put_pid_ns(ns);
196 put_pid_ns(ns);
197 } 206 }
198} 207}
199EXPORT_SYMBOL_GPL(put_pid); 208EXPORT_SYMBOL_GPL(put_pid);
@@ -244,9 +253,7 @@ struct pid *alloc_pid(struct pid_namespace *ns)
244 tmp = tmp->parent; 253 tmp = tmp->parent;
245 } 254 }
246 255
247 if (ns != &init_pid_ns) 256 get_pid_ns(ns);
248 get_pid_ns(ns);
249
250 pid->level = ns->level; 257 pid->level = ns->level;
251 pid->nr = pid->numbers[0].nr; 258 pid->nr = pid->numbers[0].nr;
252 atomic_set(&pid->count, 1); 259 atomic_set(&pid->count, 1);