Commit Graph

5403 Commits

Author SHA1 Message Date
Kir Kolyshkin 7cf1952fcb libct/nsenter: fix logging race in nsexec
As reported in issue 3119, there is a race in nsexec logging
that can lead to garbled json received by log forwarder, which
complains about it with a "failed to decode" error.

This happens because dprintf (used since the very beginning of nsexec
logging introduced in commit ba3cabf932) relies on multiple write(2)
calls, and with additional logging added by 64bb59f592 a race is
possible between runc init parent and its children.

The fix is to prepare a string and write it using a single call to
write(2).

[v2: NULLify json on error from asprintf]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 2bab4a56f1)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-11 10:02:43 -07:00
Kir Kolyshkin 0b77b2d1d5 Merge pull request #3101 from AkihiroSuda/cirrus-10
[1.0] Use Cirrus CI for Vagrant tests
2021-07-28 10:47:41 -07:00
Adrian Reber 1d45404592 Do not use Vagrant for CentOS 7/8
As Cirrus CI does not provide a real terminal this uses the same
'ssh -tt' workaround as the Vagrant setup. This sets up the
CentOS 7 and 8 to allow SSH as root to localhost so that we can run
all the tests via 'ssh -tt'.

Not going through vagrant reduces CI times for CentOS 7 and 8 from 6
minutes to 4 minutes.

Signed-off-by: Adrian Reber <areber@redhat.com>
(cherry picked from commit 9f656dbb11)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-07-27 15:21:06 +09:00
Kir Kolyshkin c8d8fd5b5c tests/rootless.sh: fixup for "update rt" test
Without this, the test case fails with

> Writing 1000000 to /sys/fs/cgroup/cpu,cpuacct/runc-cgroups-integration-test/cpu.rt_period_us
> /tmp/bats-run-106836/bats.116418.src: line 548: /sys/fs/cgroup/cpu,cpuacct/runc-cgroups-integration-test/cpu.rt_period_us: Permission denied

Since we do not currently have a setup to test this, this went
unnoticed (can be seen in RHEL8 though).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Adrian Reber <areber@redhat.com>
(cherry picked from commit d448016486)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-07-27 15:20:59 +09:00
Kir Kolyshkin 257018e76c tests/int: fix "update rt period and runtime" for rootless
Since commit f09a3e1b8d, the value passed on to read starts with
a slash, resulting in the first element of the array to be empty.

As a result, the test tries to write to the top-level cgroup, which
fails when rootless:

> # Writing 1000000 to /sys/fs/cgroup/cpu,cpuacct//cpu.rt_period_us
> # /tmp/bats-run-106184/bats.115768.src: line 548: /sys/fs/cgroup/cpu,cpuacct//cpu.rt_period_us: Permission denied

To fix, remove the leading slash.

An alternative fix would be to do "for ((i = 1;" instead of "i = 0", but
that seems less readable.

Fixes: f09a3e1b8d
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 86af524866)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-07-27 15:20:54 +09:00
Akihiro Suda 76c047f1b1 Evaluate Cirrus CI for Vagrant tests
ref: issue 3078

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
(cherry picked from commit 87bfd20fbd)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-07-20 13:53:50 +09:00
Kir Kolyshkin 2881afb65b Merge pull request #3095 from cyphar/release-1.0.1
[1.0] VERSION: release 1.0.1
2021-07-16 08:00:48 -07:00
Aleksa Sarai 466d1a1ad8 VERSION: back to development
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-07-16 14:39:38 +10:00
Aleksa Sarai 4144b63817 VERSION: release 1.0.1
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
v1.0.1
2021-07-16 14:39:19 +10:00
Aleksa Sarai 40dcf1f748 merge branch 'pr-3093' into release-1.0
Kir Kolyshkin (6):
  libct/cg/sd: add TestPodSkipDevicesUpdate
  libct/cg/sd: TestFreezePodCgroup: rm explicit freeze
  libct/cg/sd/v1: Set: avoid unnecessary freeze/thaw
  libct/int/TestFreeze: test freeze/thaw via Set
  libct/int: allow subtests
  libct/cg/sd/v1: Set: don't overwrite r.Freezer

LGTMs: mrunalp cyphar
Closes #3093
2021-07-16 14:37:17 +10:00
Kir Kolyshkin 4efb7a697e libct/cg/sd: add TestPodSkipDevicesUpdate
TestPodSkipDevicesUpdate checks that updating a pod having SkipDevices: true
does not result in spurious "permission denied" errors in a container
running under the pod. The test is somewhat similar in nature to the
@test "update devices [minimal transition rules]" in tests/integration,
but uses a pod.

