Commit Graph

138 Commits

Author SHA1 Message Date
Kir Kolyshkin 79a8647b81 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 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>
2021-03-30 19:58:09 -07:00
Kir Kolyshkin b774454736 libct/int: fix a data race
Fix for the following:

$ sudo go test -race -v ./libcontainer/integration/
=== RUN   TestUsernsCheckpoint
==================
WARNING: DATA RACE
Write at 0x00c00019e650 by goroutine 15:
  bytes.(*Buffer).ReadFrom()
      /usr/lib/golang/src/bytes/buffer.go:200 +0x48
  io.copyBuffer()
      /usr/lib/golang/src/io/io.go:395 +0x3fe
  io.Copy()
      /usr/lib/golang/src/io/io.go:368 +0x7a
  os/exec.(*Cmd).writerDescriptor.func1()
      /usr/lib/golang/src/os/exec/exec.go:311 +0x4a
  os/exec.(*Cmd).Start.func1()
      /usr/lib/golang/src/os/exec/exec.go:441 +0x38

Previous write at 0x00c00019e650 by goroutine 12:
  bytes.(*Buffer).ReadFrom()
      /usr/lib/golang/src/bytes/buffer.go:200 +0x48
  io.copyBuffer()
      /usr/lib/golang/src/io/io.go:395 +0x3fe
  io.Copy()
      /usr/lib/golang/src/io/io.go:368 +0x7a
  os/exec.(*Cmd).writerDescriptor.func1()
      /usr/lib/golang/src/os/exec/exec.go:311 +0x4a
  os/exec.(*Cmd).Start.func1()
      /usr/lib/golang/src/os/exec/exec.go:441 +0x38

Goroutine 15 (running) created at:
  os/exec.(*Cmd).Start()
      /usr/lib/golang/src/os/exec/exec.go:440 +0xaaa
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).criuSwrk()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:1490 +0x5f7
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).Restore()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:1398 +0x29ef
  github.com/opencontainers/runc/libcontainer/integration.testCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:204 +0x1898
  github.com/opencontainers/runc/libcontainer/integration.TestUsernsCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:48 +0x177
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:1123 +0x202

Goroutine 12 (finished) created at:
  os/exec.(*Cmd).Start()
      /usr/lib/golang/src/os/exec/exec.go:440 +0xaaa
  github.com/opencontainers/runc/libcontainer.(*initProcess).start()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/process_linux.go:313 +0xda
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).start()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:366 +0xb0
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).Start()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:263 +0x27b
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).Run()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:273 +0x46
  github.com/opencontainers/runc/libcontainer/integration.testCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:108 +0x941
  github.com/opencontainers/runc/libcontainer/integration.TestUsernsCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:48 +0x177
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:1123 +0x202
==================
==================
WARNING: DATA RACE
Read at 0x00c00019e630 by goroutine 15:
  bytes.(*Buffer).Len()
      /usr/lib/golang/src/bytes/buffer.go:73 +0x58
  bytes.(*Buffer).grow()
      /usr/lib/golang/src/bytes/buffer.go:118 +0x4f
  bytes.(*Buffer).ReadFrom()
      /usr/lib/golang/src/bytes/buffer.go:202 +0x7c
  io.copyBuffer()
      /usr/lib/golang/src/io/io.go:395 +0x3fe
  io.Copy()
      /usr/lib/golang/src/io/io.go:368 +0x7a
  os/exec.(*Cmd).writerDescriptor.func1()
      /usr/lib/golang/src/os/exec/exec.go:311 +0x4a
  os/exec.(*Cmd).Start.func1()
      /usr/lib/golang/src/os/exec/exec.go:441 +0x38

Previous write at 0x00c00019e630 by goroutine 12:
  bytes.(*Buffer).ReadFrom()
      /usr/lib/golang/src/bytes/buffer.go:209 +0x1c4
  io.copyBuffer()
      /usr/lib/golang/src/io/io.go:395 +0x3fe
  io.Copy()
      /usr/lib/golang/src/io/io.go:368 +0x7a
  os/exec.(*Cmd).writerDescriptor.func1()
      /usr/lib/golang/src/os/exec/exec.go:311 +0x4a
  os/exec.(*Cmd).Start.func1()
      /usr/lib/golang/src/os/exec/exec.go:441 +0x38

