mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
	Pavel Emelyanov <xemul@openvz.org>, Pavel Machek <pavel@ucw.cz>,
	Stephen Smalley <sds@tycho.nsa.gov>,
	Roland McGrath <roland@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] ptrace: it is fun to strace /sbin/init
Date: Sun, 23 Mar 2008 16:51:10 +0300	[thread overview]
Message-ID: <20080323135110.GA294@tv-sign.ru> (raw)

(re-send with updated changelog)

Ptracing of /sbin/init is not allowed. Of course, this is dangerous, but may
be useful. Introduce the kernel boot parameter to allow this, so that we can't
surprise some special/secured systems.

Afaics, with the recent changes there is no kernel problems with ptracing init,
it can't lose SIGNAL_UNKILLABLE flag and be killed by accident. However, admin
should know what it does, "gdb /sbin/init 1" stops init, it can't reap zombies
or take care of /etc/inittab until continued. It is even possible to crash init
(and thus the whole system) if you wish, ptracer has full control.

The "if (pid == 1)" check in ptrace_get_task_struct() is killed, ptrace_attach
does the same check.

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

--- 25/kernel/ptrace.c~5_INIT_PTRACE	2008-03-16 17:22:04.000000000 +0300
+++ 25/kernel/ptrace.c	2008-03-16 18:33:02.000000000 +0300
@@ -160,6 +160,15 @@ int ptrace_may_attach(struct task_struct
 	return !err;
 }
 
+static int allow_ptrace_init;
+
+static int __init __allow_ptrace_init(char *str)
+{
+	allow_ptrace_init = 1;
+	return 1;
+}
+__setup("init_ptrace", __allow_ptrace_init);
+
 int ptrace_attach(struct task_struct *task)
 {
 	int retval;
@@ -168,7 +177,7 @@ int ptrace_attach(struct task_struct *ta
 	audit_ptrace(task);
 
 	retval = -EPERM;
-	if (task->pid <= 1)
+	if (unlikely(is_global_init(task)) && likely(!allow_ptrace_init))
 		goto out;
 	if (same_thread_group(task, current))
 		goto out;
@@ -518,12 +527,6 @@ struct task_struct *ptrace_get_task_stru
 {
 	struct task_struct *child;
 
-	/*
-	 * Tracing init is not allowed.
-	 */
-	if (pid == 1)
-		return ERR_PTR(-EPERM);
-
 	read_lock(&tasklist_lock);
 	child = find_task_by_vpid(pid);
 	if (child)
--- 25/Documentation/kernel-parameters.txt~5_INIT_PTRACE	2008-02-15 16:58:12.000000000 +0300
+++ 25/Documentation/kernel-parameters.txt	2008-03-16 18:30:28.000000000 +0300
@@ -803,6 +803,8 @@ and is between 256 and 4096 characters. 
 			Run specified binary instead of /sbin/init as init
 			process.
 
+	init_ptrace	[KNL] Allows to ptrace init.
+
 	initcall_debug	[KNL] Trace initcalls as they are executed.  Useful
 			for working out where the kernel is dying during
 			startup.


             reply	other threads:[~2008-03-23 13:47 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-23 13:51 Oleg Nesterov [this message]
2008-03-24 16:01 ` Pavel Machek
2008-03-24 16:40   ` Oleg Nesterov
2008-03-24 22:39     ` Pavel Machek
2008-03-24 23:04       ` Oleg Nesterov
2008-03-24 23:09         ` Pavel Machek
2008-03-24 23:18           ` Oleg Nesterov
2008-03-24 23:26             ` Andrew Morton
2008-03-24 23:38               ` Oleg Nesterov
2008-03-25 12:03         ` Stephen Smalley
2008-03-25 13:40           ` Serge E. Hallyn
2008-03-25 14:37             ` Stephen Smalley
2008-03-25 18:06               ` Serge E. Hallyn
2008-03-25 19:07                 ` Herbert Poetzl
2008-03-25 21:55                 ` Pavel Machek
2008-03-26 15:31                   ` Andrew Morgan
2008-03-26 15:47                 ` Pavel Emelyanov
2008-03-24 22:29 ` Andrew Morton
2008-03-24 22:56   ` Oleg Nesterov
2008-03-24 23:08     ` Andrew Morton
2008-03-24 23:29       ` Oleg Nesterov
2008-03-25 10:00       ` Andi Kleen
2008-03-25 14:16         ` Krzysztof Halasa
2008-03-25 14:22           ` Andi Kleen
2008-03-25 14:30             ` Krzysztof Halasa
2008-03-25 14:35               ` Andi Kleen
2008-03-25 14:58                 ` Krzysztof Halasa
2008-03-25 14:47             ` Pavel Machek
2008-03-25 14:56               ` Andi Kleen
2008-03-25 17:42         ` Oleg Nesterov
2008-03-25 22:00         ` Roland McGrath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080323135110.GA294@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=roland@redhat.com \
    --cc=sds@tycho.nsa.gov \
    --cc=xemul@openvz.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®