Skip to content
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

libct: fix some container.Run fd leaks, add fd leak test #2802

Merged
merged 2 commits into from
Mar 31, 2021

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Feb 10, 2021

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.

  1. 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.

  2. libct: close log pipe

    Otherwise we have one extra fd opened after container.Run.
    Commit removed (obsoleted by Fix init log forwarding race #2835)

  3. 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:

    1. /sys/fs/cgroup directory 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 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

@kolyshkin kolyshkin changed the title Run leaks libct: fix some container.Run leaks, add fd leak test Feb 10, 2021
@kolyshkin kolyshkin changed the title libct: fix some container.Run leaks, add fd leak test libct: fix some container.Run fd leaks, add fd leak test Feb 10, 2021
@kolyshkin kolyshkin changed the title libct: fix some container.Run fd leaks, add fd leak test [WIP] libct: fix some container.Run fd leaks, add fd leak test Feb 10, 2021
@kolyshkin
Copy link
Contributor Author

Looks like by closing fifo fd I have introduced some kind of a race. Looking...

@cclerget
Copy link
Contributor

Looks good to me, thanks for tackling this one 👍

@kolyshkin kolyshkin force-pushed the run-leaks branch 2 times, most recently from 5a28a55 to ea99c27 Compare February 10, 2021 21:58
@kolyshkin kolyshkin changed the title [WIP] libct: fix some container.Run fd leaks, add fd leak test libct: fix some container.Run fd leaks, add fd leak test Feb 10, 2021
@kolyshkin kolyshkin added this to the 1.0.0-rc94 milestone Feb 10, 2021
@kolyshkin
Copy link
Contributor Author

CI failure in Fedora 33 seems unrelated (filed #2805) -- CI restarted.

@kolyshkin
Copy link
Contributor Author

@AkihiroSuda @cyphar @mrunalp PTAL

AkihiroSuda
AkihiroSuda previously approved these changes Feb 24, 2021
@mrunalp
Copy link
Contributor

mrunalp commented Mar 31, 2021

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>
@kolyshkin
Copy link
Contributor Author

Rebased (removed the first patch as it is no longer needed (#2835 implements closing the log pipe).

@AkihiroSuda AkihiroSuda merged commit a1270a6 into opencontainers:master Mar 31, 2021
@kolyshkin kolyshkin mentioned this pull request Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants