Skip to content

Commit 232590e

Browse files
committed
Revert "pidfd: prevent creation of pidfds for kthreads"
This reverts commit 3b5bbe7. Eric reported that systemd-shutdown gets broken by blocking the creating of pidfds for kthreads as older versions seems to rely on being able to create a pidfd for any process in /proc. Reported-by: Eric Biggers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 524b2c6 commit 232590e

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

kernel/fork.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,23 +2053,10 @@ static int __pidfd_prepare(struct pid *pid, unsigned int flags, struct file **re
20532053
*/
20542054
int pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret)
20552055
{
2056-
if (!pid)
2057-
return -EINVAL;
2058-
2059-
scoped_guard(rcu) {
2060-
struct task_struct *tsk;
2061-
2062-
if (flags & PIDFD_THREAD)
2063-
tsk = pid_task(pid, PIDTYPE_PID);
2064-
else
2065-
tsk = pid_task(pid, PIDTYPE_TGID);
2066-
if (!tsk)
2067-
return -EINVAL;
2056+
bool thread = flags & PIDFD_THREAD;
20682057

2069-
/* Don't create pidfds for kernel threads for now. */
2070-
if (tsk->flags & PF_KTHREAD)
2071-
return -EINVAL;
2072-
}
2058+
if (!pid || !pid_has_task(pid, thread ? PIDTYPE_PID : PIDTYPE_TGID))
2059+
return -EINVAL;
20732060

20742061
return __pidfd_prepare(pid, flags, ret);
20752062
}
@@ -2416,12 +2403,6 @@ __latent_entropy struct task_struct *copy_process(
24162403
if (clone_flags & CLONE_PIDFD) {
24172404
int flags = (clone_flags & CLONE_THREAD) ? PIDFD_THREAD : 0;
24182405

2419-
/* Don't create pidfds for kernel threads for now. */
2420-
if (args->kthread) {
2421-
retval = -EINVAL;
2422-
goto bad_fork_free_pid;
2423-
}
2424-
24252406
/* Note that no task has been attached to @pid yet. */
24262407
retval = __pidfd_prepare(pid, flags, &pidfile);
24272408
if (retval < 0)

0 commit comments

Comments
 (0)