PDA

View Full Version : how to prevent a fork bomb


nbari
February 24th, 2009, 08:41
I have just installed FreeBSD 7.1 amd64, created a jail and inside the jail executed the following code:

#include <stdio.h> int main() { while(1) fork(); }

gcc -o fork forc.c

$./fork

after few seconds the server stop responding and the load average increased a lot:

977.85 527.55 311.05

on the console i got lot of this:

maxproc limit exceeded by uid 1001, please see tuning(7) and login.conf(5).
maxproc limit exceeded by uid 1001, please see tuning(7) and login.conf(5).
maxproc limit exceeded by uid 1001, please see tuning(7) and login.conf(5).
maxproc limit exceeded by uid 1001, please see tuning(7) and login.conf(5).


Any good hints/tips on how to avoid this on a production server ? I pretend to give ssh to many users and would like to avoid this kind of problems.


thanks in advance

SirDice
February 24th, 2009, 09:24
AFAIK you can never prevent someone from running a fork bomb. You can however limit the effects by setting the user's limits in such a way a normal user can never take up all the resources.

lme@
February 24th, 2009, 12:01
See maxproc in /etc/login.conf and don't forget to run cap_mkdb /etc/login.conf after changing the file.