-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sandbox): add fd sandbox #857
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #857 +/- ##
==========================================
- Coverage 71.86% 71.31% -0.56%
==========================================
Files 23 23
Lines 3064 3134 +70
==========================================
+ Hits 2202 2235 +33
- Misses 862 899 +37 ☔ View full report in Codecov by Sentry. |
bf3f183
to
2bbae9b
Compare
Have you also considered the special file descriptors (1,2 & 3) that are opened on the hypervisor per default? |
In my bruteforcing attempts to get this to work, I think I completely forgot about
|
I presume that I'll probably have to take note of |
All checks pass. This change should probably be manually tested on macOS too, just to be sure. I will leave the commit squashing for later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this change is somewhat complex, I left a few remarks addressing some of its behavior as well as specific points for review, so as to prevent churn / bugs.
@@ -171,8 +190,7 @@ pub fn write<B: VirtualizationBackend>( | |||
) | |||
.unwrap(); | |||
|
|||
if syswrite.fd == 1 { | |||
// fd 0 is stdout | |||
if syswrite.fd == 1 || syswrite.fd == 2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not 1000% sure whether this is sane.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine, at least until we have separate handling for stderr
src/hypercall.rs
Outdated
pub fn close(sysclose: &mut CloseParams, file_map: &mut UhyveFileMap) { | ||
if file_map.get_fd_presence(sysclose.fd.into_raw_fd()) { | ||
unsafe { sysclose.ret = libc::close(sysclose.fd) } | ||
if sysclose.ret >= 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is allowing close
on the fd
s 0
, 1
, 2
violating isolation? Should we handle this in a different way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this comment: https://stackoverflow.com/a/4973065/6551168
So it might be ok for the kernel to close them, but as uhyve still needs them, I think ignoring this close is the way to go.
823ea51
to
5802165
Compare
This extends UhyveFileMap with a sandbox mapping file descriptors to maps, so as to prevent the opening of file descriptors that belong to Uhyve (or to that of other VMs, when Uhyve exposes such functionality to the user). There is no Linux equivalent of unlink that is capable of removing files using a file descriptor. We did not want to keep a file descriptor of an unlinked file available to the VM. Therefore, we used a BiMap that associate fds to guest paths and guest paths to fds (instead of a simple container containing fds).
If an unlink takes place while the file is open, this would make the subsequent close fail, as soon as the file object goes out of scope and gets dropped. We introduced a HashSet that temporarily caches such unlinked file descriptors.
caught a bug that occurs when unlinking a file and then subsequently dropping it - unlinked files present in the map will cause an error later, as we'd have already removed the fd during an unlink. this keeps it in a HashSet until it is actually dropped - this only happens if the file is already present in the fdmap map<>fd association |
No description provided.