Commit Graph

5142 Commits

Author SHA1 Message Date
Kir Kolyshkin 5cdd9022a9 libct/cg/fs[2]: fix comments about m.rootless
For fs, commit fc620fdf81 made rootless field private,
and for fs2, it was always private, and yet comments in both
mention it as m.Rootless.

Fix it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-14 17:44:22 -07:00
Kir Kolyshkin 3397a09ee9 Merge pull request #2908 from saschagrunert/vendor
Fix vendored dependencies
2021-04-14 10:14:15 -07:00
Sascha Grunert 2f1a3ed308 Fix vendored dependencies
The current master branch does not build, running a `make vendor` fixes
this inconsistency.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2021-04-14 13:30:50 +02:00
Aleksa Sarai b474993b13 merge branch 'pr-2903'
Sebastiaan van Stijn (1):
  ebpf: replace deprecated prog.Attach/prog.Detach

LGTMs: AkihiroSuda kolyshkin cyphar
Closes #2903
2021-04-14 10:36:32 +10:00
Kir Kolyshkin 60973b5977 Merge pull request #2904 from thaJeztah/bump_ebpf2
go.mod: github.com/cilium/ebpf v0.5.0
2021-04-13 17:13:48 -07:00
Sebastiaan van Stijn d15c7bb0f2 go.mod: github.com/cilium/ebpf v0.5.0
full diff: https://github.com/cilium/ebpf/compare/v0.4.0...v0.5.0

Breaking changes
------------------------------------------

All LoadPinned*() functions now take LoadPinOptions to control loader behaviour.
Simply pass nil to load with default options.

- LoadPinnedMap()
- LoadPinnedProgram()
- LoadPinnedCgroup()
- LoadPinnedIter()
- LoadPinnedRawLink()
- LoadPinnedNetNs()

Bug fixes
------------------------------------------

- Program.IsPinned() now behaves correctly on maps loaded from bpffs
- Map.Pin() no longer clobbers the destination file if it already exists

Features
------------------------------------------

- Attaching to k(ret)probes and tracepoints can now be done with link.Kprobe(),
  link.Kretprobe() and link.Tracepoint()
- Programs of type Kprobe automatically get their KernelVersion fields populated
  by detecting the kernel version at runtime
- MapOptions now contains a LoadPinOptions
- ProgSpec now contains a Flags field, adding support for BPF_F_SLEEPABLE
- Made BTF map loader more flexible by looping over Vars in a BTF data section
- Pinned Maps and Programs can now be loaded from bpffs in read-or write-only mode
- Added golangci-lint project configuration, running in CI

Examples
------------------------------------------

