Skip to content

Commit 24baca5

Browse files
committed
clone: add CLONE_NNP
Add a new clone3() flag CLONE_NNP that sets no_new_privs on the child process at clone time. This is analogous to prctl(PR_SET_NO_NEW_PRIVS) but applied at process creation rather than requiring a separate step after the child starts running. CLONE_NNP is rejected with CLONE_THREAD. It's conceptually a lot simpler if the whole thread-group is forced into NNP and not have single threads running around with NNP. Link: https://patch.msgid.link/20260226-work-pidfs-autoreap-v5-2-d148b984a989@kernel.org Reviewed-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 12ae2c8 commit 24baca5

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

include/uapi/linux/sched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#define CLONE_CLEAR_SIGHAND (1ULL << 32) /* Clear any signal handler and reset to SIG_DFL. */
3838
#define CLONE_INTO_CGROUP (1ULL << 33) /* Clone into a specific cgroup given the right permissions. */
3939
#define CLONE_AUTOREAP (1ULL << 34) /* Auto-reap child on exit. */
40+
#define CLONE_NNP (1ULL << 35) /* Set no_new_privs on child. */
4041

4142
/*
4243
* cloning flags intersect with CSIGNAL so can be used with unshare and clone3

kernel/fork.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,11 @@ __latent_entropy struct task_struct *copy_process(
20402040
if ((clone_flags & CLONE_PARENT) && current->signal->autoreap)
20412041
return ERR_PTR(-EINVAL);
20422042

2043+
if (clone_flags & CLONE_NNP) {
2044+
if (clone_flags & CLONE_THREAD)
2045+
return ERR_PTR(-EINVAL);
2046+
}
2047+
20432048
/*
20442049
* Force any signals received before this point to be delivered
20452050
* before the fork happens. Collect up signals sent to multiple
@@ -2424,6 +2429,9 @@ __latent_entropy struct task_struct *copy_process(
24242429
*/
24252430
copy_seccomp(p);
24262431

2432+
if (clone_flags & CLONE_NNP)
2433+
task_set_no_new_privs(p);
2434+
24272435
init_task_pid_links(p);
24282436
if (likely(p->pid)) {
24292437
ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
@@ -2912,7 +2920,7 @@ static bool clone3_args_valid(struct kernel_clone_args *kargs)
29122920
/* Verify that no unknown flags are passed along. */
29132921
if (kargs->flags &
29142922
~(CLONE_LEGACY_FLAGS | CLONE_CLEAR_SIGHAND | CLONE_INTO_CGROUP |
2915-
CLONE_AUTOREAP))
2923+
CLONE_AUTOREAP | CLONE_NNP))
29162924
return false;
29172925

29182926
/*

0 commit comments

Comments
 (0)