Re: [RFC][PATCH 1/3] exec: Move unshare_files down to avoid locks being dropped on exec.

From: Oleg Nesterov
Date: Mon Sep 17 2018 - 11:49:43 EST


On 09/16, Eric W. Biederman wrote:
>
> @@ -1291,6 +1292,12 @@ int flush_old_exec(struct linux_binprm * bprm)
> flush_thread();
> current->personality &= ~bprm->per_clear;
>
> + retval = unshare_files(&displaced);

I was going to sugget basically the same changes, please feel free to add
my reviewed-by to 1-3.


Just for record. If we should really worry about unshare_files() failure
after de_thread() (imo we shouldn't), we can do another change:

__do_execve_file:

unshare_fd(CLONE_FILES, &bprm->unshared_copy);
...


flush_old_exec:

de_thread();

if (bprm->unshared_copy) {
// now that we killed sub-threads recheck
if (current->files->count > 1) {
put_files_struct(current->files);
current->files = bprm->unshared_copy;
} else {
put_files_struct(bprm->unshared_copy);
}

}

but again, I think your series is fine.

Oleg.