nixCraft Poll

Topics

How to: Prevent a fork bomb by limiting user process

Posted by Vivek Gite [Last updated: November 27, 2007]

Earlier, I wrote about fork bomb, few readers like to know about getting protection against such attacks:

How do I protect my system from a fork bomb under Linux?

Limiting user processes is important for running a stable system. To limit user process just add user name or group or all users to /etc/security/limits.conf file and impose process limitations.

Understanding /etc/security/limits.conf file

Each line describes a limit for a user in the form:
<domain> <type> <item> <value>
Where:

Login as the root and open configuration file:
# vi /etc/security/limits.conf
Following will prevent a "fork bomb":
vivek hard nproc 300
@student hard nproc 50
@faculty soft nproc 100
@pusers hard nproc 200

Above will prevent anyone in the student group from having more than 50 processes, faculty and pusers group limit is set to 100 and 200. Vivek can create only 300 process. Please note that KDE and Gnome desktop system can launch many process.

Save and close the file. Test your new system by dropping a form bomb:
$ :(){ :|:& };:

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. RuBiCK Says:

    Could you tell me what it’s the difference between hard and soft limits?

    People told me soft is like warning and hard is real max limit, but I’m not sure

  2. vivek Says:

    @RuBiCK,

    Yup, you are correct about soft and hard limit. For example, following will prevent anyone in the student group from having more than 50 processes, and a warning will be given at 30 processes.
    @student soft nproc 30
    @student hard nproc 50

    HTH

  3. yoooo Says:

    :) thanks for this mini howto

  4. Igor Says:

    Could you explain how does that form bomb work?

  5. JV Says:

    Is there a reason to limit core dump file sizes? I am usually in the process of doing so mainly because I don’t like to set anything to unlimited

  6. vivek Says:

    @Igor, see

    http://www.cyberciti.biz/faq/understanding-bash-fork-bomb/

    @JV,

    Limit disk space.

  7. mastrboy Says:

    is there a way to activate these settings on a running system? Currently i have not found any other solution that to reboot to make the settings active :(

    (using debian etch)

  8. MaoP Says:

    man ulimit
    google linux sysctl limit proccess

  9. sandoz Says:

    Actually soft limits work like hard limits except, that the user can change them up to the hard limit.

    Say:
    @student soft nproc 30
    @student hard nproc 50

    @students can run 30 process. After that starting processes will fail. But an
    ulimit -Su 50
    will make it possible for them to run 50 processes, in that shell until the next logout.

    To make changes work, the user has to logout and login again. All user already logged in are able to work as before.

    sandoz

  10. ATOzTOA Says:

    Tried the Fork BOmb… Worked perfectly :)

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.