Goroutine 15 (running) created at:
  os/exec.(*Cmd).Start()
      /usr/lib/golang/src/os/exec/exec.go:440 +0xaaa
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).criuSwrk()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:1490 +0x5f7
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).Restore()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:1398 +0x29ef
  github.com/opencontainers/runc/libcontainer/integration.testCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:204 +0x1898
  github.com/opencontainers/runc/libcontainer/integration.TestUsernsCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:48 +0x177
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:1123 +0x202

Goroutine 12 (finished) created at:
  os/exec.(*Cmd).Start()
      /usr/lib/golang/src/os/exec/exec.go:440 +0xaaa
  github.com/opencontainers/runc/libcontainer.(*initProcess).start()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/process_linux.go:313 +0xda
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).start()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:366 +0xb0
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).Start()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:263 +0x27b
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).Run()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:273 +0x46
  github.com/opencontainers/runc/libcontainer/integration.testCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:108 +0x941
  github.com/opencontainers/runc/libcontainer/integration.TestUsernsCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:48 +0x177
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:1123 +0x202
==================
==================
WARNING: DATA RACE
Read at 0x00c00019e648 by goroutine 15:
  bytes.(*Buffer).Len()
      /usr/lib/golang/src/bytes/buffer.go:73 +0x7e
  bytes.(*Buffer).grow()
      /usr/lib/golang/src/bytes/buffer.go:118 +0x4f
  bytes.(*Buffer).ReadFrom()
      /usr/lib/golang/src/bytes/buffer.go:202 +0x7c
  io.copyBuffer()
      /usr/lib/golang/src/io/io.go:395 +0x3fe
  io.Copy()
      /usr/lib/golang/src/io/io.go:368 +0x7a
  os/exec.(*Cmd).writerDescriptor.func1()
      /usr/lib/golang/src/os/exec/exec.go:311 +0x4a
  os/exec.(*Cmd).Start.func1()
      /usr/lib/golang/src/os/exec/exec.go:441 +0x38

Previous write at 0x00c00019e648 by goroutine 12:
  bytes.(*Buffer).grow()
      /usr/lib/golang/src/bytes/buffer.go:147 +0x2d7
  bytes.(*Buffer).ReadFrom()
      /usr/lib/golang/src/bytes/buffer.go:202 +0x7c
  io.copyBuffer()
      /usr/lib/golang/src/io/io.go:395 +0x3fe
  io.Copy()
      /usr/lib/golang/src/io/io.go:368 +0x7a
  os/exec.(*Cmd).writerDescriptor.func1()
      /usr/lib/golang/src/os/exec/exec.go:311 +0x4a
  os/exec.(*Cmd).Start.func1()
      /usr/lib/golang/src/os/exec/exec.go:441 +0x38

Goroutine 15 (running) created at:
  os/exec.(*Cmd).Start()
      /usr/lib/golang/src/os/exec/exec.go:440 +0xaaa
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).criuSwrk()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:1490 +0x5f7
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).Restore()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:1398 +0x29ef
  github.com/opencontainers/runc/libcontainer/integration.testCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:204 +0x1898
  github.com/opencontainers/runc/libcontainer/integration.TestUsernsCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:48 +0x177
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:1123 +0x202

Goroutine 12 (finished) created at:
  os/exec.(*Cmd).Start()
      /usr/lib/golang/src/os/exec/exec.go:440 +0xaaa
  github.com/opencontainers/runc/libcontainer.(*initProcess).start()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/process_linux.go:313 +0xda
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).start()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:366 +0xb0
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).Start()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:263 +0x27b
  github.com/opencontainers/runc/libcontainer.(*linuxContainer).Run()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:273 +0x46
  github.com/opencontainers/runc/libcontainer/integration.testCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:108 +0x941
  github.com/opencontainers/runc/libcontainer/integration.TestUsernsCheckpoint()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/integration/checkpoint_test.go:48 +0x177
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:1123 +0x202
==================
    testing.go:1038: race detected during execution of test
--- FAIL: TestUsernsCheckpoint (0.62s)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 15:33:24 -08:00
Kir Kolyshkin 5ab0588432 ci: untangle getting test images
This simplifies and optimizes getting container images used for tests.

Currently, we have three different ways of getting images:

1. (for hello-world) the image is in this repo under tests/integration/testdata.

2. (for busybox) download it from github (the repo that is used for
   preparing official Docker image) using curl.

3. (for debian) download from Docker hub, using skopeo and umoci.

To further complicate things, we have to do this downloading in multiple
scenarios (at least 4): locally, in github CI, from Dockefile, inside a
Vagrant VM. For each scenario, we have to install skopeo and umoci, and
those two are not yet universally available for all the distros that we
use.

