podman icon indicating copy to clipboard operation
podman copied to clipboard

rootless: pause.pid of a live pause process is removed when /proc/<pid>/environ is unreadable (EACCES from another user namespace)

Open lusoris opened this issue 1 month ago • 4 comments

Issue Description

The stale pause.pid check added in a2db18f35 (for #28157) treats any failure to read /proc/<pid>/environ as "not a pause process" and unlinks the pid file. Reading another process's environ also fails with EACCES when podman runs inside a nested user namespace that shares $XDG_RUNTIME_DIR with the host, for example inside a non-setuid bubblewrap sandbox such as the ones coding agents run their tools in. In that case podman removes the pid file of a live, healthy pause process.

On my host this happened once from inside such a sandbox: the host's libpod/tmp/pause.pid and a running container's userdata/conmon.pid were deleted. Later podman calls on the host then started a new pause process instead of joining the existing one, and the old pause process stayed behind in its own user namespace.

Both code paths have the same shape, on v6.1.4 and on main today:

  • is_pause_process() in pkg/rootless/rootless_linux.c returns 0 when open() fails, and check_stale_pause_pid() then calls unlink (path).
  • isPauseProcess() in pkg/rootless/rootless_linux.go returns false on any os.ReadFile error, and TryJoinFromFilePaths() then calls os.Remove(path).

Steps to reproduce the issue

The script below hides the real runtime directory behind a tmpfs and keeps all podman state in a throwaway directory, so it does not touch a running podman setup.

  1. Start a process that carries the pause marker: env -i _PODMAN_PAUSE=1 sleep 120 &.
  2. Write its PID to $d/run/libpod/tmp/pause.pid in a fresh directory $d.
  3. Run podman inside a non-setuid bubblewrap user namespace that points at that runtime directory:
bwrap --die-with-parent --unshare-user --dev-bind / / \
  --tmpfs /run/user/$UID --tmpfs $HOME/.local/share/containers --tmpfs $HOME/.config/containers \
  --bind "$d" "$d" --setenv XDG_RUNTIME_DIR "$d/run" --setenv HOME "$d/home" \
  --setenv XDG_CONFIG_HOME "$d/cfg" --setenv XDG_DATA_HOME "$d/data" --unsetenv DBUS_SESSION_BUS_ADDRESS \
  /usr/bin/podman --root "$d/storage" --runroot "$d/runroot" --cgroup-manager cgroupfs --events-backend none ps
  1. Check whether $d/run/libpod/tmp/pause.pid still exists.

Describe the results you received

Inside the sandbox, open("/proc/<pid>/environ") of the marked process fails with errno 13 Permission denied, while outside the sandbox the same file reads _PODMAN_PAUSE=1. podman then prints:

pause.pid file refers to PID 47578 which is not a pause process, the process may have exited and the PID been recycled. Removing /…/run/libpod/tmp/pause.pid

The file is removed although PID 47578 is alive and carries _PODMAN_PAUSE=1. (The following newuidmap error is expected inside this sandbox and is not the point of this report.)

Describe the results you expected

podman should only treat the pid file as stale when it can positively tell that the process is not a pause process. When the environ cannot be read (EACCES, or any error other than the process having exited), podman should leave the file alone and fail the join with an error, as it did before a2db18f35.

A possible fix: make is_pause_process() / isPauseProcess() return three states (pause, not pause, unknown) and only unlink on "not pause"; the same reasoning applies to the conmon.pid paths passed to TryJoinFromFilePaths().

podman info output

podman version 6.1.4 (Arch Linux package podman 6.1.4-1.1)
bubblewrap 0.13.0
kernel 7.2.10-1-cachyos

Full podman info omitted: running it on the host would join the live pause process; I can add it if needed.

Podman in a container

No

Privileged Or Rootless

Rootless

Upstream Latest Release

Yes (6.1.4; the same code is on main as of 2026-10-16)

Additional environment details

CachyOS (Arch based), x86_64, systemd user session, rootless podman with the default runtime directory /run/user/1000.

Additional information

Reproduces every time with the script above. Related: #28157 (origin of the check), #29650 / #29657 (a different false positive in the same check, the 4096-byte environ read).

lusoris avatar Oct 15 '26 22:10 lusoris

Hi! I'd like to work on this — could you assign it to me?

The stale-check from a2db18f35 treats a failed /proc//environ read as "not a pause process", so an EACCES inside a nested user namespace unlinks a live pause.pid. I'd change the fallback to leave the pid file alone on read errors other than ENOENT/ESRCH and add a regression test. Happy to adjust. Thanks!

sapnasingh4852-source avatar Oct 16 '26 10:10 sapnasingh4852-source

Well for starters using the same runroot across two different envs (containers, namesapces, whatever...) is completely unsupported and will lead to all kinds errors so the simple answer is never do that.

Getting EACCES is totally expected for this function because it the pid is stale we might end up reading a /proc//environ file owned by another user which naturally fails with EACCES is the exact error path in which case we want to remove the file and use a new pause process because we have to assume it is stale at this point.

Now in general using pids for all sorts of things is just horrible, I guess the better investment is using pid handles instead. We also already have a PODMAN_NO_PAUSE_PROCESS env which may be used to only use namespace handles instead of a running process. I however do not know how/if these handles work across the pid namesapce boundary.

cc @giuseppe


ps: How did you create the issue? You used the github bug template for the most part which is good but github did not actually add the bug label which leads me to believe you did not use the web ui?

Luap99 avatar Oct 16 '26 11:10 Luap99

we can't support running from different environments (user namespaces), because each object has a different owner. There are just too many things that can go wrong.

@sapnasingh4852-source stop using AI tools to interact with users here.

giuseppe avatar Oct 16 '26 11:10 giuseppe

Thanks for the explanation that a runroot shared across user namespaces is not supported.

We changed our setup: each sandbox now gets an empty private runroot and an empty private storage and config directory, so no podman state is shared across namespaces any more. Closing this as not a podman bug.

lusoris avatar Oct 19 '26 17:10 lusoris