Skip to content

Commit 33a2d6b

Browse files
avaginkees
authored andcommitted
Revert "fs/exec: allow to unshare a time namespace on vfork+exec"
This reverts commit 133e2d3. Alexey pointed out a few undesirable side effects of the reverted change. First, it doesn't take into account that CLONE_VFORK can be used with CLONE_THREAD. Second, a child process doesn't enter a target time name-space, if its parent dies before the child calls exec. It happens because the parent clears vfork_done. Eric W. Biederman suggests installing a time namespace as a task gets a new mm. It includes all new processes cloned without CLONE_VM and all tasks that call exec(). This is an user API change, but we think there aren't users that depend on the old behavior. It is too late to make such changes in this release, so let's roll back this patch and introduce the right one in the next release. Cc: Alexey Izbyshev <izbyshev@ispras.ru> Cc: Christian Brauner <brauner@kernel.org> Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Florian Weimer <fweimer@redhat.com> Cc: Kees Cook <keescook@chromium.org> Signed-off-by: Andrei Vagin <avagin@gmail.com> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20220913102551.1121611-3-avagin@google.com
1 parent 2b1e892 commit 33a2d6b

3 files changed

Lines changed: 2 additions & 13 deletions

File tree

fs/exec.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
#include <linux/io_uring.h>
6666
#include <linux/syscall_user_dispatch.h>
6767
#include <linux/coredump.h>
68-
#include <linux/time_namespace.h>
6968

7069
#include <linux/uaccess.h>
7170
#include <asm/mmu_context.h>
@@ -979,12 +978,10 @@ static int exec_mmap(struct mm_struct *mm)
979978
{
980979
struct task_struct *tsk;
981980
struct mm_struct *old_mm, *active_mm;
982-
bool vfork;
983981
int ret;
984982

985983
/* Notify parent that we're no longer interested in the old VM */
986984
tsk = current;
987-
vfork = !!tsk->vfork_done;
988985
old_mm = current->mm;
989986
exec_mm_release(tsk, old_mm);
990987
if (old_mm)
@@ -1029,10 +1026,6 @@ static int exec_mmap(struct mm_struct *mm)
10291026
tsk->mm->vmacache_seqnum = 0;
10301027
vmacache_flush(tsk);
10311028
task_unlock(tsk);
1032-
1033-
if (vfork)
1034-
timens_on_fork(tsk->nsproxy, tsk);
1035-
10361029
if (old_mm) {
10371030
mmap_read_unlock(old_mm);
10381031
BUG_ON(active_mm != old_mm);

kernel/fork.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,11 +2046,8 @@ static __latent_entropy struct task_struct *copy_process(
20462046
/*
20472047
* If the new process will be in a different time namespace
20482048
* do not allow it to share VM or a thread group with the forking task.
2049-
*
2050-
* On vfork, the child process enters the target time namespace only
2051-
* after exec.
20522049
*/
2053-
if ((clone_flags & (CLONE_VM | CLONE_VFORK)) == CLONE_VM) {
2050+
if (clone_flags & (CLONE_THREAD | CLONE_VM)) {
20542051
if (nsp->time_ns != nsp->time_ns_for_children)
20552052
return ERR_PTR(-EINVAL);
20562053
}

kernel/nsproxy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
179179
if (IS_ERR(new_ns))
180180
return PTR_ERR(new_ns);
181181

182-
if ((flags & CLONE_VM) == 0)
183-
timens_on_fork(new_ns, tsk);
182+
timens_on_fork(new_ns, tsk);
184183

185184
tsk->nsproxy = new_ns;
186185
return 0;

0 commit comments

Comments
 (0)