Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 84d73786 authored by Sukadev Bhattiprolu's avatar Sukadev Bhattiprolu Committed by Linus Torvalds
Browse files

[PATCH] add child reaper to pid_namespace

Add a per pid_namespace child-reaper.  This is needed so processes are reaped
within the same pid space and do not spill over to the parent pid space.  Its
also needed so containers preserve existing semantic that pid == 1 would reap
orphaned children.

This is based on Eric Biederman's patch: http://lkml.org/lkml/2006/2/6/285



Signed-off-by: default avatarSukadev Bhattiprolu <sukadev@us.ibm.com>
Signed-off-by: default avatarCedric Le Goater <clg@fr.ibm.com>
Cc: Kirill Korotaev <dev@openvz.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 6cc1b22a
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@
#include <linux/binfmts.h>
#include <linux/binfmts.h>
#include <linux/swap.h>
#include <linux/swap.h>
#include <linux/utsname.h>
#include <linux/utsname.h>
#include <linux/pid_namespace.h>
#include <linux/module.h>
#include <linux/module.h>
#include <linux/namei.h>
#include <linux/namei.h>
#include <linux/proc_fs.h>
#include <linux/proc_fs.h>
@@ -620,8 +621,8 @@ static int de_thread(struct task_struct *tsk)
	 * Reparenting needs write_lock on tasklist_lock,
	 * Reparenting needs write_lock on tasklist_lock,
	 * so it is safe to do it under read_lock.
	 * so it is safe to do it under read_lock.
	 */
	 */
	if (unlikely(tsk->group_leader == child_reaper))
	if (unlikely(tsk->group_leader == child_reaper(tsk)))
		child_reaper = tsk;
		tsk->nsproxy->pid_ns->child_reaper = tsk;


	zap_other_threads(tsk);
	zap_other_threads(tsk);
	read_unlock(&tasklist_lock);
	read_unlock(&tasklist_lock);
+3 −2
Original line number Original line Diff line number Diff line
@@ -35,8 +35,9 @@ enum pid_type
 *
 *
 * Holding a reference to struct pid solves both of these problems.
 * Holding a reference to struct pid solves both of these problems.
 * It is small so holding a reference does not consume a lot of
 * It is small so holding a reference does not consume a lot of
 * resources, and since a new struct pid is allocated when the numeric
 * resources, and since a new struct pid is allocated when the numeric pid
 * pid value is reused we don't mistakenly refer to new processes.
 * value is reused (when pids wrap around) we don't mistakenly refer to new
 * processes.
 */
 */


struct pid
struct pid
+6 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ struct pid_namespace {
	struct kref kref;
	struct kref kref;
	struct pidmap pidmap[PIDMAP_ENTRIES];
	struct pidmap pidmap[PIDMAP_ENTRIES];
	int last_pid;
	int last_pid;
	struct task_struct *child_reaper;
};
};


extern struct pid_namespace init_pid_ns;
extern struct pid_namespace init_pid_ns;
@@ -36,4 +37,9 @@ static inline void put_pid_ns(struct pid_namespace *ns)
	kref_put(&ns->kref, free_pid_ns);
	kref_put(&ns->kref, free_pid_ns);
}
}


static inline struct task_struct *child_reaper(struct task_struct *tsk)
{
	return tsk->nsproxy->pid_ns->child_reaper;
}

#endif /* _LINUX_PID_NS_H */
#endif /* _LINUX_PID_NS_H */
+0 −1
Original line number Original line Diff line number Diff line
@@ -1400,7 +1400,6 @@ extern NORET_TYPE void do_group_exit(int);
extern void daemonize(const char *, ...);
extern void daemonize(const char *, ...);
extern int allow_signal(int);
extern int allow_signal(int);
extern int disallow_signal(int);
extern int disallow_signal(int);
extern struct task_struct *child_reaper;


extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *);
extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *);
extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
+2 −3
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@
#include <linux/debug_locks.h>
#include <linux/debug_locks.h>
#include <linux/lockdep.h>
#include <linux/lockdep.h>
#include <linux/utsrelease.h>
#include <linux/utsrelease.h>
#include <linux/pid_namespace.h>
#include <linux/compile.h>
#include <linux/compile.h>


#include <asm/io.h>
#include <asm/io.h>
@@ -626,8 +627,6 @@ static int __init initcall_debug_setup(char *str)
}
}
__setup("initcall_debug", initcall_debug_setup);
__setup("initcall_debug", initcall_debug_setup);


struct task_struct *child_reaper = &init_task;

extern initcall_t __initcall_start[], __initcall_end[];
extern initcall_t __initcall_start[], __initcall_end[];


static void __init do_initcalls(void)
static void __init do_initcalls(void)
@@ -727,7 +726,7 @@ static int init(void * unused)
	 * assumptions about where in the task array this
	 * assumptions about where in the task array this
	 * can be found.
	 * can be found.
	 */
	 */
	child_reaper = current;
	init_pid_ns.child_reaper = current;


	cad_pid = task_pid(current);
	cad_pid = task_pid(current);


Loading