All of lore.kernel.org
 help / color / mirror / Atom feed
* RLIMIT_NPROC check in set_user()
@ 2011-06-12 13:09 ` Vasiliy Kulikov
  0 siblings, 0 replies; 76+ messages in thread
From: Vasiliy Kulikov @ 2011-06-12 13:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: Linus Torvalds, Greg Kroah-Hartman, Andrew Morton,
	David S. Miller, Jiri Slaby, James Morris, Neil Brown,
	kernel-hardening

Hi,

I'd want to start a discussion of RLIMIT_NPROC check in set_user().
8 years ago set_user() was forced to check whether RLIMIT_NPROC limit is
reached, and, if so, abort set_user():

http://lkml.org/lkml/2003/7/13/226 [1]

Before the patch setuid() and similar were not able to fail because
of the reached limit.  So, some daemons running as root, dropping root
and switching uid/gid to some user were able to greatly exceed the limit
of processes running as this user.

The patch has solved this problem.  But it also unexpectedly created new
security threat.  Many poorly written programs running as root (or
owning CAP_SYS_ADMIN) don't expect setuid() failure and don't check its
return code.  If it fails, they still assume the uid has changed, but
actually it has not, which leads to very sad consequences.

In times of Linux 2.4 the initial problem (the lack of RLIMIT_NPROC
check) was solved in -ow patches by introducing the check in execve(),
not in setuid()/setuid() helpers as a process after dropping privileges
usually does execve() call.  While strictly speaking it is not a full
fix (it doesn't limit the number of not-execve'd but setuid'ed
processes) it works just fine for most of programs.

Another possible workaround is not moving the check from setuid() to
execve(), but sending SIGSEGV to the current process if setuid() failed [2].
This should solve the problem of poor programs and looks like not
breaking legitimate applications that handle setuid() failure as they
usually just print error message to the logfile/stderr and exit.  Also
as it is a horribly rare case (setuid() failure), more complicated code
path might be not tested very well.

I want to repeat myself: I don't consider checking RLIMIT_NPROC in
setuid() as a bug (a lack of syscalls return code checking is a real
bug), but as a pouring oil on the flames of programs doing poorly
written privilege dropping.  I believe the situation may be improved by
relatively small ABI changes that shouldn't be visible to normal
programs.

The first solution is reverting [1] and introducing similar check in
execve(), just like in -ow patch for 2.4.  The second solution is
applying [2] and sending SIGSEGV in case of privileges dropping failure.

I'd be happy to hear opinions about improving the fixes above or
alternative fixes.

Related references:
[1] - http://lkml.org/lkml/2003/7/13/226
[2] - https://lkml.org/lkml/2006/8/19/129 

Thanks,

-- 
Vasiliy

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

end of thread, other threads:[~2011-07-29  8:21 UTC | newest]

Thread overview: 76+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-12 13:09 RLIMIT_NPROC check in set_user() Vasiliy Kulikov
2011-06-12 13:09 ` [kernel-hardening] " Vasiliy Kulikov
2011-07-06 17:36 ` Vasiliy Kulikov
2011-07-06 17:36   ` [kernel-hardening] " Vasiliy Kulikov
2011-07-06 18:01   ` Linus Torvalds
2011-07-06 18:01     ` [kernel-hardening] " Linus Torvalds
2011-07-06 18:59     ` Vasiliy Kulikov
2011-07-07  7:56       ` Vasiliy Kulikov
2011-07-07  8:19         ` Vasiliy Kulikov
2011-07-12 13:27           ` [PATCH] move RLIMIT_NPROC check from set_user() to do_execve_common() Vasiliy Kulikov
2011-07-12 13:27             ` [kernel-hardening] " Vasiliy Kulikov
2011-07-12 21:16             ` Linus Torvalds
2011-07-12 21:16               ` [kernel-hardening] " Linus Torvalds
2011-07-12 23:14               ` NeilBrown
2011-07-12 23:14                 ` [kernel-hardening] " NeilBrown
2011-07-13  6:31                 ` Solar Designer
2011-07-13  6:31                   ` [kernel-hardening] " Solar Designer
2011-07-13  7:06                   ` NeilBrown
2011-07-13  7:06                     ` [kernel-hardening] " NeilBrown
2011-07-13 20:46                     ` Linus Torvalds
2011-07-13 20:46                       ` [kernel-hardening] " Linus Torvalds
2011-07-14  0:11                       ` James Morris
2011-07-14  0:11                         ` [kernel-hardening] " James Morris
2011-07-14  1:27                         ` NeilBrown
2011-07-14  1:27                           ` [kernel-hardening] " NeilBrown
2011-07-14 15:06                           ` Solar Designer
2011-07-14 15:06                             ` [kernel-hardening] " Solar Designer
2011-07-15  3:30                             ` NeilBrown
2011-07-15  3:30                               ` [kernel-hardening] " NeilBrown
2011-07-15  5:35                               ` Willy Tarreau
2011-07-15  5:35                                 ` [kernel-hardening] " Willy Tarreau
2011-07-15  6:31                               ` Vasiliy Kulikov
2011-07-15  7:06                                 ` NeilBrown
2011-07-15  7:06                                   ` NeilBrown
2011-07-15  7:38                                   ` Vasiliy Kulikov
2011-07-15 13:04                                     ` Solar Designer
2011-07-15 13:04                                       ` [kernel-hardening] " Solar Designer
2011-07-15 13:58                                     ` Stephen Smalley
2011-07-15 15:26                                       ` Vasiliy Kulikov
2011-07-15 19:54                                         ` Stephen Smalley
2011-07-21  4:09                                           ` NeilBrown
2011-07-21 12:48                                             ` Solar Designer
2011-07-21 18:21                                               ` Linus Torvalds
2011-07-21 19:39                                                 ` [kernel-hardening] " Solar Designer
2011-07-25 17:14                                                   ` Vasiliy Kulikov
2011-07-25 17:14                                                     ` [kernel-hardening] " Vasiliy Kulikov
2011-07-25 23:40                                                     ` Solar Designer
2011-07-26  0:47                                                       ` NeilBrown
2011-07-26  1:16                                                         ` Solar Designer
2011-07-26  4:11                                                           ` NeilBrown
2011-07-26 14:48                                                             ` [patch v2] " Vasiliy Kulikov
2011-07-26 14:48                                                               ` [kernel-hardening] " Vasiliy Kulikov
2011-07-27  2:15                                                               ` NeilBrown
2011-07-27  2:15                                                                 ` [kernel-hardening] " NeilBrown
2011-07-29  7:07                                                                 ` Vasiliy Kulikov
2011-07-29  8:06                                                               ` Vasiliy Kulikov
2011-07-29  8:06                                                                 ` [kernel-hardening] " Vasiliy Kulikov
2011-07-29  8:11                                                                 ` [patch v3] " Vasiliy Kulikov
2011-07-29  8:11                                                                   ` [kernel-hardening] " Vasiliy Kulikov
2011-07-29  8:17                                                                   ` James Morris
2011-07-29  8:17                                                                     ` [kernel-hardening] " James Morris
2011-07-24 14:32                                               ` [kernel-hardening] [PATCH] " Solar Designer
2011-07-24 18:02                                                 ` Vasiliy Kulikov
2011-07-14  1:30                         ` KOSAKI Motohiro
2011-07-14  1:30                           ` [kernel-hardening] " KOSAKI Motohiro
2011-07-13  5:36             ` KOSAKI Motohiro
2011-07-13  5:36               ` [kernel-hardening] " KOSAKI Motohiro
2011-07-14 15:22             ` [kernel-hardening] " Solar Designer
2011-07-14 15:55               ` Vasiliy Kulikov
2011-07-11 16:59       ` [kernel-hardening] RLIMIT_NPROC check in set_user() Solar Designer
2011-07-11 18:56         ` Vasiliy Kulikov
2011-07-13  9:48           ` Solar Designer
2011-07-14 14:15             ` Solar Designer
2011-07-14 14:27               ` Vasiliy Kulikov
2011-07-14 15:14                 ` Solar Designer
2011-07-14 16:31                   ` [kernel-hardening] compile time warnings in libc for setuid() unused result (was: RLIMIT_NPROC check in set_user()) Vasiliy Kulikov

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.