diff options
author | Oleg Nesterov <oleg@redhat.com> | 2024-02-05 15:55:32 +0100 |
---|---|---|
committer | Christian Brauner <brauner@kernel.org> | 2024-02-06 14:39:32 +0100 |
commit | 83b290c9e3b5d95891f43a4aeadf6071cbff25d3 (patch) | |
tree | 72aa83a6564a6969f44e47850230894007ffbee4 /kernel/fork.c | |
parent | e2e8a142fbd988d658ccb3da1d6f4b26a39de0fd (diff) |
pidfd: clone: allow CLONE_THREAD | CLONE_PIDFD together
copy_process() just needs to pass PIDFD_THREAD to __pidfd_prepare()
if clone_flags & CLONE_THREAD.
We can also add another CLONE_ flag (or perhaps reuse CLONE_DETACHED)
to enforce PIDFD_THREAD without CLONE_THREAD.
Originally-from: Tycho Andersen <tycho@tycho.pizza>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Link: https://lore.kernel.org/r/20240205145532.GA28823@redhat.com
Reviewed-by: Tycho Andersen <tandersen@netflix.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index aa08193d124f..4b6d994505ca 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2311,9 +2311,8 @@ __latent_entropy struct task_struct *copy_process( /* * - CLONE_DETACHED is blocked so that we can potentially * reuse it later for CLONE_PIDFD. - * - CLONE_THREAD is blocked until someone really needs it. */ - if (clone_flags & (CLONE_DETACHED | CLONE_THREAD)) + if (clone_flags & CLONE_DETACHED) return ERR_PTR(-EINVAL); } @@ -2536,8 +2535,10 @@ __latent_entropy struct task_struct *copy_process( * if the fd table isn't shared). */ if (clone_flags & CLONE_PIDFD) { + int flags = (clone_flags & CLONE_THREAD) ? PIDFD_THREAD : 0; + /* Note that no task has been attached to @pid yet. */ - retval = __pidfd_prepare(pid, 0, &pidfile); + retval = __pidfd_prepare(pid, flags, &pidfile); if (retval < 0) goto bad_fork_free_pid; pidfd = retval; |