Commit Graph

7984 Commits

Author SHA1 Message Date
RedMakeUp 8178af4930 ci: propagate RUNC_ALLOW_UNSAFE_TESTS to ssh session
The RUNC_ALLOW_UNSAFE_TESTS variable set in the Cirrus CI env block
does not reach the integration tests because they are executed via
"ssh -tt localhost make ...", which starts a new login shell that
does not inherit the caller's environment. As a result, unsafe tests
are always skipped in Cirrus CI even though the intent is to run them.

Fix this by exporting the variable in /root/.bashrc (same way we
already handle PATH), so the ssh session picks it up.

See #5212 (comment).

Fixes: 9932ad19 ("tests/int: introduce the concept of unsafe tests")
Signed-off-by: RedMakeUp <girafeeblue@gmail.com>
2026-04-09 10:03:37 +00:00
lfbzhm 65bf6dc661 Merge pull request #5226 from kolyshkin/fix-rootless-systemd-idmap
tests/rootless.sh: fix skipping idmap tests for systemd
2026-04-08 19:05:36 +08:00
Rodrigo Campos Catelin d57a45eb78 Merge pull request #5227 from cyphar/internal-cmsg-package
libct: move cmsg helpers to new internal/cmsg package
2026-04-08 11:36:32 +02:00
Rodrigo Campos Catelin 4c8d72d54d Merge pull request #5186 from kolyshkin/poststart
Move poststart hook from runc create to runc start
2026-04-08 11:35:17 +02:00
Kir Kolyshkin 3e0829d195 tests/rootless.sh: fix skipping idmap tests for systemd
When RUNC_USE_SYSTEMD is set, tests/rootless.sh is using

	ssh -tt rootless@localhost

to run tests as rootless user. In this case, local environment is not
passed to the user's ssh session (unless explicitly specified), and so
the tests do not get ROOTLESS_FEATURES.

As a result, idmap-related tests are skipped when running as rootless
using systemd cgroup driver:

	integration test (systemd driver)
	...
	[02] run rootless tests ... (idmap)
	...
	ok 286 runc run detached ({u,g}id != 0) # skip test requires rootless_idmap
	...

Fix this by creating a list of environment variables needed by the
tests, and adding those to ssh command line (in case of ssh) or
exporting (in case of sudo) so both cases work similarly.

Also, modify disable_idmap to unset variables set in enable_idmap so
they are not exported at all if idmap is not in features.

