Commit Graph

5184 Commits

Author SHA1 Message Date
Kir Kolyshkin 06a9ea36de script/release.sh: add -a to force rebuild
https://golang.org/cmd/go/#hdr-Build_and_test_caching says:

> If you have made changes to the C libraries on your system, you will
> need to clean the cache explicitly or else use the -a build flag
> (see 'go help build') to force rebuilding of packages that depend
> on the updated C libraries.

This means that:

1. We need to either 'go clean -cache' or 'go build -a' when building
   the release binary. Adding '-a' seems less intrusive / more focused.

2. The check for existing libseccomp.a (added by commit d748280aa)
   is no longer needed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-05-03 10:30:23 -07:00
Akihiro Suda c2c35aefee Merge pull request #2911 from kolyshkin/debug-enable-file-line
logging: enable file/line info if --debug is set
2021-04-28 12:07:21 +09:00
Aleksa Sarai fac849263b merge branch 'pr-2923'
Shiming Zhang (3):
  libct/cg/sd: add dbus manager
  libct/cg/sd: add renew dbus connection
  Privatize NewUserSystemDbus

Kir Kolyshkin (2):
  libct/cg/sd: add isDbusError
  libct/cg/sd: retry on dbus disconnect

LGTMs: mrunalp cyphar
Closes #2923
2021-04-28 13:02:12 +10:00
Aleksa Sarai b2eb90816e merge branch 'pr-2922'
Akihiro Suda (1):
  CI: update Fedora to 34

LGTMs: mrunalp cyphar
Closes #2922
2021-04-28 10:13:11 +10:00
Kir Kolyshkin 47ef9a104f libct/cg/sd: retry on dbus disconnect
Instead of reconnecting to dbus after some failed operations, and
returning an error (so a caller has to retry), reconnect AND retry
in place for all such operations.

This should fix issues caused by a stale dbus connection after e.g.
a dbus daemon restart.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-27 16:19:49 -07:00
Shiming Zhang 6122bc8beb Privatize NewUserSystemDbus
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-27 16:16:27 -07:00
Shiming Zhang 15fee9899f libct/cg/sd: add renew dbus connection
[@kolyshkin: doc nits, use dbus.ErrClosed and isDbusError]

Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-27 16:16:05 -07:00
Kir Kolyshkin bacfc2c2f9 libct/cg/sd: add isDbusError
Generalize isUnitExists as isDbusError, and use errors.As while at it
(which can handle wrapped errors as well).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-27 16:14:04 -07:00
Shiming Zhang cdbed6f02f libct/cg/sd: add dbus manager
[@kolyshkin: documentation nits]

Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-27 16:02:39 -07:00
Akihiro Suda 7e7eb1c39d CI: update Fedora to 34
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-04-27 23:52:53 +09:00
Mrunal Patel 42a18e7f02 Merge pull request #2818 from kolyshkin/rootless-cgroup2-mount
Fix cgroup2 mount for rootless case
2021-04-22 17:04:19 -07:00
Akihiro Suda d061b41d9d Merge pull request #2917 from kolyshkin/validate-mounts
Validate mounts
2021-04-22 18:31:25 +09:00
Akihiro Suda 76559c60f1 Merge pull request #2918 from kolyshkin/freeze-3
libct/cg/fs/freezer: make sure to thaw on failure
2021-04-21 14:24:36 +09:00
Mrunal Patel b69bd53648 Merge pull request #2869 from dqminh/fix-oss-fuzz
Fix oss-fuzz build
2021-04-20 19:07:52 -07:00
Kir Kolyshkin fcd7fe85e1 libct/cg/fs/freezer: make sure to thaw on failure
Function (*FreezerGroup).Set has a few paths where in can return an
error. In any case, if an error is returned, we failed to freeze,
and we need to thaw to avoid leaving the cgroup in a stuck state.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-20 15:57:59 -07:00
Kir Kolyshkin 0216716c18 tests/int: add a case for cgroupv2 mount
This checks that in-container view of /sys/fs/cgroup does not
contain any extra cgroups (which was the case for rootless
before the previous commit).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-20 12:37:54 -07:00
Kir Kolyshkin 5ffcc5683e tests/int: use bfq test with rootless
As the rootless cgroup2 mount is now fixed, we can enable this test
for rootless as well.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-20 12:37:39 -07:00
Kir Kolyshkin ff692f289b Fix cgroup2 mount for rootless case
In case of rootless, cgroup2 mount is not possible (see [1] for more
details), so since commit 9c81440fb5 runc bind-mounts the whole
/sys/fs/cgroup into container.

Problem is, if cgroupns is enabled, /sys/fs/cgroup inside the container
is supposed to show the cgroup files for this cgroup, not the root one.

The fix is to pass through and use the cgroup path in case cgroup2
mount failed, cgroupns is enabled, and the path is non-empty.

Surely this requires the /sys/fs/cgroup mount in the spec, so modify
runc spec --rootless to keep it.

Before:

	$ ./runc run aaa
	# find /sys/fs/cgroup/ -type d
	/sys/fs/cgroup
	/sys/fs/cgroup/user.slice
	/sys/fs/cgroup/user.slice/user-1000.slice
	/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service
	...
	# ls -l /sys/fs/cgroup/cgroup.controllers
	-r--r--r--    1 nobody   nogroup          0 Feb 24 02:22 /sys/fs/cgroup/cgroup.controllers
	# wc -w /sys/fs/cgroup/cgroup.procs
	142 /sys/fs/cgroup/cgroup.procs
	# cat /sys/fs/cgroup/memory.current
	cat: can't open '/sys/fs/cgroup/memory.current': No such file or directory

