Skip to content

Commit 63b5b4f

Browse files
committed
runtime-spec: update pids.limit handling to match new guidance
The main update is actually in github.com/opencontainers/cgroups, but we need to also update runtime-spec to a newer pre-release version to get the updates from there as well. In short, the behaviour change is now that "0" is treated as a valid value to set in "pids.max", "-1" means "max" and unset/nil means "do nothing". As described in the opencontainers/cgroups PR, this change is actually backwards compatible because our internal state.json stores PidsLimit, and that entry is marked as "omitempty". So, an old runc would omit PidsLimit=0 in state.json, and this will be parsed by a new runc as being "nil" -- and both would treat this case as "do not set anything". Signed-off-by: Aleksa Sarai <[email protected]>
1 parent fb01482 commit 63b5b4f

File tree

16 files changed

+167
-47
lines changed

16 files changed

+167
-47
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- The deprecated `libcontainer/userns` package has been removed; use
1111
`github.com/moby/sys/userns` instead.
1212

13+
### Breaking ###
14+
- The handling of `pids.limit` have been updated to match the newer guidance
15+
from the OCI runtime specification. In particular, now a maximum limit value
16+
of `0` will be treated as an actual limit (due to limitations with systemd,
17+
it will be treated the same as a limit value of `1`). We only expect users
18+
that explicitly set `pids.limit` to `0` will see a behaviour change.
19+
(opencontainers/cgroups#48, #4949)
20+
21+
### Fixed ###
22+
- cgroups: provide iocost statistics for cgroupv2. (opencontainers/cgroups#43)
23+
- cgroups: retry DBus connection when it fails with EAGAIN.
24+
(opencontainers/cgroups#45)
25+
- cgroups: improve `cpuacct.usage_all` resilience when parsing data from
26+
patched kernels (such as the Tencent kernels). (opencontainers/cgroups#46,
27+
opencontainers/cgroups#50)
28+
1329
## [1.4.0-rc.1] - 2025-09-05
1430

1531
> おめェもボスになったんだろぉ?

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ require (
1414
github.com/moby/sys/user v0.4.0
1515
github.com/moby/sys/userns v0.1.0
1616
github.com/mrunalp/fileutils v0.5.1
17-
github.com/opencontainers/cgroups v0.0.5
18-
github.com/opencontainers/runtime-spec v1.2.2-0.20250818071321-383cadbf08c0
17+
github.com/opencontainers/cgroups v0.0.6
18+
github.com/opencontainers/runtime-spec v1.2.2-0.20251022072015-5caf3047c341
1919
github.com/opencontainers/selinux v1.12.0
2020
github.com/seccomp/libseccomp-golang v0.11.1
2121
github.com/sirupsen/logrus v1.9.3

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
4444
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
4545
github.com/mrunalp/fileutils v0.5.1 h1:F+S7ZlNKnrwHfSwdlgNSkKo67ReVf8o9fel6C3dkm/Q=
4646
github.com/mrunalp/fileutils v0.5.1/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
47-
github.com/opencontainers/cgroups v0.0.5 h1:DRITAqcOnY0uSBzIpt1RYWLjh5DPDiqUs4fY6Y0ktls=
48-
github.com/opencontainers/cgroups v0.0.5/go.mod h1:oWVzJsKK0gG9SCRBfTpnn16WcGEqDI8PAcpMGbqWxcs=
49-
github.com/opencontainers/runtime-spec v1.2.2-0.20250818071321-383cadbf08c0 h1:RLn0YfUWkiqPGtgUANvJrcjIkCHGRl3jcz/c557M28M=
50-
github.com/opencontainers/runtime-spec v1.2.2-0.20250818071321-383cadbf08c0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
47+
github.com/opencontainers/cgroups v0.0.6 h1:tfZFWTIIGaUUFImTyuTg+Mr5x8XRiSdZESgEBW7UxuI=
48+
github.com/opencontainers/cgroups v0.0.6/go.mod h1:oWVzJsKK0gG9SCRBfTpnn16WcGEqDI8PAcpMGbqWxcs=
49+
github.com/opencontainers/runtime-spec v1.2.2-0.20251022072015-5caf3047c341 h1:fQ6LUhSWtHE2SdjVfrgANsFgQZtCNDTjUhussoMtX+8=
50+
github.com/opencontainers/runtime-spec v1.2.2-0.20251022072015-5caf3047c341/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
5151
github.com/opencontainers/selinux v1.12.0 h1:6n5JV4Cf+4y0KNXW48TLj5DwfXpvWlxXplUkdTrmPb8=
5252
github.com/opencontainers/selinux v1.12.0/go.mod h1:BTPX+bjVbWGXw7ZZWUbdENt8w0htPSrlgOOysQaU62U=
5353
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

libcontainer/integration/exec_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,20 +525,22 @@ func TestPidsSystemd(t *testing.T) {
525525
testPids(t, true)
526526
}
527527

528+
func mkPtr[T any](v T) *T { return &v }
529+
528530
func testPids(t *testing.T, systemd bool) {
529531
if testing.Short() {
530532
return
531533
}
532534

533535
config := newTemplateConfig(t, &tParam{systemd: systemd})
534-
config.Cgroups.Resources.PidsLimit = -1
536+
config.Cgroups.Resources.PidsLimit = mkPtr[int64](-1)
535537

536538
// Running multiple processes, expecting it to succeed with no pids limit.
537539
runContainerOk(t, config, "/bin/sh", "-c", "/bin/true | /bin/true | /bin/true | /bin/true")
538540

539541
// Enforce a permissive limit. This needs to be fairly hand-wavey due to the
540542
// issues with running Go binaries with pids restrictions (see below).
541-
config.Cgroups.Resources.PidsLimit = 64
543+
config.Cgroups.Resources.PidsLimit = mkPtr[int64](64)
542544
runContainerOk(t, config, "/bin/sh", "-c", `
543545
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
544546
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
@@ -547,7 +549,7 @@ func testPids(t *testing.T, systemd bool) {
547549

548550
// Enforce a restrictive limit. 64 * /bin/true + 1 * shell should cause
549551
// this to fail reliably.
550-
config.Cgroups.Resources.PidsLimit = 64
552+
config.Cgroups.Resources.PidsLimit = mkPtr[int64](64)
551553
out, _, err := runContainer(t, config, "/bin/sh", "-c", `
552554
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
553555
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |

update.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ other options are ignored.
252252
}
253253
}
254254

255-
r.Pids.Limit = int64(context.Int("pids-limit"))
255+
if context.IsSet("pids-limit") {
256+
r.Pids.Limit = i64Ptr(int64(context.Int("pids-limit")))
257+
}
256258
}
257259

258260
// Fix up values

vendor/github.com/opencontainers/cgroups/config_linux.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/opencontainers/cgroups/fs/cpuacct.go

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/opencontainers/cgroups/fs/pids.go

Lines changed: 16 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/opencontainers/cgroups/fs2/io.go

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/opencontainers/cgroups/fs2/pids.go

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)