Fixes: bf15cc99 ("cgroup v2: support rootless systemd")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-04-07 11:27:48 -07:00
Kir Kolyshkin ac2a53be8e tests: rename AUX_{DIR,UID} to ROOTLESS_AUX_*
Also, fix the typo (AUX_DIX) in cleanup.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-04-07 10:53:37 -07:00
Aleksa Sarai ca509e76ff libct: move cmsg helpers to new internal/cmsg package
These helpers all make more sense as a self-contained package and moving
them has the added benefit of removing an unneeded libpathrs dependency
(from libcontainer/utils's import of pathrs-lite) from several test
binaries.

Signed-off-by: Aleksa Sarai <aleksa@amutable.com>
2026-04-08 01:21:41 +10:00
Kir Kolyshkin 80fc1cd34e Merge pull request #5223 from thaJeztah/gofix
libcontainer/devices: add '//go:fix inline' directives
2026-04-06 11:08:29 -07:00
Aleksa Sarai 4f2090fd31 Merge pull request #5212 from kolyshkin/unsafe_test
tests/int: introduce the concept of unsafe tests
2026-04-05 10:24:07 +10:00
Sebastiaan van Stijn ba83c7c7d7 libcontainer/devices: add '//go:fix inline' directives
This allows users to automaticaly migrate to the new location
using `go fix`. It has some limitations, but can help smoothen
the transition; for example, taking this file;

```
package main

import (
	"github.com/opencontainers/runc/libcontainer/devices"
)

func main() {
	_, _ = devices.DeviceFromPath("a", "b")
	_, _ = devices.HostDevices()
	_, _ = devices.GetDevices("a")
}
```

Running `go fix -mod=readonly ./...` will migrate the code;

```
package main

import (
	devices0 "github.com/moby/sys/devices"
)

func main() {
	_, _ = devices0.DeviceFromPath("a", "b")
	_, _ = devices0.HostDevices()
	_, _ = devices0.GetDevices("a")
}
```

updates b345c78dca

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-04-04 19:36:43 +02:00
Kir Kolyshkin 9932ad19be tests/int: introduce the concept of unsafe tests
Some of runc integration tests may do something that I would not like
when running those on my development laptop. Examples include

 - changing the root mount propagation [1];
 - replacing /root/runc [2];
 - changing the file in /etc (see checkpoint.bats).

Yet it is totally fine to do all that in a throwaway CI environment,
or inside a Docker container.

Introduce a mechanism to skip specific "unsafe" tests unless an
environment variable, RUNC_ALLOW_UNSAFE_TESTS, is set. Use it
from a specific checkpoint/restore test which modifies
/etc/criu/default.conf.

[1]: https://github.com/opencontainers/runc/pull/5200
[2]: https://github.com/opencontainers/runc/pull/5207

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-04-02 20:03:47 -07:00
Kir Kolyshkin 7a1cae6dd0 Merge pull request #5142 from cyphar/deprecate-libct-devices
libct: deprecate libcontainer/devices in favour of moby/sys/devices
2026-04-02 17:58:00 -07:00
Kir Kolyshkin 3cdda464fa Move poststart hook from runc create to runc start
The runtime-spec [1] currently says:

> 6. Runtime's start command is invoked with the unique identifier of
>    the container.
> 7. The startContainer hooks MUST be invoked by the runtime. If any
>    startContainer hook fails, the runtime MUST generate an error, stop
>    the container, and continue the lifecycle at step 12.
> 8. The runtime MUST run the user-specified program, as specified by
>    process.
> 9. The poststart hooks MUST be invoked by the runtime. If any
>    poststart hook fails, the runtime MUST generate an error, stop the
>    container, and continue the lifecycle at step 12.
> ...
> 11. Runtime's delete command is invoked with the unique identifier of
>     the container.
> 12. The container MUST be destroyed by undoing the steps performed
>     during create phase (step 2).
> 13. The poststop hooks MUST be invoked by the runtime. If any poststop
>     hook fails, the runtime MUST log a warning, but the remaining hooks
>     and lifecycle continue as if the hook had succeeded.

Currently, we do 9 before 8 (heck, even before 6), which is clearly
against the spec and results in issues like the one described in [2].

Let's move running poststart hook to after the user-specified process
has started.

NOTE this patch only fixes the order and does not implement removing
the container when the poststart hook failed (as this part of the spec
is controversial -- destroy et al and should probably be, and currently
are, part of "runc delete").

[1]: https://github.com/opencontainers/runtime-spec/blob/main/runtime.md#lifecycle
[2]: https://github.com/opencontainers/runc/issues/5182

Reported-by: ningmingxiao <ning.mingxiao@zte.com.cn>
Reported-by: Erik Sjölund <erik.sjolund@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-04-02 12:28:54 -07:00
Kir Kolyshkin 2253475660 libct: factor handleFifo out of c.exec
No functional change. To be used by the next patch.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-04-02 10:22:22 -07:00
Kir Kolyshkin b0762c7af1 libct: add lock-less c.signal
Rename c.signal to c.signalInit, and add c.signal which is a lock-less
form of c.Signal.

To be used by the next patch.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-04-02 10:22:22 -07:00
Aleksa Sarai b345c78dca libct/devices: deprecate in favour of moby/sys/devices
The libcontainer/devices package has been moved to moby/sys/devices, so
we can just point users to that and keep some compatibility shims around
until runc 1.6. We don't use it at all so there are no other changes
needed.

Signed-off-by: Aleksa Sarai <aleksa@amutable.com>
2026-04-02 22:54:14 +11:00
Rodrigo Campos Catelin a0d1b98e06 Merge pull request #4661 from lifubang/skip-setup-signalNotify-for-detached
skip setup signal notifier for detached container
2026-04-02 13:50:34 +02:00
lfbzhm 62d4f147e8 Merge pull request #5210 from lifubang/fix-signal-race
Fix SIGCHLD race in signal handler setup
2026-04-02 09:38:46 +08:00
lifubang 404181e4cc Fix SIGCHLD race in signal handler setup
When signal installation was moved to a goroutine for performance,
containers that exited quickly could complete before SIGCHLD was
registered, causing runc to hang waiting for the signal.

This fix ensures SIGCHLD is registered immediately in the main thread
before other signals are handled in the goroutine, maintaining performance
while guaranteeing no missed SIGCHLD notifications for fast-exiting
containers.

Reported-by: Ayato Tokubi <atokubi@redhat.com>
Signed-off-by: lifubang <lifubang@acmcoder.com>
2026-04-02 00:59:18 +00:00
Kir Kolyshkin 5c9b6ac713 Merge pull request #5164 from opencontainers/dependabot/go_modules/golang.org/x/net-0.52.0
build(deps): bump golang.org/x/net from 0.50.0 to 0.52.0
2026-04-01 13:05:39 -07:00
dependabot[bot] d033312a74 build(deps): bump golang.org/x/net from 0.50.0 to 0.52.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.50.0 to 0.52.0.
- [Commits](https://github.com/golang/net/compare/v0.50.0...v0.52.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-version: 0.52.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-01 18:11:21 +00:00
lifubang 4c0496a69f skip setup signal notifier for detached container
For detached container, we don't need to setup signal notifier, because
there is no customer to consume the signals in `forward()`.

Signed-off-by: lifubang <lifubang@acmcoder.com>
2026-03-31 12:35:25 -07:00
lifubang e259ae0c38 move notifySocket out of signalHandler
In fact, notifySocket has no relationship to signalHandler, we
can move it out of signalHandler to make the code more clear.

Signed-off-by: lifubang <lifubang@acmcoder.com>
2026-03-31 12:35:25 -07:00
lifubang fba5a1ec23 move process terminate operation to defer function
Signed-off-by: lifubang <lifubang@acmcoder.com>
2026-03-31 12:35:25 -07:00
lifubang 456d0f525a fix a ambiguity of err in defer func
We should use a named return value of error, or else we can't
catch all errors when calling defer function, for example we
used a block scope var name `err` for `setupPidfdSocket`.

Signed-off-by: lifubang <lifubang@acmcoder.com>
2026-03-31 12:35:25 -07:00
Rodrigo Campos Catelin 348d92f497 Merge pull request #5205 from kolyshkin/carry-5169
Switch to Go 1.25+
2026-03-31 11:13:44 +02:00
Aleksa Sarai 47fba7e4b1 go fix: use (*sync.WaitGroup).Go
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2026-03-30 13:13:53 -07:00
Aleksa Sarai 99d054b93f go.mod: bump minimum to Go 1.25
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2026-03-30 13:13:53 -07:00
Kir Kolyshkin f9a9a36fa8 tests/int: allow cpu quota cgroup v1 files fds
Since switching to Go 1.25 in go.mod, the "detect fd leaks" test fails
like this:

> not ok 57 runc create[detect fd leak as comprehensively as possible]
> # (in test file tests/integration/create.bats, line 76)
> #   `[ "$violation_found" -eq 0 ]' failed
> ...
> # Violation: FD 9 -> '/system.slice/runc-test_busybox.scope/cpu.cfs_quota_us'
> # Violation: FD 10 -> '/system.slice/runc-test_busybox.scope/cpu.cfs_period_us'
> ...

This happens because Go 1.25 adds a feature to dynamically set GOMAXPROC
based on current CPU quota values. This feature can be disabled by setting

	GODEBUG=containermaxprocs=0,updatemaxprocs=0

but it is harmless to keep it (except for the above test failure).

Add an exception to the test case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-03-30 13:13:50 -07:00
lfbzhm 400f3dd460 Merge pull request #5190 from kolyshkin/preopen_root
Pre-open container root directory
2026-03-30 09:09:42 +08:00
lfbzhm 5b094ed1ac libct: use preopened rootfs more
This uses preopened rootfs in Chdir and pivotRoot.

While at it, add O_PATH when opening oldroot in pivotRoot.

Co-authored-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: lfbzhm <lifubang@acmcoder.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-03-29 12:02:38 -07:00
Kir Kolyshkin 28cb321887 Pre-open container root directory
A lot of filesystem-related stuff happens inside the container root
directory, and we have used its name before. It makes sense to pre-open
it and use a *os.File handle instead.

Function names in internal/pathrs are kept as is for simplicity (and it
is an internal package), but they now accept root as *os.File.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-03-29 12:02:36 -07:00
Kir Kolyshkin 78b80677f6 libct: minor refactor in mountToRootfs
No change in functionality, just a preparation for the next patch.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-03-28 23:48:07 -07:00
Kir Kolyshkin 60352524d3 libct: mountCgroupV1: address TODO
Indeed, it does not make sense to prepend c.root once we started using
MkdirAllInRoot in commit 63c29081.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-03-28 23:48:07 -07:00
Aleksa Sarai 7b40afb6cc merge #5177 into opencontainers/runc:main
Li Fubang (3):
  test: check mount source fds are cleaned up with idmapped mounts
  libct: close mount source fd as soon as possible
  libct: add a nil check for mountError

LGTMs: kolyshkin rata cyphar
2026-03-28 17:32:21 +11:00
lfbzhm fe158d1781 Merge pull request #5195 from cyphar/readme-libpathrs
README: add libpathrs installation notes
2026-03-26 12:44:40 +08:00
Aleksa Sarai 81d59df8d5 README: add libpathrs installation notes
libpathrs now has its own installation instructions[1] but it is quite
helpful to provide some high-level instructions as well as notes about
what minimum versions we expect.

[1]: https://github.com/cyphar/libpathrs/blob/main/INSTALL.md

Suggested-by: Li Fubang <lifubang@acmcoder.com>
Signed-off-by: Aleksa Sarai <aleksa@amutable.com>
2026-03-25 19:38:39 +11:00
Aleksa Sarai 142c838e53 merge #5194 into opencontainers/runc:main
Akhil Mohan (1):
  use POSIX regex in libpathrs build

LGTMs: kolyshkin cyphar
2026-03-25 02:57:28 +11:00
Akhil Mohan 28d5ffbab0 use POSIX regex in libpathrs build
word boundary anchor \> is present only in GNU awk implementation. This
will not work if we are building libpathrs inside a container like
debian/ubuntu which uses mawk. Therefore switch to a POSIX compatible
regex that can be used with all implementations of awk to find the
system libc path

Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
Signed-off-by: Aleksa Sarai <aleksa@amutable.com>
2026-03-24 21:20:45 +11:00
lfbzhm 132498f869 Merge pull request #5191 from kolyshkin/unix
libct/exeseal: drop own F_SEAL_EXEC
2026-03-21 19:55:16 +08:00
Kir Kolyshkin dc2558d7b2 Merge pull request #5185 from kolyshkin/fix-5172
CHANGELOG fixups
2026-03-20 23:19:04 -07:00
Kir Kolyshkin f00b2f9fd5 libct/exeseal: drop own F_SEAL_EXEC
Since golang.org/x/sys@v0.22 it is available from unix.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-03-20 15:57:55 -07:00
lifubang 7fdab1cb69 test: check mount source fds are cleaned up with idmapped mounts
Signed-off-by: lifubang <lifubang@acmcoder.com>
2026-03-20 01:17:08 +00:00
lifubang c77e71a3e7 libct: close mount source fd as soon as possible
This commit factors out setupAndMountToRootfs without changing any
logic. Use "Hide whitespace changes" during review to focus on the
actual changes.

The refactor ensures the mount source file descriptor is closed via
defer in each loop iteration, reducing the total number of open FDs
in runc. This helps avoid hitting the file descriptor limit under
high concurrency or when handling many mounts.

Signed-off-by: lifubang <lifubang@acmcoder.com>
2026-03-20 01:09:49 +00:00
Kir Kolyshkin 65d3120d9e CHANGELOG: forward-port v1.3.5 changes
From commit 488fc13e.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-03-19 12:18:44 -07:00
Kir Kolyshkin 29f2d82a85 CHANGELOG: fix entry placement
Commit 0079bee1 incorrectly placed an entry into v1.4.1 changelog.
Move it to under "Unreleased".

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-03-19 12:18:41 -07:00
lifubang 0d0fd95731 libct: add a nil check for mountError
Signed-off-by: lifubang <lifubang@acmcoder.com>
2026-03-19 15:47:32 +00:00
lfbzhm 837e98c984 Merge pull request #5171 from kolyshkin/runc-buildtags
Makefile: add RUNC_BUILDTAGS, deprecate EXTRA_BUILDTAGS
2026-03-19 16:32:40 +08:00
Kir Kolyshkin d8c62c7d0b Makefile: add RUNC_BUILDTAGS, deprecate EXTRA_BUILDTAGS
A bit of history. EXTRA_BUILDTAGS was introduced in commit dac417174,
as a quick way to add some extra Go build tags to the runc build.

Later, commit 767bc008 changed Makefile to not get EXTRA_TAGS from the
shell environment, as the name is quite generic and some unrelated
environment variable with that name can affect runc build. While such
change does make sense, it makes it more complicated to pass build tags
in CI and otherwise (see e.g. commit 0e1fe368a).

Moreover, runc build uses some Go build tags by default (via Makefile),
and while it is easy to add more build tags (via EXTRA_BUILDTAGS), in
order to remove some existing tags one has to redefine BUILDTAGS from
scratch, which is not very convenient (again, see commit 0e1fe368a which
gets the current value of BUILDTAGS from the Makefile in order to remove
a single tag).

To handle all of the above, let's do this:
 - implement RUNC_BUILDTAGS, fixing the issue of not-so-unique name;
 - allow to get RUNC_BUILDTAGS from shell environment;
 - implement a feature to remove a build tag from default set by
   prefixing it with "-" (as in RUNC_BUILDTAGS="-seccomp");
 - document all this in README;
 - make CI use the new feature;
 - keep EXTRA_BUILDTAGS for backward compatibility, add a make warning
   and a TODO to remove it for runc 1.6.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-03-18 13:17:17 +08:00
Akihiro Suda 348c7663e1 Merge pull request #5172 from kolyshkin/seccomp-wait-kill
Support specs.LinuxSeccompFlagWaitKillableRecv
2026-03-18 09:34:49 +09:00