Yet another complication is those images are used for tests/integration
(bats-driven tests) as well as for libcontainer/integration (go tests).
The tests in libcontainer/integration rely on busybox being available
from /busybox, and the bats tests just download the images to a
temporary location during every run.

It is also hard to support CI for other architectures, because all
the machinery for preparing images is so complicated.

This commit is an attempt to simplify and optimize getting images,
mostly by getting rid of skopeo and umoci dependencies, but also
by moving the download logic into one small shell script, which
is used from all the places.

Benefits:

 - images (if not present) are only downloaded once;
 - same images are used for both kind of tests (go and bats);
 - same images are used for local and inside-docker tests
   (because source directory is mounted into container);
 - the download logic is located within 1 simple shell script.

[v2: fix eval; more doc to get-images; print URL if curl failed]
[v3: use "slim" debian, twice as small]
[v4: fix not using $image in setup_bundle]
[v5: don't remove TESTDATA from helpers.bash]
[v6: add i386 support]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-02 16:03:29 -08:00
Kir Kolyshkin 426aa416b2 libct/int/TestExecInTTY: skip
This test is racy and so far I can't figure out how to fix it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-19 09:40:16 -08:00
Kir Kolyshkin c30cd3cddd libct/int/TestExecInTTY: fix error reporting
As buf is instantiated outside the loop, it is appended to,
so if/once an error happens, it contains the output of all previous
iterations. Not a big problem but looks a bit untidy.

Move the declaration to inside the loop.

Fixes: 06a684d6a7
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-19 09:40:16 -08:00
Kir Kolyshkin dac0c1e34a console.ClearONLCR: move it back
This reverts most of commit 24c05b7, as otherwise it causes
a few regressions (docker cli, TestDockerSwarmSuite/TestServiceLogsTTY).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-19 09:39:54 -08:00
Kir Kolyshkin 06a684d6a7 libct/int/TestExecInTTY: repeat the test 300 times
This is to increase the chance to hit the recently fixed race.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-07 13:34:46 -08:00
Kir Kolyshkin fedaa2abed TestExecInTTY: simplify, improve error reporting
Simplify the tty code by using 1 goroutine instead of 2.

Improve error reporting by wrapping the errors.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-07 13:34:41 -08:00
Kir Kolyshkin 24c05b71fa tty: fix ClearONLCR race
The TestExecInTTY test case is sometimes failing like this:

> execin_test.go:332: unexpected carriage-return in output "PID USER TIME COMMAND\r\n 1 root 0:00 cat\r\n 7 root 0:00 ps\r\n"

or this:

> execin_test.go:332: unexpected carriage-return in output "PID USER TIME COMMAND\r\n 1 root 0:00 cat\n 7 root 0:00 ps\n"

(this is easy to repro with `go test -run TestExecInTTY -count 1000`).

This is caused by a race between

 - an Init() (in this case it is is (*linuxSetnsInit.Init(), but
   (*linuxStandardInit).Init() is no different in this regard),
   which creates a pty pair, sends pty master to runc, and execs
   the container process,

and

 - a parent runc process, which receives the pty master fd and calls
   ClearONLCR() on it.

One way of fixing it would be to add a synchronization mechanism
between these two, so Init() won't exec the process until the parent
sets the flag. This seems excessive, though, as we can just move
the ClearONLCR() call to Init(), putting it right after console.NewPty().

Note that bug only happens in the TestExecInTTY test case, but
from looking at the code it seems like it can happen in runc run
or runc exec, too.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-07 13:33:00 -08:00
Kir Kolyshkin 2143b36835 libct/int/execin_tty: do help debug a flake
Do help to debug https://github.com/opencontainers/runc/issues/2425.

Previous commit 1909051b9c modified the code in the wrong place.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-12-18 09:00:33 -08:00
Akihiro Suda b923ff4373 Merge pull request #2701 from kolyshkin/exec-tty
libct/int/execin_tty: help debug a flake
2020-12-05 09:09:34 +09:00
Kir Kolyshkin 1909051b9c libct/int/execin_tty: help debug a flake
This helps to debug https://github.com/opencontainers/runc/issues/2425

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-12-03 17:29:54 -08:00
Kir Kolyshkin 3de5c51454 libct/int: don't hardcode CAP_NET_ADMIN
... use the one from unix instead.

Coincidentally, this fixes this warning from gosimple linter:

> libcontainer/integration/exec_test.go:448:2: S1021: should merge variable declaration with assignment on next line (gosimple)
>	var netAdminBit uint
>	^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-12-03 10:24:27 -08:00
Kir Kolyshkin 3387422bf9 libct/int: fix "simple" linter warnings
This fixes the following warnings:

> libcontainer/integration/exec_test.go:369:18: S1030: should use stdout.String() instead of string(stdout.Bytes()) (gosimple)
>	outputStatus := string(stdout.Bytes())
>	                ^
> libcontainer/integration/exec_test.go:422:18: S1030: should use stdout.String() instead of string(stdout.Bytes()) (gosimple)
>	outputStatus := string(stdout.Bytes())
>	                ^
> libcontainer/integration/exec_test.go:486:18: S1030: should use stdout.String() instead of string(stdout.Bytes()) (gosimple)
>	outputGroups := string(stdout.Bytes())
>	                ^
> libcontainer/integration/execin_test.go:191:18: S1030: should use stdout.String() instead of string(stdout.Bytes()) (gosimple)
>	outputGroups := string(stdout.Bytes())
>	                ^
> libcontainer/integration/execin_test.go:474:9: S1030: should use stdout.String() instead of string(stdout.Bytes()) (gosimple)
>	out := string(stdout.Bytes())
>	       ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-12-03 10:24:27 -08:00
Sebastiaan van Stijn 4fc2de77e9 libcontainer/devices: remove "Device" prefix from types
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-12-01 11:11:23 +01:00
Sebastiaan van Stijn 677baf22d2 libcontainer: isolate libcontainer/devices
Move the Device-related types to libcontainer/devices, so that
the package can be used in isolation. Aliases have been created
in libcontainer/configs for backward compatibility.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-12-01 11:11:21 +01:00
Mauricio Vásquez ac5ec5e32f libcontainer/integration: fix unit test
Fix a merge issue between 0aa0fae393 ("Kill all processes in cgroup even if init process Wait fails")
& 73d93eeb01 ("libct/int: make newTemplateConfig argument a struct") that
resulted in passing the wrong datatype to newTemplateConfig in
TestPIDHostInitProcessWait.

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
2020-10-23 07:56:11 -05:00
Mrunal Patel 07e35a7a40 Merge pull request #2600 from kolyshkin/libct-int-wut
libcontainer/integration: fix cgroupv1 + systemd tests
2020-10-22 21:05:15 -07:00
Kir Kolyshkin 44f221e2fc Merge pull request #2633 from chaitanyabandi/2632-fix
Kill processes in cgroup even if process Wait fails
2020-10-08 10:51:13 -07:00
Chaitanya Bandi 0aa0fae393 Kill all processes in cgroup even if init process Wait fails
If the cgroup's init process doesn't complete successfully, Wait returns a
non-nil error. We should still kill all the process in the cgroup if process
namespace is shared. Otherwise, it may result in process leak.

Fixes #2632

Signed-off-by: Chaitanya Bandi <kbandi@cs.stonybrook.edu>
2020-10-08 01:26:34 +00:00
Amim Knabben 978fa6e906 Fixing some lint issues
Signed-off-by: Amim Knabben <amim.knabben@gmail.com>
2020-10-06 14:44:14 -04:00
Kir Kolyshkin fa47f95872 libct/int/newTemplateConfig: add systemd support
... and properly set ScopePrefix, Name and Parent for a systemd case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 20:51:02 -07:00
Kir Kolyshkin 9135d99c94 libct/int/newTemplateConfig: add userns param
It seems that a few tests add a cgroup mount in case userns is not set.
Let's do it inside newTemplateConfig() for all tests.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 20:51:02 -07:00
Kir Kolyshkin 73d93eeb01 libct/int: make newTemplateConfig argument a struct
...so we can add more fields later.

This commit is mostly courtesy of

sed -i 's/newTemplateConfig(rootfs)/newTemplateConfig(\&tParam{rootfs: rootfs})/g'

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 20:51:02 -07:00
Sebastiaan van Stijn 28b452bf65 libcontainer: unconvert
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-10-01 18:36:56 +02:00
Sebastiaan van Stijn b3a8b0742c libcontainer: prefer bytes.TrimSpace() over strings.TrimSpace()
Perform trimming before converting to a string, which should be
somewhat more performant.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-10-01 18:36:53 +02:00
Sebastiaan van Stijn 8bf216728c use string-concatenation instead of sprintf for simple cases
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-30 10:51:59 +02:00
Kir Kolyshkin b006f4a180 libct/cgroups: support Cgroups.Resources.Unified
Add support for unified resource map (as per [1]), and add some test
cases for the new functionality.

[1] https://github.com/opencontainers/runtime-spec/pull/1040

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-24 15:29:35 -07:00
Kir Kolyshkin 2de0b5aaf3 libct/integration: enable some tests for cgroupv2
The only two tests that are still skipped on v2 are kmem
and invalid CpuShares test -- since v2 does not support either.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-08 19:19:31 -07:00
Xiaodong Liu f57bb2fe3d fix TestPidsSystemd and TestRunWithKernelMemorySystemd test error
Signed-off-by: Xiaodong Liu <liuxiaodong@loongson.cn>
2020-07-09 09:36:03 +08:00
Renaud Gaubert 2f7bdf9d3b Tests the new Hook
Signed-off-by: Renaud Gaubert <rgaubert@nvidia.com>
2020-06-19 02:39:20 +00:00
Akihiro Suda bd236e50a5 integration: skip checkpoint tests if criu binary not found
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-06-10 13:18:58 +09:00
Giuseppe Scrivano 41aa19662b libcontainer: honor seccomp errnoRet
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-05-20 09:11:55 +02:00
Aleksa Sarai 24388be71e configs: use different types for .Devices and .Resources.Devices
Making them the same type is simply confusing, but also means that you
could accidentally use one in the wrong context. This eliminates that
problem. This also includes a whole bunch of cleanups for the types
within DeviceRule, so that they can be used more ergonomically.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2020-05-13 17:38:45 +10:00
Aleksa Sarai b2bec9806f cgroup: devices: eradicate the Allow/Deny lists
These lists have been in the codebase for a very long time, and have
been unused for a large portion of that time -- specconv doesn't
generate them and the only user of these flags has been tests (which
doesn't inspire much confidence).

In addition, we had an incorrect implementation of a white-list policy.
This wasn't exploitable because all of our users explicitly specify
"deny all" as the first rule, but it was a pretty glaring issue that
came from the "feature" that users can select whether they prefer a
white- or black- list. Fix this by always writing a deny-all rule (which
is what our users were doing anyway, to work around this bug).

This is one of many changes needed to clean up the devices cgroup code.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2020-05-13 17:38:45 +10:00
Kir Kolyshkin 20959b1666 libcontainer/integration/checkpoint_test: simplify
Since commit 9280e3566d it is not longer needed to have `cgroup2'
mount.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-04-23 15:22:32 -07:00
Michael Crosby 9ec5b03e5a Merge pull request #2259 from adrianreber/v2-test
Add minimal cgroup2 checkpoint/restore support
2020-03-31 15:01:18 -04:00
Adrian Reber 3e99aa3628 Fix checkpoint/restore tests on Fedora 31
The Travis tests running on Fedora 31 with cgroup2 on Vagrant had the
CRIU parts disabled because of a couple of problems.

One problem was a bug in runc and CRIU handling that Andrei fixed.

In addition four patches from the upcoming  CRIU 3.14 are needed for
minimal cgroup2 support (freezer and mounting of cgroup2). With Andrei's
fix and the CRIU cgroup2 support and the runc CRIU cgroup2 integration
it is now possible the checkpoint integration tests again on the Fedora
Vagrant cgroup2 based integration test.

To run CRIU based tests the modules of Fedora 31 (the test host system)
are mounted inside of the container used to test runc in the buster
based container with -v /lib/modules:/lib/modules.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-03-31 16:36:36 +02:00
Mrunal Patel 33c6125da6 systemd: Export IsSystemdRunning() function
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2020-03-30 15:24:06 -07:00
Mrunal Patel 981dbef514 Merge pull request #2226 from avagin/runsc-restore-cmd-wait
restore: fix a race condition in process.Wait()
2020-03-15 18:48:16 -07:00
Andrei Vagin 269ea385a4 restore: fix a race condition in process.Wait()
Adrian reported that the checkpoint test stated failing:
=== RUN   TestCheckpoint
--- FAIL: TestCheckpoint (0.38s)
    checkpoint_test.go:297: Did not restore the pipe correctly:

The problem here is when we start exec.Cmd, we don't call its wait
method. This means that we don't wait cmd.goroutines ans so we don't
know when all data will be read from process pipes.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-02-10 10:21:08 -08:00
Boris Popovschi 3b992087b8 Fix skip message for cgroupv2
Signed-off-by: Boris Popovschi <zyqsempai@mail.ru>
2020-02-03 14:27:12 +02:00
Akihiro Suda 55f8c254be temporarily disable CRIU tests
Ubuntu kernel is temporarily broken: https://github.com/opencontainers/runc/pull/2198#issuecomment-571124087

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-01-14 11:18:44 +09:00
Akihiro Suda ccd4436fc4 .travis.yml: add Fedora 31 vagrant box (for cgroup2)
As the baby step, only unit tests are executed.

Failing tests are currently skipped and will be fixed in follow-up PRs.

Fix #2124

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2019-10-31 16:53:01 +09:00
Aleksa Sarai 565325fc36 integration: fix mis-use of libcontainer.Factory
For some reason, libcontainer/integration has a whole bunch of incorrect
usages of libcontainer.Factory -- causing test failures with a set of
security patches that will be published soon. Fixing ths is fairly
trivial (switch to creating a new libcontainer.Factory once in each
process, rather than creating one in TestMain globally).

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2019-01-24 23:12:48 +13:00
W. Trevor King e23868603a libcontainer: Set 'status' in hook stdin
Finish off the work started in a344b2d6 (sync up `HookState` with OCI
spec `State`, 2016-12-19, #1201).

And drop HookState, since there's no need for a local alias for
specs.State.

Also set c.initProcess in newInitProcess to support OCIState calls
from within initProcess.start().  I think the cyclic references
between linuxContainer and initProcess are unfortunate, but didn't
want to address that here.

I've also left the timing of the Prestart hooks alone, although the
spec calls for them to happen before start (not as part of creation)
[1,2].  Once the timing gets fixed we can drop the
initProcessStartTime hacks which initProcess.start currently needs.

I'm not sure why we trigger the prestart hooks in response to both
procReady and procHooks.  But we've had two prestart rounds in
initProcess.start since 2f276498 (Move pre-start hooks after container
mounts, 2016-02-17, #568).  I've left that alone too.

I really think we should have len() guards to avoid computing the
state when .Hooks is non-nil but the particular phase we're looking at
is empty.  Aleksa, however, is adamantly against them [3] citing a
risk of sloppy copy/pastes causing the hook slice being len-guarded to
diverge from the hook slice being iterated over within the guard.  I
think that ort of thing is very lo-risk, because:

* We shouldn't be copy/pasting this, right?  DRY for the win :).
* There's only ever a few lines between the guard and the guarded
  loop.  That makes broken copy/pastes easy to catch in review.
* We should have test coverage for these.  Guarding with the wrong
  slice is certainly not the only thing you can break with a sloppy
  copy/paste.

But I'm not a maintainer ;).

[1]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0/config.md#prestart
[2]: https://github.com/opencontainers/runc/issues/1710
[3]: https://github.com/opencontainers/runc/pull/1741#discussion_r233331570

Signed-off-by: W. Trevor King <wking@tremily.us>
2018-11-14 06:49:49 -08:00
Mrunal Patel 4769cdf607 Merge pull request #1916 from crosbymichael/cgns
Add support for cgroup namespace
2018-11-13 12:21:38 -08:00
Yuanhong Peng df3fa115f9 Add support for cgroup namespace
Cgroup namespace can be configured in `config.json` as other
namespaces. Here is an example:

```
"namespaces": [
	{
		"type": "pid"
	},
	{
		"type": "network"
	},
	{
		"type": "ipc"
	},
	{
		"type": "uts"
	},
	{
		"type": "mount"
	},
	{
		"type": "cgroup"
	}
],

```

Note that if you want to run a container which has shared cgroup ns with
another container, then it's strongly recommended that you set
proper `CgroupsPath` of both containers(the second container's cgroup
path must be the subdirectory of the first one). Or there might be
some unexpected results.

Signed-off-by: Yuanhong Peng <pengyuanhong@huawei.com>
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-10-31 10:51:43 -04:00
Dominik Süß 0b412e9482 various cleanups to address linter issues
Signed-off-by: Dominik Süß <dominik@suess.wtf>
2018-10-13 21:14:03 +02:00
Mrunal Patel bd3c4f844a Fix race in runc exec
There is a race in runc exec when the init process stops just before
the check for the container status. It is then wrongly assumed that
we are trying to start an init process instead of an exec process.

This commit add an Init field to libcontainer Process to distinguish
between init and exec processes to prevent this race.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2018-06-01 16:25:58 -07:00