If the task has unshared its time namespace then exec moves it into the new time namespace as it's getting a new mm. That allocates a new nsproxy, may take the timens offset mutex and the mmap lock of the new mm to switch the vdso data and may drop the last reference to the old nsproxy. Currently, all of that happens with exec_update_lock held.
The time namespace switch isn't tied to the credentials changing. So do it after exec_update_lock has been dropped. It still happens before the vdso is mapped. Call it after security_bprm_committed_creds() so there's no failure between committing the credentials and telling the LSMs about it. Signed-off-by: Christian Brauner (Amutable) <[email protected]> --- fs/exec.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 7b261b0a5f33c..6120310f3fbab 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1232,10 +1232,6 @@ int begin_new_exec(struct linux_binprm * bprm) bprm->mm = NULL; - retval = exec_task_namespaces(); - if (retval) - goto out_unlock_exec_update; - me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_NOFREEZE | PF_NO_SETAFFINITY); flush_thread(); @@ -1334,6 +1330,11 @@ int begin_new_exec(struct linux_binprm * bprm) */ security_bprm_committed_creds(bprm); + /* Switch time namespace now that the task has a new mm. */ + retval = exec_task_namespaces(); + if (retval) + goto out_unlock_cred_guard; + /* Pass the opened binary to the interpreter. */ if (bprm->have_execfd) { struct file *executable = bprm->executable; -- 2.53.0
