From bf6672d2143897807115645490c654245d428906 Mon Sep 17 00:00:00 2001 From: Stephen Rothwell <sfr@canb.auug.org.au> Date: Mon, 17 Mar 2025 23:34:19 +1100 Subject: [PATCH] Revert "pidfs: ensure that PIDFS_INFO_EXIT is available" This reverts commit b0f4119d8b2a680c8cd019f41c64e8b5444c6b83. --- fs/pidfs.c | 54 ++++----------------------------------------------- kernel/fork.c | 7 ++----- 2 files changed, 6 insertions(+), 55 deletions(-) diff --git a/fs/pidfs.c b/fs/pidfs.c index d52643cc9b16c..079a5b1b34938 100644 --- a/fs/pidfs.c +++ b/fs/pidfs.c @@ -762,49 +762,8 @@ static int pidfs_export_permission(struct handle_to_path_ctx *ctx, return 0; } -static inline bool pidfs_pid_valid(struct pid *pid, const struct path *path, - unsigned int flags) -{ - enum pid_type type; - - if (flags & CLONE_PIDFD) - return true; - - /* - * Make sure that if a pidfd is created PIDFD_INFO_EXIT - * information will be available. So after an inode for the - * pidfd has been allocated perform another check that the pid - * is still alive. If it is exit information is available even - * if the task gets reaped before the pidfd is returned to - * userspace. The only exception is CLONE_PIDFD where no task - * linkage has been established for @pid yet and the kernel is - * in the middle of process creation so there's nothing for - * pidfs to miss. - */ - if (flags & PIDFD_THREAD) - type = PIDTYPE_PID; - else - type = PIDTYPE_TGID; - - /* - * Since pidfs_exit() is called before struct pid's task linkage - * is removed the case where the task got reaped but a dentry - * was already attached to struct pid and exit information was - * recorded and published can be handled correctly. - */ - if (unlikely(!pid_has_task(pid, type))) { - struct inode *inode = d_inode(path->dentry); - return !!READ_ONCE(pidfs_i(inode)->exit_info); - } - - return true; -} - static struct file *pidfs_export_open(struct path *path, unsigned int oflags) { - if (!pidfs_pid_valid(d_inode(path->dentry)->i_private, path, oflags)) - return ERR_PTR(-ESRCH); - /* * Clear O_LARGEFILE as open_by_handle_at() forces it and raise * O_RDWR as pidfds always are. @@ -870,24 +829,19 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags) { struct file *pidfd_file; - struct path path __free(path_put) = {}; - unsigned int pidfd_flags = (flags & ~CLONE_PIDFD); + struct path path; int ret; - BUILD_BUG_ON(O_DSYNC != CLONE_PIDFD); - ret = path_from_stashed(&pid->stashed, pidfs_mnt, get_pid(pid), &path); if (ret < 0) return ERR_PTR(ret); - if (!pidfs_pid_valid(pid, &path, flags)) - return ERR_PTR(-ESRCH); - - pidfd_file = dentry_open(&path, pidfd_flags, current_cred()); + pidfd_file = dentry_open(&path, flags, current_cred()); /* Raise PIDFD_THREAD explicitly as do_dentry_open() strips it. */ if (!IS_ERR(pidfd_file)) - pidfd_file->f_flags |= (pidfd_flags & PIDFD_THREAD); + pidfd_file->f_flags |= (flags & PIDFD_THREAD); + path_put(&path); return pidfd_file; } diff --git a/kernel/fork.c b/kernel/fork.c index eb6bab188d1c9..081dec23ff908 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2456,11 +2456,8 @@ __latent_entropy struct task_struct *copy_process( if (clone_flags & CLONE_PIDFD) { int flags = (clone_flags & CLONE_THREAD) ? PIDFD_THREAD : 0; - /* - * Note that no task has been attached to @pid yet indicate - * that via CLONE_PIDFD. - */ - retval = __pidfd_prepare(pid, flags | CLONE_PIDFD, &pidfile); + /* Note that no task has been attached to @pid yet. */ + retval = __pidfd_prepare(pid, flags, &pidfile); if (retval < 0) goto bad_fork_free_pid; pidfd = retval; -- GitLab