The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] pidfd: add PIDFD_GETFD_NO_SELF
@ 2026-11-29 21:27 David Carlier
  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
  0 siblings, 2 replies; 3+ messages in thread
From: David Carlier @ 2026-11-29 21:27 UTC (permalink / raw)
  To: Christian Brauner, Shuah Khan
  Cc: Oleg Nesterov, Josh Triplett, linux-fsdevel, linux-kernel,
	linux-kselftest, David Carlier

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-29 21:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 21:27 [RFC PATCH 0/2] pidfd: add PIDFD_GETFD_NO_SELF David Carlier
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox