[PATCH RFC 0/4] pidfd: improve uapi when task isn't found

From: Christian Brauner
Date: Thu Apr 03 2025 - 10:15:01 EST


Oleg,

We currently report EINVAL whenever a struct pid has no tasked attached
anymore thereby conflating two concepts:

(1) The task has already been reaped.
(2) The caller requested a pidfd for a thread-group leader but the pid
actually references a struct pid that isn't used as a thread-group
leader.

This is causing issues for non-threaded workloads as in [1] where they
expect ESRCH to be reported, not EINVAL. I think that's a very resonable
assumption.

This patch tries to allow userspace to distinguish between (1) and (2).
This is racy of course but that shouldn't matter.

Christian

Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx>
---
Christian Brauner (4):
selftests/pidfd: adapt to recent changes
pidfd: remove unneeded NULL check from pidfd_prepare()
pidfd: improve uapi when task isn't found
selftest/pidfd: add test for thread-group leader pidfd open for thread

kernel/fork.c | 31 ++++++++++++++++++++++---
tools/testing/selftests/pidfd/pidfd_info_test.c | 13 ++++++-----
2 files changed, 35 insertions(+), 9 deletions(-)
---
base-commit: a2cc6ff5ec8f91bc463fd3b0c26b61166a07eb11
change-id: 20250403-work-pidfd-fixes-54c5b13ee0ee