After:

	# find /sys/fs/cgroup/ -type d
	/sys/fs/cgroup/
	# ls -l /sys/fs/cgroup/cgroup.controllers
	-r--r--r--    1 root     root             0 Feb 24 02:43 /sys/fs/cgroup/cgroup.controllers
	# wc -w /sys/fs/cgroup/cgroup.procs
	2 /sys/fs/cgroup/cgroup.procs
	# cat /sys/fs/cgroup/memory.current
	577536

[1] https://github.com/opencontainers/runc/issues/2158

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-20 12:35:40 -07:00
Kir Kolyshkin 3826db196d libct/rootfs/mountCgroupV2: minor refactor
1. s/cgroupPath/dest/

2. don't hardcode /sys/fs/cgroup

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-20 12:30:30 -07:00
Kir Kolyshkin 1e476578b6 libct/rootfs: introduce and use mountConfig
The code is already passing three parameters around from
mountToRootfs to mountCgroupV* to mountToRootfs again.

I am about to add another parameter, so let's introduce and
use struct mountConfig to pass around.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-20 12:30:06 -07:00
Kir Kolyshkin deb8a8dd77 libct/newInitConfig: nit
Move the initialization of Console* fields as they are unconditional.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-20 12:30:02 -07:00
Kir Kolyshkin 2192670a24 libct/configs/validate: validate mounts
Add a check that mount destination is absolute (as per OCI spec).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-20 11:48:44 -07:00
Kir Kolyshkin 1f1e91b1a0 libct/specconv: check mount destination is absolute
Per OCI runtime spec, mount destination MUST be absolute. Let's check
that and return an error if not.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-20 11:26:16 -07:00
Kir Kolyshkin 46e7065239 Merge pull request #2916 from thaJeztah/replace_deprecated_dbus
libcontainer/cgroups/systemd: replace use of deprecated dbus.New()
2021-04-20 11:01:55 -07:00
Sebastiaan van Stijn 73f22e7f1a libcontainer/cgroups/systemd: replace use of deprecated dbus.New()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-20 14:07:23 +02:00
Akihiro Suda ba257d2de8 Merge pull request #2873 from kolyshkin/mem-root-cgroup2
libct/cg/fs2.GetStats() improvements
2021-04-19 13:59:14 +09:00
Akihiro Suda 79e097c65f Merge pull request #2912 from odinuge/cgv2-cfs
Add cfs throttle stats to cgroup v2
2021-04-19 13:10:04 +09:00
Mrunal Patel 3a20ccbe59 Merge pull request #2897 from kolyshkin/fix-ro-paths
runc run: fix readonly path error for rootless + host pidns
2021-04-18 21:07:22 -07:00
Odin Ugedal ee3b563de7 Add cfs throttle stats to cgroup v2
Signed-off-by: Odin Ugedal <odin@uged.al>
2021-04-16 13:41:22 +02:00
Kir Kolyshkin 9f3d7534ea logging: enable file/line info if --debug is set
This helps a lot to find out where the errors come from.

Before:
> level=warning msg="lstat /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/test_hello: no such file or directory"

After:
> level=warning msg="lstat /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/test_hello: no such file or directory" func=github.com/opencontainers/runc/libcontainer.destroy file="github.com/opencontainers/runc/libcontainer/state_linux.go:44"

Presumably this comes with an overhead, but I guess no one is using
--debug by default anyway.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-15 10:58:29 -07:00
Akihiro Suda fce58ab2d5 Merge pull request #2910 from kolyshkin/oom-rootless-no-warn 2021-04-15 11:03:43 +09:00
Kir Kolyshkin ef9922c26c libct/cg: don't return OOMKillCount error when rootless
Commit 5d0ffbf9c8 added OOM kill count checking and better container
start/run/exec error reporting in case we hit OOM.

It also introduced warnings like these:

> level=warning msg="unable to get oom kill count" error="openat2
> /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/test_hello/memory.events:
> no such file or directory"

In case of rootless containers, unless cgroup is delegated or systemd is
used, runc can not create a cgroup and thus it fails to get OOM kill
count. This is expected, and the warning should not be shown in this
case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-14 17:57:00 -07:00
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 31dd1e499b tests/int: add rootless + host pidns test case
For the fix, see previous commit. Without the fix, this test case fails:

> container_linux.go:380: starting container process caused:
> process_linux.go:545: container init caused: readonly path /proc/bus:
> operation not permitted

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-14 17:35:15 -07:00
Kir Kolyshkin a2050ea471 runc run: fix start for rootless + host pidns
Currently, runc fails like this when used from rootless podman
with host PID namespace:

> $ podman --runtime=runc run --pid=host --rm -it busybox sh
> WARN[0000] additional gid=10 is not present in the user namespace, skip setting it
> Error: container_linux.go:380: starting container process caused:
> process_linux.go:545: container init caused: readonly path /proc/asound:
> operation not permitted: OCI permission denied

(Here /proc/asound is the first path from OCI spec's readonlyPaths).

The code uses MS_BIND|MS_REMOUNT flags that have a special meaning in
the kernel ("keep the flags like nodev, nosuid, noexec as is").
For some reason, this "special meaning" trick is not working for the
above use case (rootless podman + no PID namespace), and I don't know
how to reproduce this without podman.

Instead of relying on the kernel feature, let's just get the current
mount flags using fstatfs(2) and add those that needs to be preserved.

While at it, wrap errors from unix.Mount into os.PathError to make
errors a bit less cryptic.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-14 17:32:08 -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