All of lore.kernel.org
 help / color / mirror / Atom feed
* [kernel-hardening] RLIMIT_NPROC DoS fix
@ 2012-06-12  9:38 Vasily Kulikov
  2012-06-13  0:22 ` [kernel-hardening] Re: [owl-dev] " Pavel Kankovsky
  0 siblings, 1 reply; 3+ messages in thread
From: Vasily Kulikov @ 2012-06-12  9:38 UTC (permalink / raw)
  To: owl-dev, kernel-hardening

Hi,

There is a problem with RLIMIT_NPROC patch:
http://www.openwall.com/lists/kernel-hardening/2011/06/12/9
http://www.openwall.com/lists/kernel-hardening/2011/08/08/2

As planned, it moves RLIMIT check from set_user() (set*uid()) stage to
fork()/execve() stage.  But the drawback is that now there is no RLIMIT
check at set_user().  It means that there are two bad cases:

1) a root process sometimes does setrlimit()+setuid(U)+execve()/fork().
In this case U can do kill(pid, SIGSTOP) each time just after setuid(U).
U may store unlimited number of processes this way.
(Spender has learned this way.)

2) there are nonroot users A and B.
A makes a binary ./loop which does setuid(A)+for(;;) {}
A does chmod u+s ./loop
B does 'while :; do ./loop &; done'


IOW, if there is a way one can produce unlimited number of processes at
atfer-setuid before-execve stage, one may DoS the system.

I don't see any fair way to fix that.  The way I see is using additional
limit which is used to kill overmultiplied processes.  E.g.:

set_user()
{
    ...
	if (atomic_read(&new_user->processes) >= rlimit(RLIMIT_NPROC) &&
			new_user != INIT_USER) {
		if (atomic_read(&new_user->processes) >= 2*rlimit(RLIMIT_NPROC) + 10) {
		    ...some ratelimited printk warning...
		    force_sig(SIGKILL, current);
		}
		current->flags |= PF_NPROC_EXCEEDED;
	} else {
		current->flags &= ~PF_NPROC_EXCEEDED;
    }
        
    ...
}

Yes, this is dirty.  Any thoughts about less dirty way?

-- 
Vasily

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

end of thread, other threads:[~2012-06-21  0:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-12  9:38 [kernel-hardening] RLIMIT_NPROC DoS fix Vasily Kulikov
2012-06-13  0:22 ` [kernel-hardening] Re: [owl-dev] " Pavel Kankovsky
2012-06-21  0:55   ` [kernel-hardening] " Solar Designer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.