Skip to content

Commit

Permalink
test-process-util: Handle unprivileged setrlimit success
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
dbnicholson authored and bluca committed Nov 9, 2023
1 parent 63c7f58 commit 413849e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/test/test-process-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,16 @@ TEST(setpriority_closest) {
assert_se(ERRNO_IS_PRIVILEGE(errno));
full_test = false;
} else {
assert_se(setresgid(GID_NOBODY, GID_NOBODY, GID_NOBODY) >= 0);
assert_se(setresuid(UID_NOBODY, UID_NOBODY, UID_NOBODY) >= 0);
full_test = true;
/* However, if the hard limit was above 30, setrlimit would succeed unprivileged, so
* check if the UID/GID can be changed before enabling the full test. */
if (setresgid(GID_NOBODY, GID_NOBODY, GID_NOBODY) < 0) {
assert_se(ERRNO_IS_PRIVILEGE(errno));
full_test = false;
} else if (setresuid(UID_NOBODY, UID_NOBODY, UID_NOBODY) < 0) {
assert_se(ERRNO_IS_PRIVILEGE(errno));
full_test = false;
} else
full_test = true;
}

errno = 0;
Expand Down

0 comments on commit 413849e

Please sign in to comment.