Skip to content

Commit 83b290c

Browse files
oleg-nesterovbrauner
authored andcommitted
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 <[email protected]> Signed-off-by: Oleg Nesterov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Tycho Andersen <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent e2e8a14 commit 83b290c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

kernel/fork.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,9 +2311,8 @@ __latent_entropy struct task_struct *copy_process(
23112311
/*
23122312
* - CLONE_DETACHED is blocked so that we can potentially
23132313
* reuse it later for CLONE_PIDFD.
2314-
* - CLONE_THREAD is blocked until someone really needs it.
23152314
*/
2316-
if (clone_flags & (CLONE_DETACHED | CLONE_THREAD))
2315+
if (clone_flags & CLONE_DETACHED)
23172316
return ERR_PTR(-EINVAL);
23182317
}
23192318

@@ -2536,8 +2535,10 @@ __latent_entropy struct task_struct *copy_process(
25362535
* if the fd table isn't shared).
25372536
*/
25382537
if (clone_flags & CLONE_PIDFD) {
2538+
int flags = (clone_flags & CLONE_THREAD) ? PIDFD_THREAD : 0;
2539+
25392540
/* Note that no task has been attached to @pid yet. */
2540-
retval = __pidfd_prepare(pid, 0, &pidfile);
2541+
retval = __pidfd_prepare(pid, flags, &pidfile);
25412542
if (retval < 0)
25422543
goto bad_fork_free_pid;
25432544
pidfd = retval;

0 commit comments

Comments
 (0)