libct: fix some container.Run fd leaks, add fd leak test#2802
Merged
AkihiroSuda merged 2 commits intoopencontainers:masterfrom Mar 31, 2021
Merged
libct: fix some container.Run fd leaks, add fd leak test#2802AkihiroSuda merged 2 commits intoopencontainers:masterfrom
AkihiroSuda merged 2 commits intoopencontainers:masterfrom
Conversation
Contributor
Author
|
Looks like by closing fifo fd I have introduced some kind of a race. Looking... |
Contributor
|
Looks good to me, thanks for tackling this one 👍 |
2 tasks
5a28a55 to
ea99c27
Compare
Contributor
Author
|
CI failure in Fedora 33 seems unrelated (filed #2805) -- CI restarted. |
Contributor
Author
|
@AkihiroSuda @cyphar @mrunalp PTAL |
AkihiroSuda
previously approved these changes
Feb 24, 2021
Contributor
|
Needs rebase. Looks fine otherwise. |
Apparently, the parent never closes execFifo fd. Not a problem for runc per se, but can be an issue for a user of libcontainer. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This is a very simple test that checks that container.Run do not leak
opened file descriptors.
In fact it does, so we have to add two exclusions:
1. /sys/fs/cgroup is opened once per lifetime in prepareOpenat2(),
provided that cgroupv2 is used and openat2 is available. This
works as intended ("it's not a bug, it's a feature").
2. ebpf program fd is leaked every time we call setDevices() for
cgroupv2 (iow, every container.Run or container.Set leaks 1 fd).
This needs to be fixed, thus FIXME.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Contributor
Author
|
Rebased (removed the first patch as it is no longer needed (#2835 implements closing the log pipe). |
mrunalp
approved these changes
Mar 31, 2021
AkihiroSuda
approved these changes
Mar 31, 2021
Merged
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.
this is an alternative for #2794
TL;DR: Fix two cases of fd leaks on run, added a test case to avoid more in the future.
libct: close execFifo after start
Apparently, the parent never closes execFifo fd. Not a problem for runc
per se, but can be an issue for a user of libcontainer.
libct: close log pipe
Otherwise we have one extra fd opened after container.Run.Commit removed (obsoleted by Fix init log forwarding race #2835)
libct/int: add TestFdLeaks
This is a very simple test that checks that container.Run do not leak
opened file descriptors.
In fact it does, so we have to add two exclusions:
/sys/fs/cgroupdirectory is opened once per lifetime inprepareOpenat2(),provided that cgroupv2 is used and openat2 is available. This
works as intended ("it's not a bug, it's a feature").
ebpf program fd is leaked every time we call
setDevices()forcgroupv2 (iow, every
container.Runorcontainer.Setleaks 1 fd).This needs to be fixed in ebpf, thus FIXME (cgroup: devices updates appear to be broken #2366 (comment))
Closes: #2794
Thanks to @cclerget for discovery and the initial fix.
Suggested changelog entry