vmm/builder: correctly handle invalid fd for serial console#570
Merged
jakecorrenti merged 1 commit intocontainers:mainfrom Mar 11, 2026
Merged
vmm/builder: correctly handle invalid fd for serial console#570jakecorrenti merged 1 commit intocontainers:mainfrom
jakecorrenti merged 1 commit intocontainers:mainfrom
Conversation
Collaborator
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly moves the serial console TTY setup logic inside the check for a valid file descriptor, preventing a panic when an invalid fd is provided. However, the implementation introduces a soundness issue by creating both a BorrowedFd and an owning File from the same raw file descriptor. This can lead to use-after-free bugs if not handled carefully. I've suggested a change to make the code safer by creating the File first and then borrowing from it, although this still relies on unsafe due to lifetime complexities.
9a7a36b to
407072b
Compare
Commit bf3f2bf ("builder: set raw mode for ttys on serial devices") added support for raw for TTYs on serial devices, but didn't seem to take into account that the provided 'input_fd' may be invalid -- a condition supported by code below that checks for positive values. As a result, we may run into a panic as part of BorrowedFd::borrow_raw()'s sanity checks. Fix this issue by massaging the code slightly. Signed-off-by: Daniel Müller <deso@posteo.net>
407072b to
f1e9d4f
Compare
dorindabassey
approved these changes
Mar 10, 2026
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.
Commit bf3f2bf ("builder: set raw mode for ttys on serial devices") added support for raw for TTYs on serial devices, but didn't seem to take into account that the provided 'input_fd' may be invalid -- a condition supported by code below that checks for positive values. As a result, we may run into a panic as part of BorrowedFd::borrow_raw()'s sanity checks.
Fix this issue by moving code around slightly.