]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
stdlib: Do not run tst-system subtest with RLIMIT_NPROC as root
authorFlorian Weimer <fweimer@redhat.com>
Sat, 24 Jan 2026 09:29:22 +0000 (10:29 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Sat, 24 Jan 2026 09:29:22 +0000 (10:29 +0100)
RLIMIT_NPROC is typically ignored by root users with capabilities.

Reviewed-by: Collin Funk <collin.funk1@gmail.com>
stdlib/tst-system.c

index d387ef40fc3761c4c019490473f96c82d1a23e2b..0c560fe1ffc064754898172f612c4e18c4e4a3a3 100644 (file)
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <signal.h>
 #include <paths.h>
+#include <pwd.h>
 #include <sys/resource.h>
 
 #include <support/capture_subprocess.h>
@@ -196,6 +197,19 @@ do_test (void)
   }
 
   {
+    /* RLIMIT_NPROC is not enforced for root.  Switch to user nobody
+       if it exists.  */
+    if (getuid () == 0)
+      {
+       struct passwd *pw = getpwnam ("nobody");
+       if (pw == NULL)
+         FAIL_UNSUPPORTED ("RLIMIT_NPROC test skipped: "
+                           "cannot switch to user nobody");
+       if (setgid (pw->pw_gid) != 0 || setuid (pw->pw_uid) != 0)
+         FAIL_UNSUPPORTED ("RLIMIT_NPROC test skipped: "
+                           "cannot switch to user nobody: %m");
+      }
+
     struct rlimit rlimit_orig, rlimit_new;
 
     if (getrlimit (RLIMIT_NPROC, &rlimit_orig) != 0)