From: Li Chen <me@linux.beauty>
To: "Jan Kara" <jack@suse.cz>, "Christian Brauner" <brauner@kernel.org>
Cc: "Alexander Viro" <viro@zeniv.linux.org.uk>,
"Shuah Khan" <shuah@kernel.org>,
"linux-fsdevel" <linux-fsdevel@vger.kernel.org>,
"linux-kernel" <linux-kernel@vger.kernel.org>,
"linux-kselftest" <linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH] pidfs: preserve thread pidfds reopened by file handle
Date: Tue, 28 Jul 2026 14:47:11 +0800 [thread overview]
Message-ID: <19fa77a32a4.4055e8af2310651.5579113259972318429@linux.beauty> (raw)
In-Reply-To: <v2etqvlc6cq3al2pbdf43gu5b4d5f5py7dagkblbbt6mxltfro@kospd7xpqeyo>
Hi Jan & Christian,
---- On Mon, 27 Jul 2026 23:57:14 +0800 Jan Kara <jack@suse.cz> wrote ---
> On Wed 22-07-26 14:07:37, Christian Brauner wrote:
> > On 2026-07-16 13:11 +0200, Jan Kara wrote:
> > > On Thu 16-07-26 13:27:22, Li Chen wrote:
> > > > PIDFD_THREAD shares O_EXCL. do_dentry_open() clears O_EXCL after
> > > > pidfs_export_open() validates the flags, so open_by_handle_at()
> > > > silently turns a thread pidfd into a process pidfd.
> > > >
> > > > Restore PIDFD_THREAD on the opened file, matching pidfs_alloc_file(),
> > > > and cover the restored flag with F_GETFL.
> > > >
> > > > Signed-off-by: Li Chen <me@linux.beauty>
> > >
> > > Makes sense. Just looking at this code, what about PIDFD_AUTOKILL (aka
> > > O_TRUNC?)? Reading the commit introducing it 07c3ef58223e it appears it was
> > > never meant to be directly requested by userspace so probably
> > > pidfs_export_open() needs to reject it. But that's unrelated issue to your
> > > patch so feel free to add:
> >
> > Good point. But pidfs_export_open() is guarded by
> > pidfs_export_permission() which does:
> >
> > #define VALID_FILE_HANDLE_OPEN_FLAGS \
> > (O_RDONLY | O_WRONLY | O_RDWR | O_NONBLOCK | O_CLOEXEC | O_EXCL)
> >
> > if (oflags & ~(VALID_FILE_HANDLE_OPEN_FLAGS | O_LARGEFILE))
> > return -EINVAL;
> >
> > and so is safe. But I've added the following patch on top which also
> > splats if that is passed!
> >
> > From 99a859485394eca8cf6271de09ae72ac3b846bda Mon Sep 17 00:00:00 2001
> > From: Christian Brauner <brauner@kernel.org>
> > Date: Wed, 22 Jul 2026 13:56:28 +0200
> > Subject: [PATCH] pidfs: add pidfs_dentry_open() helper
> >
> > Both pidfs_alloc_file() and pidfs_export_open() need to force O_RDWR
> > and reapply the pidfd flags that do_dentry_open() strips. Move the
> > common logic into a helper.
> >
> > PIDFD_AUTOKILL is now part of the restore mask in the file handle path
> > as well, but pidfs_export_permission() rejects O_TRUNC, so this is a
> > no-op there. But warn nonetheless.
> >
> > Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
>
> Nice! Feel free to add:
>
> Reviewed-by: Jan Kara <jack@suse.cz>
>
> Both pidfs_alloc_file() and pidfs_export_open() need to force O_RDWR
> and reapply the pidfd flags that do_dentry_open() strips. Move the
> common logic into a helper.
Thanks both.
Jan, thanks for pointing out the PIDFD_AUTOKILL angle.
Christian, thanks for factoring this into pidfs_dentry_open() and
applying the fix.
Regards,
Li
next prev parent reply other threads:[~2026-07-28 6:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 5:27 Li Chen
2026-07-16 11:11 ` Jan Kara
2026-07-22 12:07 ` Christian Brauner
2026-07-27 15:57 ` Jan Kara
2026-07-28 6:47 ` Li Chen [this message]
2026-07-22 11:49 ` Christian Brauner
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=19fa77a32a4.4055e8af2310651.5579113259972318429@linux.beauty \
--to=me@linux.beauty \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®