Commit Graph

5293 Commits

Author SHA1 Message Date
Kir Kolyshkin d0cbef576f Makefile: rm go 1.13 workaround
Since go 1.14, mod=vendor is used automatically. Since go 1.16 is now
released, and minimally supported go version is 1.15.

As per commit fbeed5228, remove the go 1.13 workaround.

Fix README to require go 1.14.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 18:58:55 -08:00
Kir Kolyshkin 4019f08d68 make validate: rm go vet
As we already run go vet during CI (via golangci-lint) let's not run it
again.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 18:58:55 -08:00
Kir Kolyshkin f9c2113331 make lint: use golangci-lint
Instead of running just a couple of linters, use the same set as we run
on CI.

NOTE that this is for developers, not scripts, and requires having
golangci-lint installed (see
https://golangci-lint.run/usage/install/#local-installation).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 18:58:55 -08:00
Kir Kolyshkin 671bb97825 Makefile: remove ci target
It is not used since commit e431fe60f8.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 18:58:55 -08:00
Kir Kolyshkin 9594085573 script/validate-gofmt: rm
Add gofmt to golangci-lint configuration, and remove the script
which ran gofmt.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 18:58:55 -08:00
Akihiro Suda f245a1d1ed Merge pull request #2808 from kolyshkin/go116-final 2021-02-17 10:50:03 +09:00
Mrunal Patel 06c1cd8896 Merge pull request #2806 from kolyshkin/readme-gha-badges
README: add gha badges
2021-02-16 14:50:30 -08:00
Kir Kolyshkin 91f0ae1884 ci/gha: bump go 1.16-rc1 -> 1.16.x
As the final go 1.16 is released, rc1 is no longer available.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-16 12:30:05 -08:00
Kir Kolyshkin 5b14a26164 README: add gha badges
Note that validate currently fails on master -- this is tracked
in https://github.com/opencontainers/runc/issues/2627.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-10 14:39:27 -08:00
Mrunal Patel 824e4ad3b8 Merge pull request #2803 from AkihiroSuda/fix-arch-apparmor
apparmor: try attr/apparmor/exec before attr/exec
2021-02-10 10:29:13 -08:00
Adrian Reber 051646a3b0 tests: test nested bind mount restore
This adds a checkpoint/restore test to ensure that nested bind mount
mountpoints are correctly re-created.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-02-10 08:55:57 +01:00
Adrian Reber 705b6cc723 Re-create mountpoints during restore
runc was already re-creating mountpoints before calling CRIU to restore
a container. But mountpoints inside a bind mount were not re-created.

During initial container creation runc will mount bind mounts and then
create the necessary mountpoints for further mounts inside those bind
mounts.

If, for example, one of the bind mounts is a tmpfs and empty before
restore, CRIU will fail re-mounting all mounts because the mountpoints
in the bind mounted tmpfs no longer exist.

CRIU expects all mount points to exist as during checkpointing.

This changes runc to mount bind mounts after mountpoint creation to
ensure nested bind mounts have their mountpoints created before CRIU
does the restore.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-02-10 08:55:57 +01:00
Akihiro Suda 9f1365373d Merge pull request #2796 from vasiliy-ul/ebpf-fix-device-access-check
ebpf: fix device access check
2021-02-10 16:37:01 +09:00
Akihiro Suda f3f563bc0f apparmor: try attr/apparmor/exec before attr/exec
Fix issue 2801

Tested on Arch Linux with the following configuration
```
[root@archlinux ~]# pacman -Q runc containerd docker linux
runc 1.0.0rc93-1
containerd 1.4.3-1
docker 1:20.10.3-1
linux 5.10.14.arch1-1

[root@archlinux ~]# cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-linux root=UUID=bd8aaf58-8735-4fd5-a0c1-804a998f8d57 rw net.ifnames=0 rootflags=compress-force=zstd apparmor=1 lsm=capability,lockdown,yama,bpf,apparmor

[root@archlinux ~]# cat /etc/docker/daemon.json
{
  "runtimes": {
    "runc-tmp": {
      "path": "/tmp/runc"
    }
  }
}

[root@archlinux ~]# docker run -it --rm alpine
docker: Error response from daemon: OCI runtime create failed: container_linux.go:367: starting container process caused: process_linux.go:495: container init caused: apply apparmor profile: apparmor failed to apply profile: write /proc/self/attr/exec: invalid argument: unknown.

[root@archlinux ~]# docker run -it --rm --runtime=runc-tmp alpine
/ # cat /proc/self/attr/apparmor/current
docker-default (enforce)
/ # cat /proc/self/attr/current
cat: read error: Invalid argument
``

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-02-10 16:27:13 +09:00
Kir Kolyshkin 41670e21f0 tests/int: rework/simplify setup and teardown
1. Get rid of fixed ROOT, *_BUNDLE, and CONSOLE_SOCKET dirs.
   Now they are temporary directories created in setup_bundle.

2. Automate containers cleanup: instead of having to specify all
   containers to be removed, list and destroy everything (which is
   now possible since every test case has its own unique root).

3. Randomize cgroup paths so two tests running in parallel won't
   use the same cgroup.

Now it's theoretically possible to execute tests in parallel.
Practically it's not possible yet because bats uses GNU parallel,
which do not provide a terminal for whatever it executes, and
many runc tests (all those that run containers with terminal:
true) needs a tty. This may possibly be addressed later.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-09 20:05:54 -08:00
Mrunal Patel 2dbfa87477 Merge pull request #2793 from cyphar/cgroup2-ebpf-userns
cgroup2: devices: handle eBPF skipping more correctly
2021-02-09 15:12:12 -08:00
Kir Kolyshkin d73b4443ef ci: enable -race from matrix
Add a new test matrix dimension so all tests are run twice,
with and without race detector.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 16:01:14 -08: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 c34a9b1025 tests/int/hooks.bats: don't use DEBIAN_BUNDLE
1. Do not depend on $DEBIAN_BUNDLE, instead use the current directory.

2. Simplify setup() by calling teardown().

3. In teardown(), check that LIBPATH is set.

4. Move global variables into setup.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:49:04 -08:00
Kir Kolyshkin e40a369ea8 tests/int/list.bats: don't use $BUSYBOX_BUNDLE
Use the value of $(pwd) as we cd to bundle dir before running a test.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:47:27 -08:00
Kir Kolyshkin 985546b445 tests/int: BATS_TMPDIR -> BATS_RUN_TMPDIR
It's a little known fact, but BATS_TMPDIR is just /tmp, and it is not
being cleaned by bats after the test.

BATS_RUN_TMPDIR (available since bats 1.2.1) is $BATS_TMPDIR/bats-run-$$
(i.e. it is per bats run and includes PID), and it is cleaned up after
the test (unless --no-tmpdir-cleanup is given).

Use BATS_RUN_TMPDIR for better isolation and cleanup.

[v2: check for BATS_RUN_TMPDIR, effectively requiring bats >= 1.2.1]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:46:58 -08:00
Kir Kolyshkin 85d5fea468 tests/int: stop reusing HELLO_BUNDLE for alt root
Overloading $HELLO_BUNDLE with a second purpose of having an alternative
runc root is confusing.

Instead, let's create a temp directory in setup() and clean it up in
teardown().

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:45:44 -08:00
Kir Kolyshkin 76532fac03 tests/int/events: rm unneeded eval
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:45:44 -08:00
Kir Kolyshkin 497661406e tests/int: use wait_for_container where appropriate
... instead of more generic "retry", to simplify code.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:45:44 -08:00
Kir Kolyshkin 4d6ffa39a0 tests/int/helpers: reimplement wait_for_container
... by using retry, to avoid code duplication.

While at it, make it check the number of arguments and error out on
invalid usage.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:45:44 -08:00
Kir Kolyshkin e7052dcd83 tests/int/spec.bats: don't use HELLO_BUNDLE
All tests are run with cd to bundle directory, so
let's just use $(pwd).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:45:44 -08:00
Kir Kolyshkin 0cfc2e327d tests/int: rm teardown_running_container_inroot
It is only used in a couple of places and is easy to replace
with ROOT=xxx teardown_running_container.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:45:44 -08:00
Kir Kolyshkin 78f0e4b277 tests/int: rm wait_for_container_inroot
Since commit abd0515816 it is no longed used.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:45:44 -08:00
Kir Kolyshkin 64d5702f02 tests/int: don't depend on BUSYBOX_BUNDLE var
All the tests are run with cd to bundle directory, so
it does not make ense to explicitly specify it.

This relies on the feature of functions like set_cgroups_path
or update_config to use current directory by default.

In those cases where we need to change the directory
(runc create/run -b), save the current one and use it later.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:45:44 -08:00
Vasiliy Ulyanov efb8552b05 tests/int: add device access test
The test verifies if the device file can be queried using
'access(dev_name, F_OK)' when the permissions are set to 'rw'. The call
does not explicitly trigger read or write access but should succeed.

Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
2021-02-08 14:14:14 +01:00
Vasiliy Ulyanov 81707abd33 ebpf: fix device access check
Checking the access mode as bellow

    if (R3 & bpfAccess == 0 /* use R1 as a temp var */) goto next

does not handle correctly device file probing with:

    access(dev_name, F_OK)

F_OK does not trigger read or write access. Instead the access type in
R3 in that case will be zero and the check will not pass even if "rw" is
allowed for the device file. Comparing the 'masked' access type with the
requested one solves the issue:

    if (R3 & bpfAccess != R3 /* use R1 as a temp var */) goto next

Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
2021-02-07 19:33:10 +01:00
Aleksa Sarai 94ae7afa36 merge branch 'pr-2791'
Kir Kolyshkin (1):
  cgroupv1 freezer: thaw to increase freeze chances

LGTMs: @cyphar @dqminh
Closes #2791
2021-02-07 19:04:04 +11:00
Kir Kolyshkin c342872276 libct/config: fix a data race
As reported by go test -race ./libcontainer/configs:

=== RUN   TestCommandHookRunTimeout
==================
WARNING: DATA RACE
Read at 0x00c000202230 by goroutine 23:
  os/exec.(*Cmd).Wait()
      /usr/lib/golang/src/os/exec/exec.go:502 +0x91
  github.com/opencontainers/runc/libcontainer/configs.Command.Run()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/configs/config.go:390 +0x58c
  github.com/opencontainers/runc/libcontainer/configs_test.TestCommandHookRunTimeout()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/configs/config_test.go:223 +0x3ed
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:1123 +0x202

Previous write at 0x00c000202230 by goroutine 27:
  os/exec.(*Cmd).Wait()
      /usr/lib/golang/src/os/exec/exec.go:505 +0xb4
  github.com/opencontainers/runc/libcontainer/configs.Command.Run.func1()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/configs/config.go:373 +0x55

Goroutine 23 (running) created at:
  testing.(*T).Run()
      /usr/lib/golang/src/testing/testing.go:1168 +0x5bb
  testing.runTests.func1()
      /usr/lib/golang/src/testing/testing.go:1439 +0xa6
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:1123 +0x202
  testing.runTests()
      /usr/lib/golang/src/testing/testing.go:1437 +0x612
  testing.(*M).Run()
      /usr/lib/golang/src/testing/testing.go:1345 +0x3b3
  main.main()
      _testmain.go:69 +0x236

Goroutine 27 (running) created at:
  github.com/opencontainers/runc/libcontainer/configs.Command.Run()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/configs/config.go:372 +0x415
  github.com/opencontainers/runc/libcontainer/configs_test.TestCommandHookRunTimeout()
      /home/kir/go/src/github.com/opencontainers/runc/libcontainer/configs/config_test.go:223 +0x3ed
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:1123 +0x202
==================
    testing.go:1038: race detected during execution of test
--- FAIL: TestCommandHookRunTimeout (0.10s)

Apparently, the issue is we call two Wait()s for the same command
which can race internally.

Fix is easy -- since we already have a waiting goroutine,
wait for it to return instead of calling a second Wait().

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-05 13:02:47 -08:00
Kir Kolyshkin 51ec5db1f1 ci: add i386 unit test run
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-05 11:54:14 -08:00
Aleksa Sarai b142a70ece libct/seccomp/patchpbf/test: fix for 32-bit
This test fails to compile on i386:

> libcontainer/seccomp/patchbpf/enosys_linux_test.go:180:20: constant 3735928559 overflows int
> libcontainer/seccomp/patchbpf/enosys_linux_test.go:204:19: constant 3735928559 overflows int
> libcontainer/seccomp/patchbpf/enosys_linux_test.go:227:25: constant 3735928559 overflows int

This is because golang.org/x/net/bpf returns an int from their emulated
BPF VM implementation when they should really be returning uint32.

Fix by switching to uint32 in the test code.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-05 11:49:43 -08:00
Aleksa Sarai 2831fb5595 cgroup2: devices: handle eBPF skipping more correctly
In the past we incorrectly handled eBPF errors in two ways:

 1. We would only ignore errors if there was an allow rule in the list
    (this doesn't make sense because for security purposes we only care
    if a *deny* rule is being ignored). Arguably this is a security flaw
    but you would only get an error from bpf(2) in rare cases, and thus
    is not a big enough deal to go through security review.

 2. If we were in a rootless container we would still return an error
    even though bpf(2) is blocked for rootless containers.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-02-05 18:13:06 +11:00
Aleksa Sarai b4cb54c2ea merge branch 'pr-2782'
Kir Kolyshkin (2):
  ci/gha: bump golangci-lint to v1.36
  .golangci.yml: add

LGTMs: @AkihiroSuda @cyphar
Closes #2782
2021-02-05 17:46:52 +11:00
Akihiro Suda 9f1e43ea69 Merge pull request #2741 from kolyshkin/test-images 2021-02-05 15:30:43 +09:00
Akihiro Suda 072ed8779b Merge pull request #2789 from kolyshkin/error-trace 2021-02-05 15:21:56 +09:00
Kir Kolyshkin d1007b08a3 cgroupv1 freezer: thaw to increase freeze chances
It appears that briefly thawing the cgroup while freezing
greatly increases its chances to freeze successfully.

The test case I used is doing runc exec in a look parallel with runc
pause/resume in another loop, and the failure to freeze rate reduced
from 40 to 0 per minute (tested inside a VM using a busybox container
running sleep 1h, doing about 1500 pause/resumes and 650 execs per
minute), with max retries being 150 (of 1000).

This is still a game of chances, so failures are possible.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-04 15:06:11 -08:00
Kir Kolyshkin 1e0016cf57 Show error stack trace if --debug is set
We use github.com/pkg/errors to produce an error in many places.
One of its benefits is error comes with a stack trace.

Let's print that stack trace if --debug is set.

Example:

	# ../runc --debug run -d ''
	ERRO[0000] container id cannot be empty
	DEBU[0000] container id cannot be empty
	main.init
		github.com/opencontainers/runc/utils_linux.go:28
	runtime.doInit
		runtime/proc.go:5652
	runtime.main
		runtime/proc.go:191
	runtime.goexit
		runtime/asm_amd64.s:1374

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-04 11:50:21 -08:00
Mrunal Patel 19437f3a55 Merge pull request #2787 from kolyshkin/gha-fedora
ci/gha/fedora: retry vagrant up
2021-02-03 17:41:34 -08:00
Mrunal Patel c46eced395 Merge pull request #2788 from kinvolk/mauricio/fix_err_conversion
libcontainer: fix bad conversion from syscall.Errno to error
2021-02-03 17:40:52 -08:00
Aleksa Sarai 7c11557a07 merge branch 'pr-2784'
Aleksa Sarai (2):
  VERSION: back to development
  VERSION: release 1.0.0~rc93

Vote: +6 -0 #1
Closes #2784
2021-02-04 11:15:41 +11:00
Mauricio Vásquez 5c0342ba2c libcontainer: fix bad conversion from syscall.Errno to error
The correct way to do that conversion according to
https://pkg.go.dev/syscall#Errno is:

```
err = nil
if errno != 0 {
	err = errno
}
```

In this case the error check will always report a false positive in
unix.RawSyscall(unix.SYS_SECCOMP, ...), probably nobody has faced this
problem because the code takes the other path in most of the cases.

Fixes: 7a8d7162f9 ("seccomp: prepend -ENOSYS stub to all filters")

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
2021-02-03 16:12:33 -05:00
Kir Kolyshkin a9e99b6da3 ci/gha/fedora: retry vagrant up
download.fedoraproject.org gives HTTP 404 at times,
breaking the CI. Let's give it another chance.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-03 10:56:00 -08:00
Aleksa Sarai f26768a820 VERSION: back to development
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-02-03 11:58:14 +11:00
Aleksa Sarai 12644e614e VERSION: release 1.0.0~rc93
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
v1.0.0-rc93
2021-02-03 11:57:49 +11:00
Kir Kolyshkin c348b98203 tests/rootless.sh: fix/ignore shellcheck warnings
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-02 16:03:52 -08:00
Kir Kolyshkin 1143759338 tests/rootless.sh: use set -e -u -o pipefail
Currently, set -e ("exit on error") is only set before running tests.
The bad consequence is the script may fail to set up test environment
but will still run the tests.

Use "set -e -u -o pipefail" for the whole script to catch potential
issues with test setup and/or the script itself.

A few caveats:

1. We have to set RUNC_USE_SYSTEMD to an empty value if it is unset, so
   that the subsequent checks like [ -z "$RUNC_USE_SYSTEMD" ] won't
   trigger a "unbound variable" error. Same for ROOTLESS_TESTPATH.

2. Functions that have code like [ -f $file ] && do_something towards
   the end may return 1 in case $file does not exist (as test aka [
   was the last operation performed, and its exit code is returned.
   This is why we had to add return 0.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-02 16:03:52 -08:00