Skip to content

Commit

Permalink
fork: Stop allowing kthreads to call execve
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: "Eric W. Biederman" <[email protected]>
  • Loading branch information
ebiederm committed May 7, 2022
1 parent 753550e commit 1b2552c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1b2552c

Please sign in to comment.