[RFC][PATCH] cgroup: Don't mess with tasks in exec

From: Eric W. Biederman
Date: Thu May 10 2018 - 00:03:39 EST



Semantically exec is supposed to be atomic with no user space visible
intermediate points. Migrating tasks during exec may change that and
lead to all manner of difficult to analyze and maintin corner cases.

So avoid the problems by simply blocking cgroup migration over the
entirety of exec.

Reported-by: Oleg Nesterov <oleg@xxxxxxxxxx>
Signed-off-by: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
---

Unless this leads to some kind of deadlock
fs/exec.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 32461a1543fc..54bb01cfc635 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1101,7 +1099,6 @@ static int de_thread(struct task_struct *tsk)
struct task_struct *leader = tsk->group_leader;

for (;;) {
- cgroup_threadgroup_change_begin(tsk);
write_lock_irq(&tasklist_lock);
/*
* Do this under tasklist_lock to ensure that
@@ -1112,7 +1109,6 @@ static int de_thread(struct task_struct *tsk)
break;
__set_current_state(TASK_KILLABLE);
write_unlock_irq(&tasklist_lock);
- cgroup_threadgroup_change_end(tsk);
schedule();
if (unlikely(__fatal_signal_pending(tsk)))
goto killed;
@@ -1750,6 +1746,7 @@ static int do_execveat_common(int fd, struct filename *filename,
if (retval)
goto out_free;

+ cgroup_threadgroup_change_begin(current);
check_unsafe_exec(bprm);
current->in_execve = 1;

@@ -1822,6 +1819,7 @@ static int do_execveat_common(int fd, struct filename *filename,
/* execve succeeded */
current->fs->in_exec = 0;
current->in_execve = 0;
+ cgroup_threadgroup_change_end(current);
membarrier_execve(current);
acct_update_integrals(current);
task_numa_free(current);
@@ -1841,6 +1839,7 @@ static int do_execveat_common(int fd, struct filename *filename,
out_unmark:
current->fs->in_exec = 0;
current->in_execve = 0;
+ cgroup_threadgroup_change_end(current);

out_free:
free_bprm(bprm);
--
2.14.1