From 418d2192e0e2bcdc7fe10f4f331231a2ad5a5c00 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 31 Jul 2024 13:38:50 +0200 Subject: [PATCH] cgroup-util: Don't try to open pidfd for kernel threads The kernel might start returning -EINVAL when trying to open pidfd's for kernel threads so let's not try to open pidfd's for kernel threads. (cherry picked from commit ead48ec35c863650944352a3455f26ce3b393058) Resolves: RHEL-55746 --- src/basic/cgroup-util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 1fc83a656a..b0fe0ecbe8 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -149,7 +149,9 @@ int cg_read_pidref(FILE *f, PidRef *ret, CGroupFlags flags) { if (pid == 0) return -EREMOTE; - if (FLAGS_SET(flags, CGROUP_NO_PIDFD)) { + /* We might read kernel thread pids from cgroup.procs for which we cannot create a pidfd so + * catch those and don't try to create a pidfd for them. */ + if (FLAGS_SET(flags, CGROUP_NO_PIDFD) || pid_is_kernel_thread(pid) > 0) { *ret = PIDREF_MAKE_FROM_PID(pid); return 1; }