Skip to content

linux: treat ENOENT/EINVAL from pidfd_open as ESRCH - #2402

Merged
kolyshkin merged 2 commits into
containers:mainfrom
kolyshkin:kill-pidfd-enoent
Oct 22, 2026
Merged

kolyshkin merged 2 commits into
containers:mainfrom
kolyshkin:kill-pidfd-enoent

Conversation

@kolyshkin

Copy link
Copy Markdown
Collaborator

pidfd_open(2) with flags=0 fails if the pid is not a thread-group leader.
Older kernels report this as EINVAL (also used when the task is being
reaped), while Linux >= 6.16 reports ESRCH for a reaped task and ENOENT for
a pid which is not a thread-group leader (kernel commits 8cf4b738f6d8 and
17f1b08acf50).

The container init process is a thread-group leader and can't lose this
status while alive, so both errors mean the process is gone and its pid
number was either reused by a thread of another process, or is being
released.

Currently, EINVAL is handled by re-checking the pid validity, which is
redundant, and ENOENT is not handled at all, so on newer kernels
crun delete --force fails with "open pidfd: No such file or directory".

This maps both EINVAL and ENOENT to ESRCH in libcrun_kill_linux, and drops
the now-unneeded EINVAL check from container_delete_internal.

Closes: #2399

pidfd_open(2) with flags=0 fails if the pid is not a thread-group
leader. Older kernels report this as EINVAL (also used when the task
is being reaped), while Linux >= 6.16 reports ESRCH for a reaped task
and ENOENT for a pid which is not a thread-group leader (see kernel
commits 8cf4b738f6d8 and 17f1b08acf50).

The container init process is a thread-group leader, and it can't
lose this status while alive, so both errors mean the process is gone
and its pid number was either reused by a thread of another process,
or is being released.

Currently, EINVAL is handled by re-checking the pid validity, which is
redundant, and ENOENT is not handled at all, resulting in an
"open pidfd: No such file or directory" error on newer kernels.

Map both EINVAL and ENOENT to ESRCH.

Assisted-by: Claude Code (claude-opus-5-5)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Since the previous commit, libcrun_kill_linux maps EINVAL (and ENOENT)
from pidfd_open to ESRCH, so there is no need to check for it here.

Assisted-by: Claude Code (claude-opus-5-5)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

@giuseppe giuseppe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kolyshkin
kolyshkin enabled auto-merge October 22, 2026 06:25
@kolyshkin
kolyshkin merged commit 3fc2624 into containers:main Oct 22, 2026
89 of 102 checks passed
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.

2 participants