From 7e17b33523a0f192b1f62ef5f4634a5d867c5e7f Mon Sep 17 00:00:00 2001 From: Jonathan Siegel Date: Wed, 21 Oct 2026 15:09:37 +0900 Subject: [PATCH] linux: treat ENOENT from pidfd_open like EINVAL when killing Since Linux 6.16 (commit 8cf4b738f6d8, "pidfd: improve uapi when task isn't found"), pidfd_open() returns ENOENT instead of EINVAL when the pid exists but is not a thread-group leader. libcrun_kill_linux() only checked the pid with libcrun_check_pid_valid() for EINVAL, so on newer kernels it returned "open pidfd: No such file or directory" when the container's recorded pid had been reused by a thread of another process. "crun delete --force" then failed for that stopped container, and it could never be deleted. On a busy node, where the pid space wraps quickly, stopped containers accumulate. Handle ENOENT the same way as EINVAL: check that the pid still belongs to the container, and report ESRCH when it does not. Accept ENOENT in the same place in container_delete_internal(). Signed-off-by: Jonathan Siegel --- src/libcrun/container.c | 7 ++++--- src/libcrun/linux.c | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/libcrun/container.c b/src/libcrun/container.c index 05a6821781..b7bc92dae0 100644 --- a/src/libcrun/container.c +++ b/src/libcrun/container.c @@ -2025,9 +2025,10 @@ container_delete_internal (libcrun_context_t *context, libcrun_container_t *cont { errno = crun_error_get_errno (err); - /* pidfd_open returns EINVAL if the process is not a thread-group leader. - In our case it means the process already exited, so handle as ESRCH. */ - if (errno != ESRCH && errno != EINVAL) + /* pidfd_open returns EINVAL (ENOENT since Linux 6.16) if the process + is not a thread-group leader. In our case it means the process + already exited, so handle as ESRCH. */ + if (errno != ESRCH && errno != EINVAL && errno != ENOENT) return ret; crun_error_release (err); diff --git a/src/libcrun/linux.c b/src/libcrun/linux.c index c9ead7c9e7..051777fb05 100644 --- a/src/libcrun/linux.c +++ b/src/libcrun/linux.c @@ -8070,8 +8070,12 @@ libcrun_kill_linux (libcrun_container_status_t *status, int signal, libcrun_erro return libcrun_kill_linux_no_pidfd (status, true, signal, err); if (errno == ESRCH) return crun_make_error (err, errno, "process not running"); - /* Check if the PID is valid before reporting an error. */ - if (errno == EINVAL) + /* Check if the PID is valid before reporting an error. pidfd_open + fails for a pid that is not a thread-group leader, for example when + the container's pid was reused by a thread: with EINVAL before + Linux 6.16, with ENOENT since (commit 8cf4b738f6d8, "pidfd: improve + uapi when task isn't found"). */ + if (errno == EINVAL || errno == ENOENT) { int errno_saved = errno; ret = libcrun_check_pid_valid (status, err);