runc: add CommandFile for fd-based binary execution#113
Draft
dmcgowan wants to merge 1 commit into
Draft
Conversation
Add Runc.CommandFile *os.File as a Linux-only alternative to Command. When set, every invocation executes the binary via /proc/self/fd/<n> rather than by filesystem path, which is semantically equivalent to execveat(fd, "", argv, env, AT_EMPTY_PATH): the binary is identified solely by its open file descriptor, so the original path need not remain accessible after the file is opened. The implementation adds finalizeCommand(), called from startCommand() just before cmd.Start(). It appends CommandFile to cmd.ExtraFiles (so Go's fork+exec inherits the fd) and sets cmd.Path to /proc/self/fd/<n>. The file is always appended last, so any pre-existing ExtraFiles keep their fd positions and --preserve-fds / --status-fd accounting is unaffected. Tests cover basic execution, execution after the binary path is unlinked (the core guarantee), and the fd numbering invariants. Signed-off-by: Derek McGowan <derek@mcg.dev>
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.
Add Runc.CommandFile *os.File as a Linux-only alternative to Command. When set, every invocation executes the binary via /proc/self/fd/ rather than by filesystem path, which is semantically equivalent to execveat(fd, "", argv, env, AT_EMPTY_PATH): the binary is identified solely by its open file descriptor, so the original path need not remain accessible after the file is opened.
The implementation adds finalizeCommand(), called from startCommand() just before cmd.Start(). It appends CommandFile to cmd.ExtraFiles (so Go's fork+exec inherits the fd) and sets cmd.Path to /proc/self/fd/. The file is always appended last, so any pre-existing ExtraFiles keep their fd positions and --preserve-fds / --status-fd accounting is unaffected.
Tests cover basic execution, execution after the binary path is unlinked (the core guarantee), and the fd numbering invariants.
Ideally in the future Go will support execveat and path resolution can be completely avoided in this case. Experimenting with this for Nerdbox, to avoid needing to have runc/crun available in the rootfs.