Skip to contentSkip to conversation

evading ulimits

DISCUSSION John Richard Moser 3 participants 6 messages Dec 22, 2006 – Dec 24, 2006

lore
Share & tools
lore
#0 lore raw

I've set up some stuff on my box where /etc/security/limits.conf contains the following:

@users          soft    nproc           3072
@users          hard    nproc           4096

I'm in group users, and a simple fork bomb is easily quashed by this:

bluefox@icebox:~$ :(){ :|:; };:
bash: fork: Resource temporarily unavailable
Terminated

Oddly enough, trying this again and again yields the same results; but, I can kill the box (eventually; about 1 minute in I managed to /exec killall -9 bash from x-chat, since I couldn't get a new shell open) with the below:

bluefox@icebox:~$ :(){ :|:|:; };:

How exactly does the ulimit work? Why do I seem to be able to evade limits on maximum number of processes by doing a bigger fork bomb? I would have thought that the above would have terminated much sooner, since it was spawning x^3 processes instead of x^2 for iteration x and should have hit 4096 a lot sooner.

Signature · 4 lines
    We will enslave their women, eat their children and rape their
    cattle!
             -- Bosc, Evil alien overlord from the fifth dimension
Anti-Spam:  https://bugzilla.mozilla.org/show_bug.cgi?id=229686
#1 lore raw
Quoted 9 lines

I've set up some stuff on my box where /etc/security/limits.conf contains the following:

@users          soft    nproc           3072
@users          hard    nproc           4096

I'm in group users, and a simple fork bomb is easily quashed by this:

Quoted 8 lines
bluefox@icebox:~$ :(){ :|:; };:
bash: fork: Resource temporarily unavailable
Terminated

Oddly enough, trying this again and again yields the same results; but, I can kill the box (eventually; about 1 minute in I managed to /exec killall -9 bash from x-chat, since I couldn't get a new shell open) with the below:

Note that trying to kill all shells is a race between killing them all first and them spawning new ones everytime. To stop fork bombs, use killall -STOP first, then kill them.

	-`J'
#2 lore raw
Quoted 12 lines · Jan Engelhardt
Quoted 12 lines

I've set up some stuff on my box where /etc/security/limits.conf contains the following:

@users          soft    nproc           3072
@users          hard    nproc           4096

I'm in group users, and a simple fork bomb is easily quashed by this:

bluefox@icebox:~$ :(){ :|:; };:
bash: fork: Resource temporarily unavailable
Terminated
Quoted 9 lines
Quoted 4 lines

Oddly enough, trying this again and again yields the same results; but, I can kill the box (eventually; about 1 minute in I managed to /exec killall -9 bash from x-chat, since I couldn't get a new shell open) with the below:

Note that trying to kill all shells is a race between killing them all first and them spawning new ones everytime. To stop fork bombs, use killall -STOP first, then kill them.

Yes I know; the point, though, is that they should die automatically when the process count hits 4096. They do with the first fork bomb; they keep growing with the second, well past what they should.

Quoted 2 lines
	-`J'
Signature · 4 lines
    We will enslave their women, eat their children and rape their
    cattle!
             -- Bosc, Evil alien overlord from the fifth dimension
Anti-Spam:  https://bugzilla.mozilla.org/show_bug.cgi?id=229686
#3 lore raw
Quoted 15 lines · John Richard Moser
Quoted 12 lines · Jan Engelhardt
Quoted 12 lines

I've set up some stuff on my box where /etc/security/limits.conf contains the following:

@users          soft    nproc           3072
@users          hard    nproc           4096

I'm in group users, and a simple fork bomb is easily quashed by this:

bluefox@icebox:~$ :(){ :|:; };:
bash: fork: Resource temporarily unavailable
Terminated
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Oddly enough, trying this again and again yields the same results; but, I can kill the box (eventually; about 1 minute in I managed to /exec killall -9 bash from x-chat, since I couldn't get a new shell open) with the below:

Note that trying to kill all shells is a race between killing them all firs

t

Quoted 7 lines
Quoted 3 lines

and them spawning new ones everytime. To stop fork bombs, use killall -STOP first, then kill them.

Yes I know; the point, though, is that they should die automatically when the process count hits 4096. They do with the first fork bomb; they keep growing with the second, well past what they should.

This may be another timing issue - note that in the first case, you have :|:
which forks off 2 processes with a pipe in between. If the head process fails, the second probably won't get started by the shell *either*. In the second case, you launch *3*, and it's possible that the head process will start and live long enough to re-fork before a later one in the pipe gets killed.

Does the behavior change if you use 4095 or 4097 rather than 4096? I'm willing to bet that your system exhibits semi-predictable behavior regarding the order the processes get created, and *which* process gets killed makes a difference regarding how fast the process tree gets pruned.

Do you have any good evidence that the second version manages to create much more than 4096 processes, rather than just being more exuberant about doing so? I'm guessing that in fact, in both cases the number of processes ends up pseudorandomly oscillating in the 4090-4906 range, but the exact order of operations makes the rate and impact different in the two cases.

#4 lore raw
Quoted 34 lines · [email protected] wrote:
Quoted 14 lines · John Richard Moser
Quoted 12 lines · Jan Engelhardt
Quoted 12 lines

I've set up some stuff on my box where /etc/security/limits.conf contains the following:

@users          soft    nproc           3072
@users          hard    nproc           4096

I'm in group users, and a simple fork bomb is easily quashed by this:

bluefox@icebox:~$ :(){ :|:; };:
bash: fork: Resource temporarily unavailable
Terminated
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Oddly enough, trying this again and again yields the same results; but, I can kill the box (eventually; about 1 minute in I managed to /exec killall -9 bash from x-chat, since I couldn't get a new shell open) with the below:

Note that trying to kill all shells is a race between killing them all firs

t

Quoted 6 lines
Quoted 3 lines

and them spawning new ones everytime. To stop fork bombs, use killall -STOP first, then kill them.

Yes I know; the point, though, is that they should die automatically when the process count hits 4096. They do with the first fork bomb; they keep growing with the second, well past what they should.

This may be another timing issue - note that in the first case, you have :|:
which forks off 2 processes with a pipe in between. If the head process fails, the second probably won't get started by the shell *either*. In the second case, you launch *3*, and it's possible that the head process will start and live long enough to re-fork before a later one in the pipe gets killed.

Quoted 5 lines

Does the behavior change if you use 4095 or 4097 rather than 4096? I'm willing to bet that your system exhibits semi-predictable behavior regarding the order the processes get created, and *which* process gets killed makes a difference regarding how fast the process tree gets pruned.

I will test this later (sleeping now)

Quoted 5 lines

Do you have any good evidence that the second version manages to create much more than 4096 processes, rather than just being more exuberant about doing so? I'm guessing that in fact, in both cases the number of processes ends up pseudorandomly oscillating in the 4090-4906 range, but the exact order of operations makes the rate and impact different in the two cases.

I haven't gathered evidence; I rather look for evidence that fork() is failing, like bash complaints. I get those in abundance in the first case; but see none in the second case.

Trying again, I can't reproduce the phenomena. It crashes out in 3 seconds. Either just weird that it ran for so long last time before I had to manually kill it off; or a race. I don't have sufficient data to decide.

Signature · 4 lines
    We will enslave their women, eat their children and rape their
    cattle!
             -- Bosc, Evil alien overlord from the fifth dimension
Anti-Spam:  https://bugzilla.mozilla.org/show_bug.cgi?id=229686
#5 lore raw
In reply to John Richard Moser
Quoted 9 lines · John Richard Moser
Quoted 4 lines · Jan Engelhardt

Note that trying to kill all shells is a race between killing them all first and them spawning new ones everytime. To stop fork bombs, use killall -STOP first, then kill them.

Yes I know; the point, though, is that they should die automatically when the process count hits 4096. They do with the first fork bomb; they keep growing with the second, well past what they should.

They don't just all die when you hit 4096. If you do nothing, 4096 +/- n will stay around.

	-`J'