]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fork: Stop allowing kthreads to call execve
authorEric W. Biederman <ebiederm@xmission.com>
Mon, 11 Apr 2022 19:15:54 +0000 (14:15 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Sat, 7 May 2022 14:01:59 +0000 (09:01 -0500)
Now that kernel_execve is no longer called from kernel threads stop
supporting kernel threads calling kernel_execve.

Remove the code for converting a kthread to a normal thread in execve.

Document the restriction that kthreads may not call kernel_execve by
having kernel_execve fail if called by a kthread.

Link: https://lkml.kernel.org/r/20220506141512.516114-7-ebiederm@xmission.com
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
fs/exec.c

index 75eb6e0ee7b2f5ad9454b3092cc116d7f55b2f62..9c5260e74517bc67ffab4d782ea3dfade549d750 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1308,7 +1308,7 @@ int begin_new_exec(struct linux_binprm * bprm)
        if (retval)
                goto out_unlock;
 
-       me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD |
+       me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC |
                                        PF_NOFREEZE | PF_NO_SETAFFINITY);
        flush_thread();
        me->personality &= ~bprm->per_clear;
@@ -1953,8 +1953,8 @@ int kernel_execve(const char *kernel_filename,
        int fd = AT_FDCWD;
        int retval;
 
-       if (WARN_ON_ONCE((current->flags & PF_KTHREAD) &&
-                       (current->worker_private)))
+       /* It is non-sense for kernel threads to call execve */
+       if (WARN_ON_ONCE(current->flags & PF_KTHREAD))
                return -EINVAL;
 
        filename = getname_kernel(kernel_filename);