[PATCH v2 1/3] pidfs: move O_RDWR into pidfs_alloc_file()

From: Christian Brauner
Date: Mon Apr 14 2025 - 10:21:45 EST


Since all pidfds must be O_RDWR currently enfore that directly in the
file allocation function itself instead of letting callers specify it.

Tested-by: Luca Boccassi <luca.boccassi@xxxxxxxxx>
Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx>
---
fs/pidfs.c | 1 +
kernel/fork.c | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/pidfs.c b/fs/pidfs.c
index d64a4cbeb0da..50e69a9e104a 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -888,6 +888,7 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags)
return ERR_PTR(-ESRCH);

flags &= ~PIDFD_CLONE;
+ flags |= O_RDWR;
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 c4b26cd8998b..d184e51196a2 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2071,7 +2071,7 @@ static int __pidfd_prepare(struct pid *pid, unsigned int flags, struct file **re
if (pidfd < 0)
return pidfd;

- pidfd_file = pidfs_alloc_file(pid, flags | O_RDWR);
+ pidfd_file = pidfs_alloc_file(pid, flags);
if (IS_ERR(pidfd_file))
return PTR_ERR(pidfd_file);


--
2.47.2