Skip to content

Commit

Permalink
stress-set: reduce frequency of calls to stress_get_unused_uid
Browse files Browse the repository at this point in the history
This dominates the stressor run-time, so reduce it to 1 in 1024
bogo-loops.

Signed-off-by: Colin Ian King <[email protected]>
  • Loading branch information
ColinIanKing committed Dec 16, 2024
1 parent da62be5 commit a358880
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions stress-set.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ static int stress_set(stress_args_t *args)
const bool cap_sys_resource = stress_check_capability(SHIM_CAP_SYS_RESOURCE);
#if defined(HAVE_SETREUID)
const bool cap_setuid = stress_check_capability(SHIM_CAP_SETUID);
int bad_uid_count = 0;
#endif
#if defined(HAVE_GETPGID) && \
defined(HAVE_SETPGID)
Expand Down Expand Up @@ -284,15 +285,20 @@ static int stress_set(stress_args_t *args)
#if defined(HAVE_SETREUID)
VOID_RET(int, setreuid((uid_t)-1, (uid_t)-1));

/*
* Validate setreuid syscalls exercised to increase the current
* ruid and euid without CAP_SETUID capability cannot succeed
*/
if ((!cap_setuid) && (stress_get_unused_uid(&bad_uid) >= 0)) {
if (setreuid(bad_uid, bad_uid) == 0) {
pr_fail("%s: setreuid failed, did not have privilege to set "
"ruid and euid, expected -EPERM, instead got errno=%d (%s)\n",
args->name, errno, strerror(errno));
bad_uid_count++;
if (bad_uid_count > 1024) {
bad_uid_count = 0;

/*
* Validate setreuid syscalls exercised to increase the current
* ruid and euid without CAP_SETUID capability cannot succeed
*/
if ((!cap_setuid) && (stress_get_unused_uid(&bad_uid) >= 0)) {
if (setreuid(bad_uid, bad_uid) == 0) {
pr_fail("%s: setreuid failed, did not have privilege to set "
"ruid and euid, expected -EPERM, instead got errno=%d (%s)\n",
args->name, errno, strerror(errno));
}
}
}
#else
Expand Down

0 comments on commit a358880

Please sign in to comment.