mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Christian Brauner <brauner@kernel.org>
Cc: David Laight <david.laight.linux@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] pidfd_prepare: don't pass O_RDWR to pidfs_alloc_file()
Date: Wed, 25 Feb 2026 17:18:09 +0100	[thread overview]
Message-ID: <aZ8gwQYpIjVktcOs@redhat.com> (raw)

pidfs_alloc_file() does "flags |= O_RDWR" unconditionally.

In fact pidfd files (and some users of anon_inode_getfile_fmode) do not
need O_RDWR/FMODE_WRITE, add a comment to pidfs_alloc_file().

I guess this is an accidental legacy from 628ff7c1d8d8 ("anonfd: Allow making
anon files read-only") which added O_RDWR to every anon_inode_getf*() call,
then it was copied into the initial implementation of sys_pidfd_open().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 fs/pidfs.c    | 2 +-
 kernel/fork.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/pidfs.c b/fs/pidfs.c
index 318253344b5c..0e0176f5574f 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -1106,7 +1106,7 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags)
 	VFS_WARN_ON_ONCE(!pid->attr);
 
 	flags &= ~PIDFD_STALE;
-	flags |= O_RDWR;
+	flags |= O_RDWR; /* currently this is not necessary */
 	pidfd_file = dentry_open(&path, flags, current_cred());
 	/* Raise PIDFD_THREAD explicitly as do_dentry_open() strips it. */
 	if (!IS_ERR(pidfd_file))
diff --git a/kernel/fork.c b/kernel/fork.c
index e832da9d15a4..80171158b0cd 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1895,7 +1895,7 @@ int pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret_file)
 	if (pidfd < 0)
 		return pidfd;
 
-	pidfs_file = pidfs_alloc_file(pid, flags | O_RDWR);
+	pidfs_file = pidfs_alloc_file(pid, flags);
 	if (IS_ERR(pidfs_file))
 		return PTR_ERR(pidfs_file);
 
-- 
2.52.0



                 reply	other threads:[~2026-02-25 16:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=aZ8gwQYpIjVktcOs@redhat.com \
    --to=oleg@redhat.com \
    --cc=brauner@kernel.org \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.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 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®