This tests the validity of freezeBeforeSet in v1.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit a71102624d)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-15 15:27:23 -07:00
Kir Kolyshkin 82d3eb6915 libct/cg/sd: TestFreezePodCgroup: rm explicit freeze
This was initially added by commit 3e5c199708 because Set (with
r.Freezer = Frozen) was not able to freeze a container.

Now (see a few previous commits) Set can do the freeze, so the explicit
Freeze is no longer needed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 52dd96db6b)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-15 15:27:23 -07:00
Kir Kolyshkin 2fc2e3d675 libct/cg/sd/v1: Set: avoid unnecessary freeze/thaw
Introduce freezeBeforeSet, which contains the logic of figuring out
whether we need to freeze/thaw around setting systemd unit properties.

In particular, if SkipDevices is set, and the current unit properties
allow all devices, there is no need to freeze and thaw, as systemd
won't write any device rules in this case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit f2db87986c,
 minor conflict in include() due to missing commit
 b60e2edf75)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-15 15:27:23 -07:00
Kir Kolyshkin ef0aa849ed libct/int/TestFreeze: test freeze/thaw via Set
In addition to freezing and thawing a container via Pause/Resume,
there is a way to also do so via Set.

This way was broken though and is being fixed by a few preceding
commits. The test is added to make sure this is fixed and won't regress.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 5dc3260431)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-15 15:27:23 -07:00
Kir Kolyshkin 01cd4b5f3f libct/int: allow subtests
The t.Name() usage in libcontainer/integration prevented subtests
to be used, since in such case it returns a string containing "/",
and thus it can't be used to name a container.

Fix this by replacing slashes with underscores where appropriate.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit af1688a544)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-15 15:27:23 -07:00
Kir Kolyshkin 22b2ff0f34 libct/cg/sd/v1: Set: don't overwrite r.Freezer
m.Freeze method changes m.cgroups.Resources.Freezer field, which should
not be done while we're temporarily freezing the cgroup in Set. If this
field is changed, and r == m.cgroups.Resources (as it often happens),
this results in inability to freeze the container using Set().

To fix, add and use a method which does not change r.Freezer field.

A test case for the bug will be added separately.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 67cfd3d400)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-15 15:27:23 -07:00
Aleksa Sarai e14c1347e6 merge branch 'pr-3092' into release-1.0
Odin Ugedal (2):
  libct/cg/sd: Don't freeze cgroup on cgroup v2 Set
  Update device update tests

LGTMs: mrunalp cyphar
Closes #3092
2021-07-16 07:57:26 +10:00
Odin Ugedal 04edd79d39 libct/cg/sd: Don't freeze cgroup on cgroup v2 Set
Since device updates in cgroup v2 are atomic for systemd, there is no
need to freeze the processes before running the updates.

Signed-off-by: Odin Ugedal <odin@uged.al>
(cherry picked from commit f33be7cc98, trivial conflict
 due to missing commit b60e2edf75)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-14 23:30:31 -07:00
Odin Ugedal 298a3100b0 Update device update tests
Run device update tests on cgroup v2, and add a test verifying that we
don't allow access to devices when we don't intend to.

Signed-off-by: Odin Ugedal <odin@uged.al>
(cherry picked from commit d41a273dae)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-14 23:28:26 -07:00
Aleksa Sarai 7250587156 merge branch 'pr-3091' into release-1.0
Kir Kolyshkin (1):
  ci/gha: run on release-* branches after a push

LGTMs: mrunalp cyphar
Closes #3091
2021-07-15 12:39:52 +10:00
Kir Kolyshkin 257723b3f6 ci/gha: run on release-* branches after a push
A CI is needed after PR merges.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit d02b0061d2)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-14 18:23:57 -07:00
Aleksa Sarai fc2918d950 merge branch 'pr-3087' into release-1.0
Aleksa Sarai (2):
  cgroupv2: ebpf: ignore inaccessible existing programs
  vendor: update github.com/cilium/ebpf

Closes: #3087
LGTMs: mrunalp cyphar
2021-07-15 10:34:57 +10:00
Aleksa Sarai 4dc207a6c0 cgroupv2: ebpf: ignore inaccessible existing programs
This is necessary in order for runc to be able to configure device
cgroups with --systemd-cgroup on distributions that have very strict
SELinux policies such as openSUSE MicroOS[1].

