-
Notifications
You must be signed in to change notification settings - Fork 346
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
Fix --preserve-fds, eliminate stray FD being passed into container #2893
base: main
Are you sure you want to change the base?
Conversation
00bfd41
to
97574b1
Compare
@aidanhs , failing oci CI -
|
Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>
97574b1
to
c92c2e0
Compare
The failure was a problem with some changes that I made to try and make closing FDs happen later - unfortunately seccomp got in the way. I've now backed out those changes as strictly speaking they were unnecessary. Have run the tests locally and they seem to pass. |
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.
Thanks for your PR! Probably you are right, but I'm not sure. So, may I ask you to write an e2e test to clarify?
https://containers.github.io/youki/developer/e2e/rust_oci_test.html
Also, I've updated the original PR. Thanks for your advice. It makes sense a lot.
#2663
Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>
Test harness additionally needed to support 1. tests that cannot run in parallel 2. tests that need to customise create arguments Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>
c92c2e0
to
fc5c131
Compare
There are now three integration tests:
This was harder than I expected because:
|
Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>
3b83a72
to
20d9be4
Compare
#2663 seems to have broken preserve-fds by unconditionally closing everything aside from stdio in the container main process.
I've fixed this by effectively reverting part of that PR. Typically I'd expect it to be a bad idea to revert security fixes, but unfortunately I don't really understand much of the diagnosis at #2663 and can't get it to stack up against my observations of previous and current behavior of youki.
Specifically:
I checked out 04f8f2d (the commit before the fix PR was merged) and couldn't reproduce this. With a default config generated by
youki spec
and a command of"ls", "-al", "/proc/self/fd"
I get the following output:This is what I'd expect - preserve fds (#177) already closes all the FDs in the init process before execution. FD 3 here is
ls
opening the directory.I can reproduce a leak by passing
--preserve-fds 10
(I get something at FD 7, which seems to be the rootfs being referenced) - but the fix solves this by just making the preserve-fds flag useless. I fix this by actually closing the culprit directory, and then additionally verifying by hand that passing--preserve-fds 100
does not list any other stray FDs that are being passed down.Again I don't understand this - the preserve-fds PR does exactly that by marking everything as O_CLOEXEC before process execution? It is not ideal that passing
--preserve-fds
leaks something, but I've fixed that in this PR in a more precise way.I also don't understand this - the preserve fds PR sets the O_CLOEXEC flag in the init process, before execing the user process. It seems better to do this as late as possible, so fewer file descriptors can slip in? The vulnerability fix puts it in the main process, giving ample opportunity for other FDs to be opened and leaked.
Perhaps there's more detail that would help my confusion in the review in the private repository that would help? Per:
Edit: oops, sorry for the mentions, those were unintentional