Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,16 @@ func maybeClearRlimitNofileCache(limits []configs.Rlimit) {

func setupRlimits(limits []configs.Rlimit, pid int) error {
for _, rlimit := range limits {
// Enforce a minimum RLIMIT_NOFILE to prevent the Go runtime from crashing
// due to lack of file descriptors (e.g. for the network poller).
// See https://github.com/opencontainers/runc/issues/5082.
if rlimit.Type == unix.RLIMIT_NOFILE {
// 32 is a safe "minimum" (Go runtime + runc standard FDs).
// The issue report indicates <14 crashes.
if rlimit.Soft < 32 {
return fmt.Errorf("RLIMIT_NOFILE soft limit %d is too low, must be at least 32", rlimit.Soft)
}
}
if err := unix.Prlimit(pid, rlimit.Type, &unix.Rlimit{Max: rlimit.Hard, Cur: rlimit.Soft}, nil); err != nil {
return fmt.Errorf("error setting rlimit type %v: %w", rlimit.Type, err)
}
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/rlimits.bats
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,16 @@ function exec_check_nofile() {
hard=$soft
exec_check_nofile "$soft" "$hard"
}

@test "runc run with low RLIMIT_NOFILE should error (gh-5082)" {
# Set a very low limit (10) which triggers the crash in the issue.
# We assert it fails with our nice error message.
update_config '.process.rlimits = [{"type": "RLIMIT_NOFILE", "soft": 10, "hard": 10}]'

runc run test_rlimit

# Expect failure
[ "$status" -ne 0 ]
# Expect our error message
[[ "$output" == *"RLIMIT_NOFILE soft limit 10 is too low"* ]]
}