Skip to content

Commit 413849e

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)
1 parent 63c7f58 commit 413849e

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
@@ -715,9 +715,16 @@ TEST(setpriority_closest) {
715715
assert_se(ERRNO_IS_PRIVILEGE(errno));
716716
full_test = false;
717717
} else {
718-
assert_se(setresgid(GID_NOBODY, GID_NOBODY, GID_NOBODY) >= 0);
719-
assert_se(setresuid(UID_NOBODY, UID_NOBODY, UID_NOBODY) >= 0);
720-
full_test = true;
718+
/* However, if the hard limit was above 30, setrlimit would succeed unprivileged, so
719+
* check if the UID/GID can be changed before enabling the full test. */
720+
if (setresgid(GID_NOBODY, GID_NOBODY, GID_NOBODY) < 0) {
721+
assert_se(ERRNO_IS_PRIVILEGE(errno));
722+
full_test = false;
723+
} else if (setresuid(UID_NOBODY, UID_NOBODY, UID_NOBODY) < 0) {
724+
assert_se(ERRNO_IS_PRIVILEGE(errno));
725+
full_test = false;
726+
} else
727+
full_test = true;
721728
}
722729

723730
errno = 0;

0 commit comments

Comments
 (0)