Repository navigation
Reject a closed --userns-block-fd while parsing arguments - #831
Open
sarankumar1325 wants to merge 1 commit into
Open
sarankumar1325 wants to merge 1 commit into
sarankumar1325 wants to merge 1 commit into
Conversation
If the descriptor given to --userns-block-fd isn't open, its number can be reused for child_wait_fd or, with --json-status-fd, the read end of setup_finished_pipe. The parent then closes or blocks on its own descriptor and the parent and child wait for each other forever. Check the descriptor with fcntl(F_GETFD) when the option is parsed, before bwrap opens any descriptors of its own, and fail with "Invalid fd: N: Bad file descriptor". Fixes: containers#826 Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
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.
Fixes #826.
If the descriptor passed to
--userns-block-fdis closed, its number can be reused for bwrap's ownchild_wait_fdeventfd or, with--json-status-fd, the read end ofsetup_finished_pipe. The parent then reads from or closes its own descriptor (bubblewrap.c, theopt_userns_block_fdblock after the clone), and parent and child wait for each other forever.This checks the descriptor with
fcntl (fd, F_GETFD)when the option is parsed. That's beforemainopens/procor any eventfd/pipe, so a closed number can't be confused with one of ours. A closed descriptor now fails withbwrap: Invalid fd: N: Bad file descriptor, the check suggested in the issue.Testing (built with meson on Linux, unprivileged user namespaces):
timeoutkills it (rc 124). With this change each exits 1 withInvalid fd: 4: Bad file descriptor/Invalid fd: 5: Bad file descriptor.--userns-block-fd 42with fd 42 closed must fail with that message. It fails on main (bwrap fails with a different error) and passes here.meson test -C _build: test-utils, test-run.sh, test-specifying-pidns.sh, test-specifying-userns.sh and test-sandbox.py pass. test-seccomp.py is skipped (not available on this box).I only changed
--userns-block-fd, because that's where a reused descriptor makes bwrap wait on itself. The other descriptor options (--block-fd,--sync-fd,--info-fd, ...) aren't validated at parse time either. I can add the same check there if you'd like that.I used an AI assistant for this change and reviewed the code and tests myself.