Skip to content

Commit 27a2506

Browse files
dbnicholsonbluca
authored andcommitted
test-process-util: Handle unprivileged setrlimit success
Currently test_setpriority_closest assumes that setting RLIMIT_NICE to 30 will fail if the process is unprivileged. If it succeeds, it assumes that the process is privileged and setresuid and setresgid will succeed. However, if RLIMIT_NICE is already >= 30, then setrlimit will succeed even if the process is unprivileged. Guard against that by checking for permission errors in setresuid and setresgid and skipping the full test if so. Fixes #22896. (cherry picked from commit 9217255) (cherry picked from commit 413849e) (cherry picked from commit a052d11)
1 parent 8cd1283 commit 27a2506

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/test/test-process-util.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,16 @@ TEST(setpriority_closest) {
773773
assert_se(ERRNO_IS_PRIVILEGE(errno));
774774
full_test = false;
775775
} else {
776-
assert_se(setresgid(GID_NOBODY, GID_NOBODY, GID_NOBODY) >= 0);
777-
assert_se(setresuid(UID_NOBODY, UID_NOBODY, UID_NOBODY) >= 0);
778-
full_test = true;
776+
/* However, if the hard limit was above 30, setrlimit would succeed unprivileged, so
777+
* check if the UID/GID can be changed before enabling the full test. */
778+
if (setresgid(GID_NOBODY, GID_NOBODY, GID_NOBODY) < 0) {
779+
assert_se(ERRNO_IS_PRIVILEGE(errno));
780+
full_test = false;
781+
} else if (setresuid(UID_NOBODY, UID_NOBODY, UID_NOBODY) < 0) {
782+
assert_se(ERRNO_IS_PRIVILEGE(errno));
783+
full_test = false;
784+
} else
785+
full_test = true;
779786
}
780787

781788
errno = 0;

0 commit comments

Comments
 (0)