All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: David Carlier <devnexen@gmail.com>
Cc: Christian Brauner <brauner@kernel.org>,
	Shuah Khan <shuah@kernel.org>, Oleg Nesterov <oleg@redhat.com>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [RFC PATCH 0/2] pidfd: add PIDFD_GETFD_NO_SELF
Date: Sun, 29 Nov 2026 15:49:58 -0800	[thread overview]
Message-ID: <awy6Jmb_focbBy8n@localhost> (raw)
In-Reply-To: <20261129212732.805592-1-devnexen@gmail.com>

On Sun, Nov 29, 2026 at 09:27:30PM +0000, David Carlier wrote:
> 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.

Thank you. This looks reasonable to me, and I don't think it's otherwise
possible race-free in userspace without kcmp.

The other option would be to *only* reject a pidfd that refers to the
current process, and allow one referring to another process that happens
to share the fd table. However, I think the behavior in this patch
series is more useful.

Reviewed-by: Josh Triplett <josh@joshtriplett.org>

> [1] https://github.com/rust-lang/libs-team/issues/939

  parent reply	other threads:[~2026-11-29 23:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2026-11-29 23:49 ` Josh Triplett [this message]
2026-11-30 15:50 ` [RFC PATCH 0/2] pidfd: add PIDFD_GETFD_NO_SELF 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=awy6Jmb_focbBy8n@localhost \
    --to=josh@joshtriplett.org \
    --cc=brauner@kernel.org \
    --cc=devnexen@gmail.com \
    --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.