Skip to content

exec: do not fail when oom_score_adj cannot be lowered - #2467

Open
rfay wants to merge 1 commit into
containers:mainfrom
rfay:exec-oom-score-adj-eacces
Open

rfay wants to merge 1 commit into
containers:mainfrom
rfay:exec-oom-score-adj-eacces

Conversation

@rfay

@rfay rfay commented Nov 12, 2026

Copy link
Copy Markdown

Fixes #2466

Since 499c3eb (#2425), crun exec writes the process oomScoreAdj to /proc/self/oom_score_adj. Without CAP_SYS_RESOURCE, the kernel refuses with EACCES a value below the minimum that a privileged writer set. systemd sets that minimum to 100 under user@.service (OOMScoreAdjust=100). A rootless podman exec from podman.service or a healthcheck timer therefore fails when Podman asks for 0:

crun: write to `/proc/self/oom_score_adj`: Permission denied: OCI permission denied

This change handles EACCES in the exec path only. crun logs it at debug level and keeps the inherited value, which is what exec did before 1.31. Any other error still fails the exec.

Two choices a reviewer may want changed:

  • I used libcrun_debug rather than libcrun_warning, because healthchecks run exec every few seconds and a warning would repeat on each one.
  • The container-create path (libcrun_set_oom from init_container) can fail the same way. I left it alone because that behavior is older than 1.31, and Podman already passes a value it can write there.

Testing

  • New test exec-oom-score-adj-below-min in tests/test_exec.py. As root, it sets the minimum with a privileged write and drops CAP_SYS_RESOURCE with setpriv. Then it execs with oomScoreAdj below the minimum and expects the inherited value. It skips when rootless or when setpriv is missing.

  • Fedora 44 privileged container, as root: all 25 tests in test_exec.py pass. Without the container.c change, the new test fails with exit status 255.

  • Ubuntu 26.04 arm64, rootless, Homebrew podman 6.2.0, with the reproducer from 1.31: exec fails with "write to /proc/self/oom_score_adj: Permission denied" under a systemd user manager (rootless podman API, healthchecks) #2466:

    Case Stock 1.31 This PR
    systemd-run --user exec, container adj 0 rc 126, Permission denied rc 0, inherited value
    exec from a login shell, container adj 0 — rc 0, value 0
    systemd-run --user exec, container adj 500 — rc 0, value 500
  • Same host, rootless inside podman unshare: all tests in test_exec.py and test_error_handling.py pass or skip.

I prepared this with Claude Code (AI-assisted). I reviewed the change and the kernel behavior, and ran the tests above.

Since commit 499c3eb ("linux: apply the exec process oomScoreAdj"),
crun exec writes the process oomScoreAdj to /proc/self/oom_score_adj.
Without CAP_SYS_RESOURCE, the kernel refuses with EACCES a value lower
than the minimum set by a privileged writer.  systemd sets that minimum
to 100 for every process under user@.service (OOMScoreAdjust=100).  So
a rootless "podman exec" from podman.service or from a healthcheck
timer fails when Podman asks for 0.

On EACCES, keep the inherited value, which is what exec did before
1.31.  Other errors still fail the exec.

Fixes: containers#2466

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Randy Fay <randy@randyfay.com>
@rfay

rfay commented Nov 12, 2026

Copy link
Copy Markdown
Author

Reopened after accidental closure via text in DDEV PR.

@packit-as-a-service

Copy link
Copy Markdown

TMT tests failed. @containers/packit-build please check.

@rfay

rfay commented Nov 12, 2026

Copy link
Copy Markdown
Author

/packit retest-failed

@giuseppe

Copy link
Copy Markdown
Member

@rfay thanks for the patch but I am not sure it is correct to ignore a setting that was explicitly set.

There is already a patch for Podman: podman-container-tools/podman#30243

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1.31: exec fails with "write to /proc/self/oom_score_adj: Permission denied" under a systemd user manager (rootless podman API, healthchecks)

2 participants