All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] make kernel threads invisible to /sbin/init
@ 2007-04-10 18:51 Oleg Nesterov
  2007-04-10 23:16 ` Serge E. Hallyn
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Oleg Nesterov @ 2007-04-10 18:51 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Davide Libenzi, Eric W. Biederman, Jan Engelhardt, Ingo Molnar,
	Linus Torvalds, Robin Holt, Roland McGrath, Serge E. Hallyn,
	linux-kernel

1. rename reparent_to_init() to reparent_kthread() and export it

2. use init_pid_ns.child_reaper instead of child_reaper(current)

3. set ->exit_signal = -1, so init can't see us and we don't use
   it to reap the task.

4. add reparent_kthread() to kthread() and stopmachine()

See also

	http://marc.info/?t=117580282200003&r=1
	http://marc.info/?t=95299284800003&r=1

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

 include/linux/sched.h |    1 +
 kernel/exit.c         |   16 ++++++++--------
 kernel/kthread.c      |    1 +
 kernel/stop_machine.c |    1 +
 4 files changed, 11 insertions(+), 8 deletions(-)

--- 2.6.21-rc5/include/linux/sched.h~2_DETACH	2007-04-05 12:18:28.000000000 +0400
+++ 2.6.21-rc5/include/linux/sched.h	2007-04-10 21:52:27.000000000 +0400
@@ -1401,6 +1401,7 @@ extern void exit_itimers(struct signal_s
 
 extern NORET_TYPE void do_group_exit(int);
 
+extern void reparent_kthread(void);
 extern void daemonize(const char *, ...);
 extern int allow_signal(int);
 extern int disallow_signal(int);
--- 2.6.21-rc5/kernel/exit.c~2_DETACH	2007-04-10 21:32:44.000000000 +0400
+++ 2.6.21-rc5/kernel/exit.c	2007-04-10 21:59:41.000000000 +0400
@@ -255,7 +255,7 @@ static int has_stopped_jobs(struct pid *
 }
 
 /**
- * reparent_to_init - Reparent the calling kernel thread to the init task of the pid space that the thread belongs to.
+ * reparent_kthread - Reparent the calling kernel thread to the init task of the pid space that the thread belongs to.
  *
  * If a kernel thread is launched as a result of a system call, or if
  * it ever exits, it should generally reparent itself to init so that
@@ -264,20 +264,20 @@ static int has_stopped_jobs(struct pid *
  * The various task state such as scheduling policy and priority may have
  * been inherited from a user process, so we reset them to sane values here.
  *
- * NOTE that reparent_to_init() gives the caller full capabilities.
+ * NOTE that reparent_kthread() gives the caller full capabilities.
  */
-static void reparent_to_init(void)
+void reparent_kthread(void)
 {
 	write_lock_irq(&tasklist_lock);
 
 	ptrace_unlink(current);
 	remove_parent(current);
-	current->parent = child_reaper(current);
-	current->real_parent = child_reaper(current);
+	current->parent = init_pid_ns.child_reaper;
+	current->real_parent = current->parent;
 	add_parent(current);
 
-	/* Set the exit signal to SIGCHLD so we signal init on exit */
-	current->exit_signal = SIGCHLD;
+	/* make the task auto-reap */
+	current->exit_signal = -1;
 
 	security_task_reparent_to_init(current);
 	write_unlock_irq(&tasklist_lock);
@@ -391,7 +391,7 @@ void daemonize(const char *name, ...)
 	current->files = init_task.files;
 	atomic_inc(&current->files->count);
 
-	reparent_to_init();
+	reparent_kthread();
 
 	if (!has_rt_policy(current) && (task_nice(current) < 0))
 		set_user_nice(current, 0);
--- 2.6.21-rc5/kernel/kthread.c~2_DETACH	2007-04-05 12:18:28.000000000 +0400
+++ 2.6.21-rc5/kernel/kthread.c	2007-04-10 22:02:31.000000000 +0400
@@ -82,6 +82,7 @@ static int kthread(void *_create)
 	sigset_t blocked;
 	int ret = -EINTR;
 
+	reparent_kthread();
 	kthread_exit_files();
 
 	/* Copy data: it's on keventd's stack */
--- 2.6.21-rc5/kernel/stop_machine.c~2_DETACH	2006-10-22 18:24:03.000000000 +0400
+++ 2.6.21-rc5/kernel/stop_machine.c	2007-04-10 22:04:23.000000000 +0400
@@ -33,6 +33,7 @@ static int stopmachine(void *cpu)
 	int irqs_disabled = 0;
 	int prepared = 0;
 
+	reparent_kthread();
 	set_cpus_allowed(current, cpumask_of_cpu((int)(long)cpu));
 
 	/* Ack: we are alive */


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2007-04-11 20:04 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-10 18:51 [PATCH 2/3] make kernel threads invisible to /sbin/init Oleg Nesterov
2007-04-10 23:16 ` Serge E. Hallyn
2007-04-11  3:29   ` Eric W. Biederman
2007-04-11  3:56 ` Eric W. Biederman
2007-04-11 11:42   ` Oleg Nesterov
2007-04-11  5:44 ` [PATCH] kthread: Don't depend on work queues Eric W. Biederman
2007-04-11  7:03   ` Andrew Morton
2007-04-11 10:13     ` Rafael J. Wysocki
2007-04-11 11:21       ` Gautham R Shenoy
2007-04-11 11:48         ` Oleg Nesterov
2007-04-11 13:31           ` Gautham R Shenoy
2007-04-11 14:36             ` Oleg Nesterov
2007-04-11 19:37               ` Rafael J. Wysocki
2007-04-11 14:44             ` Rafael J. Wysocki
2007-04-11 18:22     ` Eric W. Biederman
2007-04-11 18:27     ` [PATCH] kthread: Don't depend on work queues (take 2) Eric W. Biederman
2007-04-11 18:49       ` [PATCH] Change reparent_to_init to reparent_to_kthreadd Eric W. Biederman
2007-04-11 19:21       ` [PATCH] kthread: Don't depend on work queues (take 2) Andrew Morton
2007-04-11 19:28       ` Oleg Nesterov
2007-04-11 19:40         ` Eric W. Biederman
2007-04-11 19:49           ` Oleg Nesterov
2007-04-11 20:02             ` Eric W. Biederman
2007-04-11 12:04   ` [PATCH] kthread: Don't depend on work queues Oleg Nesterov
2007-04-11 16:25     ` Eric W. Biederman
2007-04-11 13:15   ` Oleg Nesterov
2007-04-11 16:22     ` Eric W. Biederman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.