public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Forking shell bombs
@ 2003-07-08 18:45 Ryan Underwood
  2003-07-08 18:55 ` Charles Cazabon
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Ryan Underwood @ 2003-07-08 18:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: witwerg


Hi,

:(){ :|:&};:

Paste that into bash and watch linux die. (2.4.21 stock)

I've seen some methods of dealing with infinitely forking processes, but
short of solving the Halting Problem I doubt we will ever find a perfect
solution to _preventing_ them.  So I had a few ideas that might help an
admin _deal_ with a fork storm when it is occurring so that the S-U-B
approach can be avoided.

I also found it interesting that alt-sysrq-S took about 5 minutes to
complete the sync.  Is there some sort of priority issue there?  I would
think that kernel operations should forget about all the little annoying
processes going crazy.  Also, eventually, the OOM killer started killing
off stuff, but I noticed that it would repeatedly attempt to kill the
same pid, such as gpm's pid, up to 10 times or so.  Was it not getting
enough CPU time to die, or something?

Anyway, here are my half-baked ideas, maybe someone else has more
suggestions:

1) Alt-SysRq-<x>- then type the name of a process and hit enter.  All
processes matching this name are killed.  Drawback -- if you use this to
kill e.g. bash, all your login shells will die too, putting a desktop
user back at a login prompt.  This is ok for servers, not for desktops.
This would solve shell bombs but not compiled bombs -- a process would
just overwrite argv[0] after it forks with random gibberish to defeat
it.

2) Alt-SysRq-<x> - Kill all processes that share the most popular
process size in the system table.  This way even if the name is changed,
if there is a process making infinite copies of itself, since all the
processes are carrying out the same action, they may have the same size.
This is speculation and may be wrong.

3) Alt-SysRq-<x> - Kill the process that has the most descendent
processes.   This could be made "smart" so that it only kills off the
part of the process tree where it really starts branching off, which
is a likely candidate for where the fork bomb started.

4) Since processes are created with increasing pids, a "killall" against
a fork bomb does nothing.  It simply starts killing processes matching
that name starting at the lowest pid.  But the processes which are
forking at higher pids eventually wrap around and get lower pids again,
which makes you end up with a forkbomb ring buffer.  Not too effective
at getting rid of the problem.

What about some sort of reverse killall, or a killall with specific
capabilities tailored to taking out fork bombs?  My roommate suggested
perhaps a "killall-bomb" may be in order.  A killall that forks
infinitely just like the bomb does, but also works to kill off the bomb
by filling up the process table itself.  Eventually the predators should
exhaust their prey, and then expire themselves with nothing left to eat.

5) Alt-SysRq-<x> - Until this key combination is pressed again, when a
process tries to fork(), kill it instead.  After a couple seconds, all
the forking annoyances should be gone.   You may lose some legitimate
processes who try to fork within that interval, but you will most likely
retain control of your system with little interruption. (?)

6) A fork flag in a process header?  Perhaps like the digital copy
flag to impose restrictions on consumer devices, a process should only
be allowed to fork a set number of times before any further fork returns
-1.

When I am in sysadmin mode, the very last thing on earth I want to do is
admit defeat to errant programs running on my system.  Perhaps the Linux
kernel can be made more resilient to fork bomb behavior in the first
place, but if not, it would certainly help to be able to take care of
the problem once it is already happening, aside from a punch of the reset
button.

Comments appreciated!

See ya,

-- 
Ryan Underwood, <nemesis at icequake.net>, icq=10317253

^ permalink raw reply	[flat|nested] 25+ messages in thread
[parent not found: <20030708193401.24226.95499.Mailman@lists.us.dell.com>]
* RE: Forking shell bombs
@ 2003-07-08 22:26 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 25+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-07-08 22:26 UTC (permalink / raw)
  To: Max Valdez, system_lists, kernel


> From: Max Valdez [mailto:maxvalde@fis.unam.mx]
>
> I set the ulimit -u 1791
> and the box keeps running(2.4.20-gentoo-r5) , but we still need the
> problem corrected, any other user can run ther DOS and crash the box, is
> there any way to set ulimits for all users fixed ??, not by sourcein a
> bashrc or something like that ?? because the user can delete the line on
> .bashrc and thats it

/etc/profile. 

This is an admin/distro problem.

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own (and my fault)

^ permalink raw reply	[flat|nested] 25+ messages in thread
* Re: Forking shell bombs
@ 2003-07-09 11:05 Arvind Kandhare
  0 siblings, 0 replies; 25+ messages in thread
From: Arvind Kandhare @ 2003-07-09 11:05 UTC (permalink / raw)
  To: linux-kernel

The problem can be attacked in two steps:

1. Stop new forks from being created
2. Kill the process causing the forks

The current ulimit implementation, afaik, can only control the
processes which will be created from the current moment onwards.
Ther processes which are already started will continue creating forks.
New processes created by the fork wil have this limit.

Basically it does not ensure that first step is completely executed.
So if your rate of killing is less than the processes being created and
resources are exausted, your system hangs.

There was a RFC patch  "[RFC][PATCH 2.5.70] Dynamically tunable
maxusers, maxuprc and max_pt_cnt" posted on 2003-06-06. It implements
maxuprc (maxuprc: maximum number of processes per user) as a dynamic tunable
parameter. It can be useful to overcome this problem. By setting maxuprc to a
very low value, new creation of the process is stopped. Then root can kill ('cos
this limit is not applicable to root) the erring processes.
There is no race against time as there is no chance of new process getting created once
this value is reduced.

cheers ..
Arvind ...








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

end of thread, other threads:[~2003-07-13 14:03 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-08 18:45 Forking shell bombs Ryan Underwood
2003-07-08 18:55 ` Charles Cazabon
2003-07-08 22:01   ` Alan Cox
2003-07-08 19:23 ` jhigdon
2003-07-08 20:35 ` vlad
     [not found] <20030708193401.24226.95499.Mailman@lists.us.dell.com>
2003-07-08 20:28 ` Ryan Underwood
2003-07-08 20:37   ` vlad
2003-07-08 20:43   ` jhigdon
2003-07-08 21:25     ` Ryan Underwood
2003-07-08 22:43       ` Sir Ace
2003-07-09 15:07       ` David Ford
2003-07-09 21:10         ` Ryan Underwood
2003-07-13  9:10         ` Riley Williams
2003-07-13  9:40           ` Jan-Benedict Glaw
2003-07-13 14:17           ` Gene Heskett
2003-07-08 21:59     ` system_lists
2003-07-08 17:18       ` Max Valdez
2003-07-08 22:25         ` Alan Cox
2003-07-08 22:26         ` Svein Ove Aas
2003-07-08 22:51     ` Ryan Underwood
2003-07-10 12:32     ` Luiz Capitulino
2003-07-08 23:05   ` Wakko Warner
2003-07-09 11:36   ` Michael Buesch
  -- strict thread matches above, loose matches on Subject: below --
2003-07-08 22:26 Perez-Gonzalez, Inaky
2003-07-09 11:05 Arvind Kandhare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox