Return EINVAL from F_DUPFD instead of asserting - #2768
Open
emkey1 wants to merge 1 commit into
Open
Conversation
fcntl(fd, F_DUPFD, -1) aborts ish. arg is a dword_t, so the guest's -1 arrives as 0xffffffff and is handed straight to f_install_start, where it narrows back to a negative fd_t and trips assert(start >= 0). Any guest program can take the emulator down with one syscall. Linux returns EINVAL when the starting fd is negative or at/above RLIMIT_NOFILE, so check both before installing. F_DUPFD_CLOEXEC takes the same argument and needed the same check.
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.
fcntl(fd, F_DUPFD, -1)aborts ish.argis adword_t, so the guest's-1arrives as0xffffffffand is handed straight tof_install_start, where it narrows back to a negativefd_tand tripsassert(start >= 0). Any guest program can take the emulator down with a single syscall:Linux returns
EINVALwhen the starting fd is negative or at/aboveRLIMIT_NOFILE, so this checks both before installing.F_DUPFD_CLOEXECtakes the same argument and needed the same check.Testing
Repro program run under
ish -f alpine, and the same binary run on real Linux (x86 Ubuntu) to confirm the expected behavior:-1 (Invalid argument)SIGABRTon the first call-1 (Invalid argument)Also ran a shell smoke test over the Alpine rootfs (directory walks,
/procreads, fork/exec churn, redirects, pipes) with no change in behavior.🤖 Generated with Claude Code