(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.
--
| Andrew Morton | Re: [PATCH 00/23] per device dirty throttling -v8 |
| Mariusz Kozlowski | [PATCH 02] kmalloc + memset conversion to kzalloc |
| Andi Kleen | [PATCH x86] [3/16] Turn irq debugging options into module params |
| Shawn Bohrer | Re: x86: 4kstacks default |
git: | |
| Sean | Re: VCS comparison table |
| Eric Wong | Re: [RFC] Git config file reader in Perl (WIP) |
| free cycle | How to Import a bitkeeper repo into git |
| Petko Manolov | git and binary files |
| Alex Thurlow | Router performance on OpenBSD and OpenBGPD |
| GVG GVG | ssh_exchange_identification: Connection closed by remote host |
| frantisek holop | nptd regression in 4.2 |
| Richard Stallman | Real men don't attack straw men |
| Matthew Dharm | Re: [RFC] Patch to option HSO driver to the kernel |
| David Miller | Re: 2.6.25-rc8: FTP transfer errors |
| Indan Zupancic | Re: Realtek 8111C transmit timed out |
| Julius Volz | [PATCH RFC 02/24] IPVS: Add genetlink interface implementation |
