From: David Carlier <devnexen@gmail.com>
To: Christian Brauner <brauner@kernel.org>, Shuah Khan <shuah@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>,
Josh Triplett <josh@joshtriplett.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
David Carlier <devnexen@gmail.com>
Subject: [RFC PATCH 0/2] pidfd: add PIDFD_GETFD_NO_SELF
Date: Sun, 29 Nov 2026 21:27:30 +0000 [thread overview]
Message-ID: <20261129212732.805592-1-devnexen@gmail.com> (raw)
pidfd_getfd() on a task that shares the caller's fd table duplicates one
of the caller's own descriptors. This is the only case that forces a
pidfd_getfd() wrapper in the Rust standard library to be unsafe [1].
Add PIDFD_GETFD_NO_SELF, which makes pidfd_getfd() fail with ELOOP when
the target shares the caller's fd table: the caller, its threads, or a
CLONE_FILES task that has not unshared. The check is on the fd table
rather than the thread group. A tgid comparison in userspace misses
CLONE_FILES, and kcmp(KCMP_FILES) depends on CONFIG_KCMP.
ELOOP is open to change. It only has to differ from EINVAL so that
userspace can tell an old kernel from a refused target.
Suggested by Josh Triplett. Tested on vfs.all (7.4-rc4) in a VM with
the added selftests. An LLM helped with the analysis and generated the
selftests.
[1] https://github.com/rust-lang/libs-team/issues/939
David Carlier (2):
pidfd: add PIDFD_GETFD_NO_SELF to pidfd_getfd()
selftests/pidfd: test PIDFD_GETFD_NO_SELF
include/uapi/linux/pidfd.h | 3 +
kernel/pid.c | 29 ++-
tools/testing/selftests/pidfd/pidfd.h | 4 +
.../selftests/pidfd/pidfd_getfd_test.c | 177 +++++++++++++++++-
4 files changed, 205 insertions(+), 8 deletions(-)
base-commit: 84fb6f8a1ba91eee3ffe6aa519686fce851a0e42
--
2.55.0
next reply other threads:[~2026-11-29 21:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 21:27 David Carlier [this message]
2026-11-29 21:27 ` [RFC PATCH 1/2] pidfd: add PIDFD_GETFD_NO_SELF to pidfd_getfd() David Carlier
2026-11-29 21:27 ` [RFC PATCH 2/2] selftests/pidfd: test PIDFD_GETFD_NO_SELF David Carlier
2026-11-29 23:49 ` [RFC PATCH 0/2] pidfd: add PIDFD_GETFD_NO_SELF Josh Triplett
2026-11-30 15:50 ` Bradley Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129212732.805592-1-devnexen@gmail.com \
--to=devnexen@gmail.com \
--cc=brauner@kernel.org \
--cc=josh@joshtriplett.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.