Let a marked exec enter fakeroot mode - #268
Draft
doanbaotrung wants to merge 1 commit into
Draft
Conversation
doanbaotrung
marked this pull request as draft
August 3, 2026 16:45
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Fakeroot could only be armed before the first guest image ran, via --fakeroot or ELFUSE_FAKEROOT, so nothing a guest did afterwards could raise privilege. A guest shell had no equivalent of sudo: the one command that needs root forced the whole session to run as root. Add ELFUSE_FAKEROOT_EXEC, naming a single executable whose exec crosses into fakeroot. sys_execve compares the requested path against it before shebang resolution repoints the path at an interpreter, so a wrapper script elevates on its own path rather than on /bin/sh, and it matches either the guest path or the host path so the embedder can name the binary in whichever namespace it knows. The transition is committed alongside the setuid credential commit, past every failure path, so an exec that never happens leaves the caller unprivileged. It sets root ids and the process-wide gate, mirroring what proc_identity_init does for --fakeroot at startup, and reaches fork children through the --fakeroot argv forkipc already derives from that gate. With the variable unset, which is the default, no exec ever elevates. tests/test-fakeroot-exec.c re-execs itself as the marked path and covers the unprivileged start, the elevated exec, root surviving a fork into a fresh host process, the exec'ing parent keeping its own ids, and a copy of the same program at another path not elevating. The escape hatch is elfuse-only, so the qemu lane skips it. Fix sysprog21#265
doanbaotrung
force-pushed
the
fakeroot-exec
branch
from
August 4, 2026 00:08
3a65295 to
038b0f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fakeroot could only be armed before the first guest image ran, via --fakeroot or ELFUSE_FAKEROOT, so nothing a guest did afterwards could raise privilege. A guest shell had no equivalent of sudo: the one command that needs root forced the whole session to run as root.
Add ELFUSE_FAKEROOT_EXEC, naming a single executable whose exec crosses into fakeroot. sys_execve compares the requested path against it before shebang resolution repoints the path at an interpreter, so a wrapper script elevates on its own path rather than on /bin/sh, and it matches either the guest path or the host path so the embedder can name the binary in whichever namespace it knows.
The transition is committed alongside the setuid credential commit, past every failure path, so an exec that never happens leaves the caller unprivileged. It sets root ids and the process-wide gate, mirroring what proc_identity_init does for --fakeroot at startup, and reaches fork children through the --fakeroot argv forkipc already derives from that gate. With the variable unset, which is the default, no exec ever elevates.
tests/test-fakeroot-exec.c re-execs itself as the marked path and covers the unprivileged start, the elevated exec, root surviving a fork into a fresh host process, the exec'ing parent keeping its own ids, and a copy of the same program at another path not elevating. The escape hatch is elfuse-only, so the qemu lane skips it.
Fix #265
Summary by cubic
Let a marked exec opt into fakeroot so guests can start unprivileged and elevate a single command, like sudo. Fixes #265.
ELFUSE_FAKEROOT_EXECto name one executable whose exec enters fakeroot. Requires an absolute path (guest or host); exact string match only. Unset or invalid means no elevation./bin/sh.tests/test-fakeroot-exec.cto cover unprivileged start, marked exec reaching root, root surviving a fork, and non-matching spellings/copies not elevating. The QEMU lane skips this elfuse-only behavior.Written for commit 038b0f7. Summary will update on new commits.