fork bomb protection patch, 2.1.30

Ingo Molnar (mingo@pc5829.hil.siemens.at)
Sat, 29 Mar 1997 13:20:30 +0100 (MET)


i'm posting now from a kernel with the fork bomb patch enabled:

------------------------------------------------------------------->
pc5829:~/forkbomb$ cat bomb
bash: fork: Try again
pc5829:~/forkbomb$ cat bomb
#!/bin/bash

bomb &
bomb &

pc5829:~/forkbomb$ uptime
2:12pm up 28 min, 3 users, load average: 225.53, 169.94, 84.59
<------------------------------------------------------------------

the system is noticably slower, but it's still quite usable :) The patch
fixes other scheduling oddities as well, i hope it's the right thing ...

It's against 2.1.30, but it should work in 2.0 too.

-- mingo

--- linux-2.1.30_vanilla/kernel/fork.c Sun Jan 26 12:40:46 1997
+++ linux/kernel/fork.c Sat Mar 29 14:17:13 1997
@@ -292,7 +298,16 @@
/* ok, now we should be set up.. */
p->swappable = 1;
p->exit_signal = clone_flags & CSIGNAL;
- p->counter = current->counter >> 1;
+
+ /*
+ * "share" dynamic priority between parent and child, thus the
+ * total amount of dynamic priorities in the system doesnt change,
+ * more scheduling fairness. This is only important in the first
+ * timeslice, on the long run the scheduling behaviour is unchanged.
+ */
+ current->counter >>= 1;
+ p->counter = current->counter;
+
if(p->pid) {
wake_up_process(p); /* do this last, just in case */
} else {