Commit Graph

5049 Commits

Author SHA1 Message Date
Kir Kolyshkin 688ea99e1b runc init: fix double call to ConfigureLogs
I have noticed that ConfigureLogs do not return an error in case logging
was already configured -- instead it just warns about it. So I went
ahead and changed the warning to the actual error...

... only to discover I broke things badly, because in case of runc init
logging is configured twice. The fix is to not configure logging in case
we are init.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-25 18:56:15 -07:00
Kir Kolyshkin dd6c8d76bb main: cast Chmod argument to os.FileMode
This fixes a big red warning in my vim.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-25 18:56:15 -07:00
Kir Kolyshkin 69ec21a12f libct/logs.ForwardLogs: use bufio.Scanner
Error handling is slightly cleaner this way.

While at it, do minor refactoring and fix error logging
in processEntry.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-25 18:56:15 -07:00
Kir Kolyshkin 0300299a72 tests/int/debug.bats: fixups
1. Remove redundant "echo $output" from the first test case, as "runc"
   helper function already logs the output.

2. Show the contents of log.out to stderr, so it case of error we can
   see what is going on.

3. Remove the check that `log.out` file exists. This check is redundant,
   since right after it we do `cat log.out` and check its exit code.

4. Factor out common checks into check_debug.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-25 18:56:15 -07:00
Kir Kolyshkin d38d1f9f79 libcontainer/logs: use int for Config.LogPipeFd
It does not make sense to have a string for a numeric type.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-25 18:56:15 -07:00
Kir Kolyshkin ec7ca2a9d8 Merge pull request #2851 from thaJeztah/fix_build_tags
Fix build-tags in libcontainer/devices
2021-03-22 20:34:23 -07:00
Kir Kolyshkin 010d0a3f8b Merge pull request #2867 from KentaTada/fix-seccomp-kernel-config
script/check-config.sh: add CONFIG_SECCOMP_FILTER
2021-03-22 15:53:46 -07:00
Akihiro Suda 3cc9670dd4 Merge pull request #2863 from thaJeztah/runc_refactor_caps
capabilities.Caps: use a map for capability-types
2021-03-22 14:33:35 +09:00
Akihiro Suda e112c95b30 Merge pull request #2852 from thaJeztah/apparmor_once 2021-03-22 03:07:26 +09:00
Kenta Tada d76309f911 script/check-config.sh: add CONFIG_SECCOMP_FILTER
CONFIG_SECCOMP_FILTER is actually used in runc.

Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
2021-03-21 13:55:12 +09:00
Sebastiaan van Stijn 997e89420d capabilities.Caps: use a map for capability-types
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-03-19 11:21:08 +01:00
Sebastiaan van Stijn 513d89eec5 capabilities: use BOUNDING/AMBIENT instead of their alias
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-03-17 17:10:15 +01:00
Akihiro Suda 0ae1475066 Merge pull request #2798 from adrianreber/2021-02-08-nested-bind.mounts
Correctly restore containers with nested bind mounts
2021-03-17 12:47:21 +09:00
Akihiro Suda 29eafff43e Merge pull request #2857 from thaJeztah/bump_runtime_spec 2021-03-17 07:58:14 +09:00
Sebastiaan van Stijn dd2caace16 go.mod: runtime-spec v1.0.3-0.20210316141917-a8c4a9ee0f6b
full diff: https://github.com/opencontainers/runtime-spec/compare/e6143ca7d51d...a8c4a9ee0f6b

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-03-16 16:57:38 +01:00
Sebastiaan van Stijn a608b7e725 libcontainer/apparmor: use sync.Once for AppArmor detection
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-03-16 15:12:55 +01:00
Sebastiaan van Stijn d6e892489f Fix build-tags in libcontainer/devices
Allows importing this package on Windows (for the types)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-03-14 19:11:19 +01:00
Kir Kolyshkin 249bca0a13 Merge pull request #2841 from AdamKorcz/fuzz1
tests: Move fuzzers upstream
2021-03-10 12:00:43 -08:00
Akihiro Suda 097062ae71 Merge pull request #2842 from kolyshkin/cpt-lazy-full-log
tests/checkpoint: show full log lazy pages cpt
2021-03-10 13:30:33 +09:00
AdamKorcz 2ae5665351 Move fuzzers upstream
Signed-off-by: AdamKorcz <adam@adalogics.com>
2021-03-09 10:07:11 +00:00
Kir Kolyshkin 053e15c001 tests/checkpoint: show full log lazy pages cpt
Sometimes the test fails without any clear diagnostics:

