proc allow root and fakeroot guests to switch to any UID/GID#217
Conversation
b484b26 to
5facada
Compare
| { \ | ||
| uint32_t old_real = real; \ | ||
| if (r != (uint32_t) -1 && r != real && r != eff) \ | ||
| if (r != (uint32_t) -1 && r != real && r != eff && !perm_fn(r)) \ |
There was a problem hiding this comment.
setreuid/setregid's real-ID (r) check now falls back to perm_fn(r), which for unprivileged callers also accepts the saved ID via uid_is_permitted/gid_is_permitted. Real Linux setreuid(2)/setregid(2) restrict the real-ID argument to {current real, current effective} only — saved ID is only valid there via setresuid/setresgid.
Verified against a real Linux kernel (aarch64, 7.0.5): after setresuid(1000,1000,0) (drop euid, keep suid=0), setreuid(0,-1) returns EPERM on Linux but succeeds here, letting an unprivileged process restore its real UID through a call a real kernel would reject. Suggest a narrower permission check for r (real/effective only, bypassed when privileged) instead of reusing uid_is_permitted/gid_is_permitted as-is.
| EXPECT_TRUE(rc > 0 && (mask & 1), "CPU0 not in mask"); | ||
| } | ||
|
|
||
| if (expected_id == 0) { |
There was a problem hiding this comment.
These root-only assertions never run in CI: test-credentials isn't in tests/manifest.txt (not part of make check), test-matrix.sh invokes it without --fakeroot (default guest UID 1000), and it's listed in QEMU_SKIP for the real-root qemu lane — so expected_id == 0 is unreachable everywhere.
Running it manually with --fakeroot fails 7/27 cases: the earlier setuid(other)/setgid(other) root-branch calls (lines 73/156) now permanently drop identity to 1000 per this PR's own "reset all three fields" fix, but the later setfsuid/setfsgid/getgroups assertions still assume the stale expected_id == 0 identity. Please wire --fakeroot into a test runner so this doesn't silently bit-rot, and fix the stale-identity assumption in those later checks.
|
I have addressed both review items:
|
Guest processes running as root (effective UID 0) or in fakeroot mode should have the privilege to change their UID or GID to any value. Previously, elfuse restricted UID/GID changes strictly to the currently configured active credentials (emu_uid, emu_euid, etc.), aborting privilege-dropping calls with EPERM. We now permit any UID/GID switches in uid_is_permitted() and gid_is_permitted() if the guest process has effective UID 0 or fakeroot is active. Fix sysprog21#190
5facada to
e39d92f
Compare
Guest processes running as root (effective UID 0) or in fakeroot mode should have the privilege to change their UID or GID to any value. Previously, elfuse restricted UID/GID changes strictly to the currently configured active credentials (emu_uid, emu_euid, etc.), aborting privilege-dropping calls with EPERM.
We now permit any UID/GID switches in uid_is_permitted() and gid_is_permitted() if the guest process has effective UID 0 or fakeroot is active.
Fix #190
Summary by cubic
Allow root (euid 0) and fakeroot guests to switch to any UID/GID; privileged setuid/setgid now reset real, effective and saved IDs, and setreuid/setregid may change the real ID, matching Linux and avoiding EPERM when dropping privileges. Fixes #190.
Written for commit e39d92f. Summary will update on new commits.