[lkml]   [2001]   [Jun]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectSysRq bug for tErm and kIll with init
Good evening,

The problem is annoying, the fix is trivial.
I am not subscribed to the list, so PLEASE CC ME when replying.


Magic SysRq behaves improperly with tErm and kIll in regards to how it
deals with init. killalL is fine (ignoring the 0x8000 "Ugly hack" :)


When you use these features of SysRq, the kernel is supposed to send a
signal to all processes except init. Well in reality the kernel sends a
signal to "all" processes including init. The reason nobody has ever
noticed this is that sysvinit doesn't do anything on SIGTERM, and the
kernel won't kill pid 1.

Affected kernels:

All current. This is present in both 2.2.19 and 2.4.6-pre1 kernels. I
didn't check 2.0.x, but i believe 2.0.x lacked the magic sysrq hack

$Id: sysrq.c,v 1.15 1998/08/23 14:56:41 mj Exp $


line 47 in 2.4.6-pre1

// -- Evil code --
for_each_task(p) {
if (p->mm) { /* Not swapper nor kernel thread */
if (p->pid == 1 && even_init) /* Ugly hack to kill init */
p->pid = 0x8000;
force_sig(sig, p);
// --end--

So what happens is if send_sig_all is supposed to kill init then p->pid is
set to 0x8000. This is bad, but it works fine so who really cares. Now,
if even_init is 0 (like with tErm and kIll), p->pid is still 1 when
force_sig() is called. If p->pid is 1 and even_init is 0, nothing should
be done.

// -- Fixed code --
for_each_task(p) {
if (p->mm) { /* Not swapper nor kernel thread */
if (p->pid == 1 && even_init) /* Ugly hack to kill init */
p->pid = 0x8000;
if (p->pid != 1)
force_sig(sig, p);
// --end--

Amazing what 1 line of code fixes, isn't it?

How the problem was found:

The busybox ( init reboots when it sees SIGTERM :).

Since this is a 1 line fix I'd like to see it go into the kernel soon,
maybe even for the 2.4.6-pre2 kernel. I don't want to sound
like a jerk, but it would be cool if I was listed at the top of
sysrq.c for submitting a bugfix or something =].

Remember to cc me when replying.

Adam Slattery
Sunrise Linux Development Team

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 12:54    [W:0.025 / U:0.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site