kprobe and tracepoint examples updated to use the new link.Kprobe() and link.Tracepoint() API
There is now an example for how to attach eBPF programs to uprobes

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-13 12:54:47 +02:00
Sebastiaan van Stijn f28a8cc28c ebpf: replace deprecated prog.Attach/prog.Detach
Caught by golangci-lint when enabling golint:

    libcontainer/cgroups/ebpf/ebpf.go:35:12: SA1019: prog.Attach is deprecated: use link.RawAttachProgram instead. (staticcheck)
        if err := prog.Attach(dirFD, ebpf.AttachCGroupDevice, unix.BPF_F_ALLOW_MULTI); err != nil {
                  ^
    libcontainer/cgroups/ebpf/ebpf.go:39:13: SA1019: prog.Detach is deprecated: use link.RawDetachProgram instead. (staticcheck)
            if err := prog.Detach(dirFD, ebpf.AttachCGroupDevice, unix.BPF_F_ALLOW_MULTI); err != nil {
                      ^

Worth noting that we currently call prog.Detach() with unix.BPF_F_ALLOW_MULTI;
https://github.com/golang/sys/blob/22da62e12c0cd9c1da93581e1113ca4d82a5be14/unix/zerrors_linux.go#L178

    BPF_F_ALLOW_MULTI = 0x2

Looking at the source code for prog.Detach(); https://github.com/cilium/ebpf/blob/v0.4.0/prog.go#L579-L581,
this would _always_ produce an error:

    if flags != 0 {
        return errors.New("flags must be zero")
    }

Note that the flags parameter is not used (except for that validation)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-13 12:27:39 +02:00
Qiang Huang 2d38476c96 Merge pull request #2840 from kolyshkin/ignore-kmem
Ignore kernel memory settings
2021-04-13 09:44:14 +08:00
Aleksa Sarai 14ce8be9b1 merge branch 'pr-2836'
Aleksa Sarai (1):
  nsenter: improve debug logging

Kir Kolyshkin (1):
  libct/nsenter: add json msg escaping

LGTMs: mrunalp cyphar
Closes #2836
2021-04-13 10:55:57 +10:00
Mrunal Patel 23f6ca80d5 Merge pull request #2900 from LiangZhou-CTY/patch-1
fix a typo
2021-04-12 17:42:51 -07:00
Kir Kolyshkin 928ef7afac libct/nsenter: add json msg escaping
Since the previous commit, some strings logged by write_log() contain a
literal newline, which leads to errors like this one:

> # time="2020-06-07T15:41:37Z" level=error msg="failed to decode \"{\\\"level\\\":\\\"debug\\\", \\\"msg\\\": \\\"nsexec-0[2265]: update /proc/2266/uid_map to '0 1000 1\\n\" to json: invalid character '\\n' in string literal"

The fix is to escape such characters.

Add a simple (as much as it can be) routine which implements JSON string
escaping as required by RFC4627, section 2.5, plus escaping of DEL (0x7f)
character (not required, but allowed by the standard, and usually done
by tools such as jq).

As much as I hate to code something like this, I was not able to find
a ready to consume and decent C implementation (not using glib).

Added a test case (and some additional asserts in C code, conditionally
enabled by the test case) to make sure the implementation is correct.
The test case have to live in a separate directory so we can use
different C flags to compile the test, and use C from go test.

[v2: try to simplify the code, add more tests]
[v3: don't do exit(1), try returning an error instead]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-12 16:47:26 -07:00
Mrunal Patel cd5208a9b9 Merge pull request #2898 from kolyshkin/fix-s390-tty
vendor: bump containerd/console to 1.0.2
2021-04-12 13:18:50 -07:00
Kir Kolyshkin 52390d6804 Ignore kernel memory settings
This is somewhat radical approach to deal with kernel memory.

Per-cgroup kernel memory limiting was always problematic. A few
examples:

 - older kernels had bugs and were even oopsing sometimes (best example
   is RHEL7 kernel);
 - kernel is unable to reclaim the kernel memory so once the limit is
   hit a cgroup is toasted;
 - some kernel memory allocations don't allow failing.

In addition to that,

 - users don't have a clue about how to set kernel memory limits
   (as the concept is much more complicated than e.g. [user] memory);
 - different kernels might have different kernel memory usage,
   which is sort of unexpected;
 - cgroup v2 do not have a [dedicated] kmem limit knob, and thus
   runc silently ignores kernel memory limits for v2;
 - kernel v5.4 made cgroup v1 kmem.limit obsoleted (see
   https://github.com/torvalds/linux/commit/0158115f702b).

In view of all this, and as the runtime-spec lists memory.kernel
and memory.kernelTCP as OPTIONAL, let's ignore kernel memory
limits (for cgroup v1, same as we're already doing for v2).

This should result in less bugs and better user experience.

The only bad side effect from it might be that stat can show kernel
memory usage as 0 (since the accounting is not enabled).

[v2: add a warning in specconv that limits are ignored]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-12 12:18:11 -07:00
Akihiro Suda 6023d635d7 Merge pull request #2844 from kolyshkin/sd-cg-docs 2021-04-13 04:12:34 +09:00
Kir Kolyshkin b7c315ad56 vendor: bump containerd/console to 1.0.2
This is to include https://github.com/containerd/console/pull/51.

Fixes: https://github.com/opencontainers/runc/issues/2896

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-12 11:21:07 -07:00
Liang Zhou b6cdb8ae09 fix a typo
Signed-off-by: Liang Zhou <zhoul110@chinatelecom.cn>
2021-04-11 09:40:21 +08:00
Kir Kolyshkin b23315bdd9 Merge pull request #2850 from thaJeztah/userns_check
libcontainer/system: move userns utilities, remove `GetParentNSeuid`, `UIDMapInUserNS`
2021-04-08 10:12:05 -07:00
Aleksa Sarai 64bb59f592 nsenter: improve debug logging
In order to make 'runc --debug' actually useful for debugging nsexec
bugs, provide information about all the internal operations when in
debug mode.

[@kolyshkin: rebasing; fix formatting via indent for make validate to pass]

Signed-off-by: Aleksa Sarai <asarai@suse.de>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-08 09:54:43 -07:00
Mrunal Patel bb28c44f12 Merge pull request #2894 from haircommander/chdir-fix-2
libct/init_linux: retry chdir to fix EPERM (regression in rc93)
2021-04-06 17:17:56 -07:00
Peter Hunt 6ce2d63a5d libct/init_linux: retry chdir to fix EPERM
Alas, the EPERM on chdir saga continues...

Unfortunately, the there were two releases between when https://github.com/opencontainers/runc/commit/5e0e67d76cc99d76c8228d48f38f37034503f315  was released
and when the workaround https://github.com/opencontainers/runc/pull/2712 was added.

Between this, folks started relying on the ability to have a workdir that the container user doesn't have access to.

Since this case was previously valid, we should continue support for it.

Now, we retry the chdir:
Once at the top of the function (to catch cases where the runc user has access, but container user does not)
and once after we setup user (to catch cases where the container user has access, and the runc user does not)

Add a test case for this as well.

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2021-04-06 14:51:43 -04:00
Aleksa Sarai bf6abcfe02 merge branch 'pr-2770'
Kir Kolyshkin (3):
  make release: build/include libseccomp
  script/release.sh: fix shellcheck warnings
  ci: make static built binary available

LGTMs: @AkihiroSuda @cyphar
Closes #2770
2021-04-06 18:55:44 +10:00
Akihiro Suda c453f1a523 Merge pull request #2881 from kolyshkin/test-rand-cg
tests/int: some refactoring, fix a flake
2021-04-06 13:27:19 +09:00
Akihiro Suda d8a5f6084a Merge pull request #2885 from thaJeztah/config_missing_type
libcontainer/configs: add missing type for hooknames
2021-04-06 13:24:28 +09:00
Kir Kolyshkin 1c3c4ac1cf Merge pull request #2889 from thaJeztah/bump_mountinfo
go.mod: github.com/moby/sys/mountinfo v0.4.1
2021-04-05 18:05:39 -07:00
Kir Kolyshkin a1d30bcbe8 Merge pull request #2890 from zhsj/fix-hello
tests: fix hello-world tarball name in testdata for arm64
2021-04-05 16:32:29 -07:00
Akihiro Suda 913b9f14e8 Merge pull request #2886 from thaJeztah/check_cleanup 2021-04-06 03:28:45 +09:00
Shengjing Zhu c5029c001d tests: fix hello-world tarball name in testdata for arm64
Signed-off-by: Shengjing Zhu <zhsj@debian.org>
2021-04-05 23:55:27 +08:00
Sebastiaan van Stijn 289a304535 go.mod: github.com/moby/sys/mountinfo v0.4.1
full diff: https://github.com/moby/sys/compare/v0.4.0...v0.4.1

github.com/moby/sys/mountinfo v0.4.1
-----------------------------------------

- Fix PrefixFilter() being too greedy
- TestMountedBy*: add missing pre-checks
- Documentation improvements

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-04 23:24:59 +02:00
Sebastiaan van Stijn 4316df8b53 libcontainer/system: move userns utilities to separate package
Moving these utilities to a separate package, so that consumers of this
package don't have to pull in the whole "system" package.

Looking at uses of these utilities (outside of runc itself);

`RunningInUserNS()` is used by [various external consumers][1],
so adding a "Deprecated" alias for this.

[1]: https://grep.app/search?current=2&q=.RunningInUserNS

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-04 22:42:03 +02:00
Sebastiaan van Stijn e7fd383bce libcontainer/system: un-export UIDMapInUserNS()
`UIDMapInUserNS()` is not used anywhere, only internally. so un-export it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-04 22:42:02 +02:00
Sebastiaan van Stijn 249356a1a4 libcontainer/system: remove unused GetParentNSeuid()
This function was added in f103de57ec, but no
longer used since 06f789cf26 (v1.0.0-rc6)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-04 22:41:59 +02:00
Kir Kolyshkin 365c6282c7 Merge pull request #2888 from thaJeztah/fixup_rm_win_carry
libcontainer: rm windows pieces (carry #2700)
2021-04-03 19:10:36 -07:00
Aleksa Sarai 0d49470392 merge branch 'pr-2855'
Kir Kolyshkin (2):
  start: don't kill runc init too early
  libct/configs/validator: add some cgroup support

LGTMs: @AkihiroSuda @cyphar
Closes #2855
2021-04-03 12:41:41 +11:00
Aleksa Sarai b85373ff5d merge branch 'pr-2875'
Sebastiaan van Stijn (1):
  go.mod: github.com/cilium/ebpf v0.4.0

LGTMs: @AkihiroSuda @cyphar
Closes #2875
2021-04-03 12:37:13 +11:00
Sebastiaan van Stijn dc52ed250a libcontainer/user: remove outdated MAINTAINERS file
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-02 11:56:41 +02:00
Sebastiaan van Stijn 72ecf59c88 libcontainer/user: fix windows compile error
Move the unix-specific code to a file that's not compiled on
Windows.

Some of the errors (ErrUnsupported, ErrNoPasswdEntries, ErrNoGroupEntries)
are used in other parts of the code, so are moved to a non-platform
specific file.

Most of "user" is probably not useful on Windows, although it's possible
that Windows code may have to parse a passwd file, so leaving that code
for now.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-02 11:56:39 +02:00
Kir Kolyshkin 2515b0c2f2 libct/user: rm windows code
Commit bf749516 added these two functions, but they are only used from
Windows code. The v1 of this patch moved these functions to _windows.go
file, but after some discussion we decided to drop windows code
altogether, so this is what this patch now does.

This fixes

> libcontainer/user/user.go:64:6: func `groupFromOS` is unused (unused)
> libcontainer/user/user.go:35:6: func `userFromOS` is unused (unused)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-02 11:56:37 +02:00
Kir Kolyshkin 0596f6e1e7 libcontainer/devices/device_windows.go: rm
This was initially added by commit d78ee47154 but later
moved from libcontainer/configs to libcontainer/devices by
commit 677baf22.

Looks like since commit 677baf22 and also [1]
there is no use for this, thus removing.

[1] https://github.com/containers/buildah/pull/2652

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-02 11:56:21 +02:00
Kir Kolyshkin b1deba8c5a libcontainer/configs/config_windows_test.go: rm
Nothing is in there, so removing.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-02 11:55:33 +02:00
Sebastiaan van Stijn f1586dbd7a libcontainer/configs/validate: make Validate() less DRY
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-02 11:41:19 +02:00
Sebastiaan van Stijn 4126b807cc libcontainer/configs: add missing type for hooknames
Commit ccdd75760c introduced the HookName type
for hooks, but only set this type on the Prestart const, but not for the
other hooks.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-02 11:08:24 +02:00
Sebastiaan van Stijn 48125179eb go.mod: github.com/cilium/ebpf v0.4.0
full diff: https://github.com/cilium/ebpf/compare/v0.2.0...v0.4.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-02 09:58:23 +02:00
Kir Kolyshkin 44611630a5 docs/systemd: add
1. Move docs/systemd-properties.md to docs/systemd.md

2. Document the cgroupsPath to systemd unit name and slice conversion
   rules, as well as mapping of OCI runtime spec resource limits to
   systemd unit properties.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-01 19:50:47 -07:00
Kir Kolyshkin 27bb1bd5ea libct/specconv/CreateCgroupConfig: don't set c.Parent default
c.Parent is only used by systemd cgroup drivers, and both v1 and v2
drivers do have code to set the default if it is empty, so setting
it here is redundant.

In addition, in case of cgroup v2 rootless container setting it here
is harmful as the default should be user.slice not system.slice.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-01 19:50:37 -07:00
Kir Kolyshkin d748280aa9 make release: build/include libseccomp
libseccomp is LGPL, meaning if we statically link it, we have to include
the source code of the library.

Amend "make release" to download and build libseccomp, build runc
against it, and include its sources into the release directory.

The only caveat is I found no way to stop go build from using the
stock (distro-provided) libseccomp.a, so the script checks that
the stock libseccomp.a is not available, and aborts otherwise.

While at it:
 - enable shellcheck for script/release.sh
 - remove libseccomp installation from the gha job
 - add dependecies needed for libseccomp build to the gha job

[v2: also include libseccomp .asc file]
[v3: rebase]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-01 19:43:02 -07:00
Kir Kolyshkin aa6da82c4a script/release.sh: fix shellcheck warnings
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-01 19:42:34 -07:00
Kir Kolyshkin 3eb46d89d2 ci: make static built binary available
This uploads the results of make release step (static binary and
a source tarball) so that they are available. I am not very sure if
it's of any use, but at least one can download and play with a static
binary from any PR.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-01 19:42:34 -07:00
Kir Kolyshkin f0dec0b4bf libct/specconv/CreateCgroupConfig: nit
Do not call libcontainerUtils.CleanPath in case its result will
not be used.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-01 19:33:01 -07:00
Kir Kolyshkin 6538f9f20a Merge pull request #2854 from thaJeztah/runc_warn_unknown_caps
capabilities: WARN, not ERROR, for unknown / unavailable capabilities
2021-04-01 18:27:57 -07:00
Mrunal Patel 6c40d8943a Merge pull request #2882 from wzshiming/update-vendor
vendor: update go-systemd and godbus
2021-04-01 16:14:31 -07:00