proc-identity fix saved-set-ID update in setreuid and setregid#206
Conversation
| * *new* effective value (eff, which may be \ | ||
| * unchanged if e == -1). \ | ||
| */ \ | ||
| if (r != (uint32_t) -1 || eff != old_real) \ |
There was a problem hiding this comment.
Saved-set-ID condition drops the e != -1 guard.
This clause fires even when the effective ID is not being changed. When e == -1, eff still holds the current, unchanged effective ID; if it differs from the real ID, saved gets spuriously rewritten. So setreuid(-1, -1) on a process whose euid != ruid (e.g. ruid=1000, euid=0, suid=500 reached via a prior setresuid) clobbers the saved-set-ID even though a (-1, -1) call must be a no-op — contradicting this PR's own description table (setreuid(-1,-1) -> no change). This is privilege-relevant because uid_is_permitted/gid_is_permitted later key off emu_suid/emu_sgid.
Linux (kernel/sys.c __sys_setreuid, and the setreuid(2) man page) guards the second clause with euid != -1:
if (r != (uint32_t) -1 || (e != (uint32_t) -1 && eff != old_real))
saved = eff;The core intent of the PR — updating the saved-set-ID for setreuid(r, -1) — is correct; this is the one remaining defect, and it applies to setregid too via the shared macro.
There was a problem hiding this comment.
Fixed.
Modify DEFINE_SETRE macro to ensure that the saved-set-ID is only
updated by the effective ID change check when the new effective ID
is actually being set (i.e. e != -1).
This prevents setreuid(-1, -1) and setregid(-1, -1) from spuriously
clobbering the saved-set-ID when the current effective ID differs
from the real ID, matching Linux behavior.
…!= -1 Modify DEFINE_SETRE macro to ensure that the saved-set-ID is only updated by the effective ID change check when the new effective ID is actually being set (i.e. e != -1). This prevents setreuid(-1, -1) and setregid(-1, -1) from spuriously clobbering the saved-set-ID when the current effective ID differs from the real ID, matching Linux behavior. Fix sysprog21#140
|
Thank @doanbaotrung for contributing! |
sys: guard saved ID update in setreuid/setregid with euid/egid != -1
Modify DEFINE_SETRE macro to ensure that the saved-set-ID is only
updated by the effective ID change check when the new effective ID
is actually being set (i.e. e != -1).
This prevents setreuid(-1, -1) and setregid(-1, -1) from spuriously
clobbering the saved-set-ID when the current effective ID differs
from the real ID, matching Linux behavior.
Fix #140
Summary by cubic
Fix saved-set-ID handling in setreuid(2) and setregid(2) to match Linux rules. The saved ID now updates from the new effective ID after applying real/effective changes, including when only the real ID is set.
DEFINE_SETREto computesavedfrom the finaleffafter independently applyingrande.setreuid/setregidSaved ID is Not Updated on Real ID Change whene == -1#140.Written for commit a6d01d9. Summary will update on new commits.