> not ok 16 checkpoint --lazy-pages and restore
> (in test file tests/integration/checkpoint.bats, line 191)
>  `[ "$out" = "0000000 000000 0000001" ]' failed
> ...
> criu failed: type NOTIFY errno 3\nlog file: work-dir/dump.log

We look for and print errors via grep, but in the above case
there are nothing that is denoted error in the log.

So, let's show the damn log in its entirely (note it is only shown
if test fails).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-08 15:04:40 -08:00
Kir Kolyshkin 59ad417c14 Merge pull request #2833 from kolyshkin/curl-retry
curl: add --retry 5
2021-03-05 20:00:53 -08:00
Mrunal Patel 497cd0c96e Merge pull request #2829 from KentaTada/refactor-mode-of-factory
libcontainer/factory*: adjust the file mode
2021-03-04 15:42:13 -08:00
Mrunal Patel 50ac158d05 Merge pull request #2809 from kolyshkin/rm-old-hacks
Makefile cleanups
2021-03-04 15:41:19 -08:00
Mrunal Patel 3742bfe891 Merge pull request #2824 from Iceber/fix-integration-tests-readme
fix integration tests README.md
2021-03-04 15:40:24 -08:00
Kir Kolyshkin e618a6d5ee curl: add --retry 5
Sometimes github gives up 5xx errors, for example:

> panic: getImages error exit status 1 (output: curl: (22) The requested URL returned error: 502
> Failed to get https://github.com/docker-library/busybox/raw/dist-i386/stable/glibc/busybox.tar.xz

This is unfortunate but temporary, and adding --retry should handle
at least some cases, improving CI stability.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-03-04 15:37:59 -08:00
Akihiro Suda d61ca65147 Merge pull request #2831 from cyphar/cyphar-email
MAINTAINERS: update Aleksa's email
2021-03-04 14:05:35 +09:00
Aleksa Sarai 4b98e4a73a MAINTAINERS: update Aleksa's email
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-03-04 10:38:35 +11:00
Kenta Tada 8a3484b736 libcontainer/factory*: adjust the file mode
This commit adjusts the file mode to use the latest golang style
Related to #2625

Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
2021-03-02 16:26:36 +09:00
Kir Kolyshkin 1820c42547 Merge pull request #2768 from kolyshkin/unit-386
ci/gha: add i386 unit test
2021-02-25 18:23:36 -08:00
Akihiro Suda d56a9c67ac Merge pull request #2812 from kolyshkin/memory-tight 2021-02-26 10:52:17 +09:00
Iceber Gu 71ca643213 fix integration tests README.md
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2021-02-26 02:23:44 +08:00
Akihiro Suda 8bddca5118 Merge pull request #2819 from Iceber/fix-comment
libcontainer: fix LinuxFactory comments
2021-02-25 18:08:04 +09:00
Mrunal Patel d11985a586 Merge pull request #2799 from kolyshkin/race1
Fix data races, enable testing with -race
2021-02-24 16:37:34 -08:00
Iceber Gu 916654fffa libcontainer: fix LinuxFactory comments
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2021-02-24 15:51:06 +08:00
Aleksa Sarai c153261830 merge branch 'pr-2786'
Daniel Dao (1):
  Do not convert blkio weight value using blkio->io conversion scheme

LGTMs: @kolyshkin @AkihiroSuda @cyphar
Closes #2786
2021-02-24 18:29:27 +11:00
Kir Kolyshkin 65116710dd Merge pull request #2757 from kolyshkin/test-int-cleanups
tests/int: cleanups
2021-02-23 20:50:17 -08:00
Daniel Dao c3ffd2ef81 Do not convert blkio weight value using blkio->io conversion scheme
bfq weight controller (i.e. io.bfq.weight if present) is still using the
same bfq weight scheme (i.e 1->1000, see [1].) Unfortunately the
documentation for this was wrong, and only fixed recently [2].

Therefore, if we map blkio weight to io.bfq.weight, there's no need to
do any conversion. Otherwise, we will try to write invalid value which
results in error such as:

```
time="2021-02-03T14:55:30Z" level=error msg="container_linux.go:367: starting container process caused: process_linux.go:495: container init caused: process_linux.go:458: setting cgroup config for procHooks process caused: failed to write \"7475\": write /sys/fs/cgroup/runc-cgroups-integration-test/test-cgroup/io.bfq.weight: numerical result out of range"
```

[1] https://github.com/torvalds/linux/blob/master/Documentation/block/bfq-iosched.rst
[2] https://github.com/torvalds/linux/commit/65752aef0a407e1ef17ec78a7fc31ba4e0b360f9

Signed-off-by: Daniel Dao <dqminh89@gmail.com>
2021-02-23 19:46:16 -08:00
Kir Kolyshkin 38b2dd391d runc exec: report possible OOM kill
An exec may fail due to memory shortage (cgroup memory limits being too
tight), and an error message provided in this case is clueless:

> $ sudo ../runc/runc exec xx56 top
> ERRO[0000] exec failed: container_linux.go:367: starting container process caused: read init-p: connection reset by peer

Same as the previous commit for run/start, check the OOM kill counter
and report an OOM kill.

The differences from run are

1. The container is already running and OOM kill counter might not be
   zero.  This is why we have to read the counter before exec and after
   it failed.

2. An unrelated OOM kill event might occur in parallel with our exec
   (and I see no way to find out which process was killed, except to
   parse kernel logs which seems excessive and not very reliable).
   This is why we report _possible_ OOM kill.

With this commit, the error message looks like:

> ERRO[0000] exec failed: container_linux.go:367: starting container process caused: process_linux.go:105: possibly OOM-killed caused: read init-p: connection reset by peer

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:16:33 -08:00
Kir Kolyshkin 5d0ffbf9c8 runc start/run: report OOM
In some cases, container init fails to start because it is killed by
the kernel OOM killer. The errors returned by runc in such cases are
semi-random and rather cryptic. Below are a few examples.

On cgroup v1 + systemd cgroup driver:

> process_linux.go:348: copying bootstrap data to pipe caused: write init-p: broken pipe

> process_linux.go:352: getting the final child's pid from pipe caused: EOF

On cgroup v2:

> process_linux.go:495: container init caused: read init-p: connection reset by peer

> process_linux.go:484: writing syncT 'resume' caused: write init-p: broken pipe

This commits adds the OOM method to cgroup managers, which tells whether
the container was OOM-killed. In case that has happened, the original error
is discarded (unless --debug is set), and the new OOM error is reported
instead:

> ERRO[0000] container_linux.go:367: starting container process caused: container init was OOM-killed (memory limit too low?)

Also, fix the rootless test cases that are failing because they expect
an error in the first line, and we have an additional warning now:

> unable to get oom kill count" error="no directory specified for memory.oom_control

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:15:33 -08:00
Kir Kolyshkin 7e137b9044 libct/cg/fs2/hugetlb: use fscommon.GetValueByKey
This makes the code simpler and more future-proof, in case
any more values will appear in hugetlb.*.events.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 9fa65f6607 libct/cg/fscommon: add GetValueByKey
Generalize the libct/getValueFromCgroup() as fscommon.GetValueByKey(),
and document it.

No changes other than using fscommon.ParseUint to convert the value.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin c54c3f852d libcontainer/notify_linux_v2: use fscommon.ReadFile
This is to benefit from openat2() implementation, on kernels
that support it. Theoretically this also improves security.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 494f900e91 libct/cg/fscommon: rename/facelift GetCgroupParamKeyValue
1. This is the only function in the package with Get prefix
   that does not read a file (but parses a string). Rename
   accordingly, and convert the callers.

	GetCgroupParamKeyValue -> ParseKeyValue

2. Use strings.Split rather than strings.Fields. Split by a space
   is 2x faster, plus we can limit the splitting. The downside is
   we have to strip a newline in one of the callers.

3. Improve the doc and the code flow.

4. Fix a test case with invalid data (spaces at BOL).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 1880d2fc05 libct/cg/fs/memory: handle EBUSY
EBUSY when trying to set memory limit may mean the new limit is too low
(lower than the current usage, and the kernel can't do anything).
Provide a more specific error for such case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 27fd3fc3ce libct/cg/fs: setMemoryAndSwap: refactor
1. Factor out setMemory and setSwap
2. Pass cgroup.Resources (rather than cgroup) to setMemoryAndSwap().
3. Merge the duplicated "set memory, set swap" case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 3cced523a5 libct/cg/fs/memory: optimize Set
Currently, we read and parse 5 different files while we only need 1.

Use GetCgroupParamUint() directly to get current limit.

While at it, remove the workaround previously needed for the unit test,
and make it a bit more verbose.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 65c2d3c2b6 tests/int/update: add test case for PR #592
Add integration test coverage for code initially added by commit
d8b8f76c4f ("Fix problem when update memory and swap memory",
2016-04-05).

This is in addition to existing unit test,
TestMemorySetSwapSmallerThanMemory.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Mrunal Patel f36d64d683 Merge pull request #2814 from kolyshkin/systemd-apply
libct/cgroups/systemd: don't set limits in Apply
2021-02-23 15:16:43 -08:00
Mrunal Patel e00273e09d Merge pull request #2816 from odinuge/cgroup-v2-cache
Fix memory stats for cache in fs2
2021-02-23 14:59:42 -08:00