Skip to content

Commit 669ed68

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 95762b6 commit 669ed68

File tree

17 files changed

+245
-51
lines changed

17 files changed

+245
-51
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` has 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.3.0
1919
github.com/opencontainers/selinux v1.13.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
@@ -46,10 +46,10 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
4646
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
4747
github.com/mrunalp/fileutils v0.5.1 h1:F+S7ZlNKnrwHfSwdlgNSkKo67ReVf8o9fel6C3dkm/Q=
4848
github.com/mrunalp/fileutils v0.5.1/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
49-
github.com/opencontainers/cgroups v0.0.5 h1:DRITAqcOnY0uSBzIpt1RYWLjh5DPDiqUs4fY6Y0ktls=
50-
github.com/opencontainers/cgroups v0.0.5/go.mod h1:oWVzJsKK0gG9SCRBfTpnn16WcGEqDI8PAcpMGbqWxcs=
51-
github.com/opencontainers/runtime-spec v1.2.2-0.20250818071321-383cadbf08c0 h1:RLn0YfUWkiqPGtgUANvJrcjIkCHGRl3jcz/c557M28M=
52-
github.com/opencontainers/runtime-spec v1.2.2-0.20250818071321-383cadbf08c0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
49+
github.com/opencontainers/cgroups v0.0.6 h1:tfZFWTIIGaUUFImTyuTg+Mr5x8XRiSdZESgEBW7UxuI=
50+
github.com/opencontainers/cgroups v0.0.6/go.mod h1:oWVzJsKK0gG9SCRBfTpnn16WcGEqDI8PAcpMGbqWxcs=
51+
github.com/opencontainers/runtime-spec v1.3.0 h1:YZupQUdctfhpZy3TM39nN9Ika5CBWT5diQ8ibYCRkxg=
52+
github.com/opencontainers/runtime-spec v1.3.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
5353
github.com/opencontainers/selinux v1.13.0 h1:Zza88GWezyT7RLql12URvoxsbLfjFx988+LGaWfbL84=
5454
github.com/opencontainers/selinux v1.13.0/go.mod h1:XxWTed+A/s5NNq4GmYScVy+9jzXhGBVEOAyucdRUY8s=
5555
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
@@ -526,20 +526,22 @@ func TestPidsSystemd(t *testing.T) {
526526
testPids(t, true)
527527
}
528528

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

534536
config := newTemplateConfig(t, &tParam{systemd: systemd})
535-
config.Cgroups.Resources.PidsLimit = -1
537+
config.Cgroups.Resources.PidsLimit = mkPtr[int64](-1)
536538

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

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

549551
// Enforce a restrictive limit. 64 * /bin/true + 1 * shell should cause
550552
// this to fail reliably.
551-
config.Cgroups.Resources.PidsLimit = 64
553+
config.Cgroups.Resources.PidsLimit = mkPtr[int64](64)
552554
out, _, err := runContainer(t, config, "/bin/sh", "-c", `
553555
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
554556
/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)