]> granicus.if.org Git - sudo/commitdiff
Unlimit nproc on Linux systems where calling the setuid() family
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 27 Jan 2008 21:34:41 +0000 (21:34 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 27 Jan 2008 21:34:41 +0000 (21:34 +0000)
of syscalls causes the nroc resource limit to be checked.  The
limits will be reset by pam_limits.so when PAM is used.  In the
non-PAM case the nproc limit will remain unlimited but there doesn't
seem to be a way around that other than having sudo parse
/etc/security/limits.conf directly.

sudo.c

diff --git a/sudo.c b/sudo.c
index 39f71eb4f588b1fcec788528d1c47295361aec81..3e45c02cb3e055365e613b4e5cae3b1e483d27e1 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -1101,9 +1101,25 @@ static void
 initial_setup()
 {
     int miss[3], devnull = -1;
-#if defined(RLIMIT_CORE) && !defined(SUDO_DEVEL)
+#if defined(__linux__) || (defined(RLIMIT_CORE) && !defined(SUDO_DEVEL))
     struct rlimit rl;
+#endif
 
+#if defined(__linux__)
+    /*
+     * Unlimit the number of processes since Linux's setuid() will
+     * apply resource limits when changing uid and return EAGAIN if
+     * nproc would be violated by the uid switch.
+     */
+    rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
+    if (setrlimit(RLIMIT_NPROC, &rl)) {
+       if (getrlimit(RLIMIT_NPROC, &rl) == 0) {
+           rl.rlim_cur = rl.rlim_max;
+           (void)setrlimit(RLIMIT_NPROC, &rl);
+       }
+    }
+#endif /* __linux__ */
+#if defined(RLIMIT_CORE) && !defined(SUDO_DEVEL)
     /*
      * Turn off core dumps.
      */