The core issue here is that systemd is adding its own BPF policy that
has an SELinux label such that runc cannot interact with it. In order to
work around this, we can just ignore the policy -- in theory this
behaviour is not correct but given that the most obvious case
(--systemd-cgroup) will still handle updates correctly, this logic is
reasonable.

[1]: https://bugzilla.suse.com/show_bug.cgi?id=1182428

Fixes: d0f2c25f52 ("cgroup2: devices: replace all existing filters when attaching")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
(cherry picked from commit 57e3c54182)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-14 00:17:44 -07:00
Aleksa Sarai 90d01a0480 vendor: update github.com/cilium/ebpf
We need to update the eBPF library so that we can get the raw syscall
errors from bpf(2) syscalls using errors.Is.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
(cherry picked from commit fe518a0678)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-14 00:17:34 -07:00
Aleksa Sarai 4f88ed68e3 merge branch 'pr-3085' into release-1.0
Odin Ugedal (1):
  libct/cg/sd: Add freezer tests
  libct/cg/fs/freezer.GetState: report current cgroup state

LGTMs: AkihiroSuda cyphar
Closes #3085
2021-07-14 16:25:05 +10:00
Odin Ugedal 3f40fbff17 libct/cg/sd: Add freezer tests
This test the issues fixed by the two preceding commits.

Co-Authored-By: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Odin Ugedal <odin@uged.al>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 3e5c199708)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-12 02:03:05 -07:00
Odin Ugedal c1a5b3e109 libct/cg/fs/freezer.GetState: report current cgroup state
If a control group is frozen, all its descendants will report FROZEN
in freezer.state cgroup file.

OTOH cgroup v2 cgroup.freeze is not reporting the cgroup as frozen
unless it is frozen directly (i.e. not via an ancestor).

Fix the discrepancy between v1 and v2 drivers behavior by
looking into freezer.self_freezing cgroup file, which, according
to kernel documentation, will show 1 iff the cgroup was frozen directly.

Co-authored-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Odin Ugedal <odin@uged.al>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 294c4866ea)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-12 02:02:25 -07:00
Mrunal Patel 8e259d29e5 Merge pull request #3079 from kolyshkin/1.0-backport-3062
[1.0] libct/user: fix parsing long /etc/group lines
2021-07-09 17:23:56 -04:00
Mrunal Patel 8304d0cbe4 Merge pull request #3074 from kolyshkin/1.0-backport-3045
[1.0] retry unix.EINTR for container init process
2021-07-09 17:21:26 -04:00
Kir Kolyshkin 0a5d8ba464 libct/user: fix parsing long /etc/group lines
Lines in /etc/group longer than 64 characters breaks the current
implementation of group parser. This is caused by bufio.Scanner
buffer limit.

Fix by re-using the fix for a similar problem in golang os/user,
namely https://go-review.googlesource.com/c/go/+/283601.

Add some tests.

Co-authored-by: Andrey Bokhanko <andreybokhanko@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 24d5daf54d)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-08 13:18:28 -07:00
Kir Kolyshkin 5fd7b3b7b5 libct/user: ParseGroupFilter: use TrimSpace
Same as in other places (other parsers here, as well as golang os/user
parser and glibc parser all tolerate extra space at BOL and EOL).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 226dfab0bc)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-08 13:18:20 -07:00
Kir Kolyshkin 0025bf6827 libct/user: use []byte more, avoid allocations
Every []byte to string conversion results in a new allocation.
Avoid some by using []byte more.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 120e3a77d8)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-08 13:18:09 -07:00
Maksim An 3745b2be56 [1.0] retry unix.EINTR for container init process
When running a script from an azure file share interrupted syscall
occurs quite frequently, to remedy this add retries around execve
syscall, when EINTR is returned.

Signed-off-by: Maksim An <maksiman@microsoft.com>
(cherry picked from commit e39ad65059)

[Minor conflict in libcontainer/standard_init_linux.go due to missing
commit e918d02139 -- resolved manually]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-08 13:13:16 -07:00
Mrunal Patel 8fad08a3f2 Merge pull request #3075 from kolyshkin/1.0-backport-3051
[1.0] tests/int/no_pivot: fix for new kernels
2021-07-08 16:11:08 -04:00
Kir Kolyshkin e99c0f5ef8 tests/int/no_pivot: fix for new kernels
The test is failing like this:

	not ok 70 runc run --no-pivot must not expose bare /proc
	# (in test file tests/integration/no_pivot.bats, line 20)
	#   `[[ "$output" == *"mount: permission denied"* ]]' failed
	# runc spec (status=0):
	#
	# runc run --no-pivot test_no_pivot (status=1):
	# unshare: write error: Operation not permitted

Apparently, a recent kernel commit db2e718a47984b9d prevents
root from doing unshare -r unless it has CAP_SETFPCAP.

Add the capability for this specific test.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 1bbeadae72)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-07 18:39:49 -07:00
Aleksa Sarai 84113eef6f VERSION: release runc 1.0.0
🎉

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
v1.0.0
2021-06-17 18:11:36 +10:00
Aleksa Sarai 47d37b33cd merge branch 'pr-3022'
Kir Kolyshkin (3):
  libct/cg/fs/blkio: do not set weight == 0
  libct/cg/fs2: set per-device io weight if available
  tests/int/cgroups: add test for bfq per-device weight

LGTMs: AkihiroSuda mrunalp cyphar
Closes #3022
2021-06-17 17:50:36 +10:00
Kir Kolyshkin 2916817278 tests/int/cgroups: add test for bfq per-device weight
This works for both cgroup v1 and v2.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-16 04:51:40 -07:00
Kir Kolyshkin 1036f3f995 libct/cg/fs2: set per-device io weight if available
Per-device weight is supported since kernel v5.4 (kernel commit
795fe54c2a8), so let's set those if supplied.

[v2: implement a more relaxed check in bfqDeviceWeightSupported]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-16 04:51:19 -07:00
Kir Kolyshkin 30d83d4d2f libct/cg/fs/blkio: do not set weight == 0
For per-device weight, you can set weight and/or leaf weight.
The problem is, with the recent fix to use BFQ on cgroup v1,
if per-device weights are set, the code tries to set device
weight to blkio.bfq.weight, and the leaf weight to
blkio.leaf_weight_device. The latter file does not exist on
kernels v5.0, meaning one can not set any per-device weights
at all.

The fix is to only set weights if they are non-zero (i.e. set).

The test case will come in a following commit.

Fixes: 6339d8a0dd
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-14 12:52:30 -07:00
Kir Kolyshkin f093cca13d Merge pull request #3024 from kolyshkin/fscommon-mv
libct/cg: mv fscommon.{Open,Read,Write}File to cgroups
2021-06-14 12:49:18 -07:00
Kir Kolyshkin 8726c701a1 Merge pull request #3017 from wzshiming/fix/setenv
Returns clearer error message for Setenv
2021-06-14 11:13:13 -07:00
Akihiro Suda c4359f8e7d Merge pull request #3005 from adrianreber/2021-06-07-lsm-profile 2021-06-15 01:16:43 +09:00
Kir Kolyshkin d7fc302860 libct/cg/fs*: mark {Open,Read,Write}File as deprecated
... and switch to using the ones from cgroups.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-13 17:17:48 -07:00
Kir Kolyshkin 8f1b4d4a6f libct/cg: mv fscommon.{Open,Read,Write}File to cgroups
This is a better place as cgroups itself is using these.
Should help with moving more stuff common in between fs and fs2 to
fscommon.

Looks big, but this is just moving the code around:

 fscommon/{fscommon,open}.go -> cgroups/file.go
 fscommon/fscommon_test.go   -> cgroups/file_test.go

and fixes for TestMode moved to a different package.

There's no functional change.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-13 12:38:21 -07:00
Shiming Zhang 322c8fd36b Returns clearer error message for setenv
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
2021-06-12 14:32:48 +08:00
Mrunal Patel 93a01cd4d0 Merge pull request #3009 from AkihiroSuda/update-ebpf-wrap
update cilium/ebpf to fix haveBpfProgReplace() check
2021-06-11 15:38:01 -04:00
Mrunal Patel a3813ca249 Merge pull request #3000 from kolyshkin/test-dev-update
libct/int: add device update test
2021-06-11 14:36:49 -04:00
Kir Kolyshkin 0ca4cdad35 Merge pull request #3010 from askervin/5D6_blkio_bfq_weight
libcontainer/cgroups/fs/blkio: support BFQ weight[_device]
2021-06-11 11:30:05 -07:00
Akihiro Suda 46940ed80c update cilium/ebpf to fix haveBpfProgReplace() check
The `errors.Is(err, unix.EINVAL)` check in `haveBpfProgReplace()` was
broken because the `cilium/ebpf` library did not "wrap" errors.
https://github.com/cilium/ebpf/blob/v0.6.0/link/program.go#L72

So the eBPF support of runc was broken for kernel prior to 5.6.

This commit bumps up cilium/ebpf to contain cilium/ebpf PR 320.

Fix opencontainers/runc issue 3008

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-06-12 02:12:25 +09:00