@@ -299,7 +299,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
* Grow the stack manually; some architectures have a limit on how
* far ahead a user-space access may be in order to grow the stack.
*/
+ if (down_read_killable(¤t->mm->mmap_sem))
+ return -EINTR;
vma = find_extend_vma(current->mm, bprm->p);
+ up_read(¤t->mm->mmap_sem);
+
if (!vma)
return -EFAULT;
@@ -1123,11 +1127,15 @@ static int load_elf_binary(struct linux_binprm *bprm)
goto out;
#endif /* ARCH_HAS_SETUP_ADDITIONAL_PAGES */
+ /*
+ * Don't take mm->arg_lock. The concurrent change might happen only
+ * from prctl_set_mm but after de_thread we are certainly alone here.
+ */
retval = create_elf_tables(bprm, &loc->elf_ex,
load_addr, interp_load_addr);
if (retval < 0)
goto out;
- /* N.B. passed_fileno might not be initialized? */
+
current->mm->end_code = end_code;
current->mm->start_code = start_code;
current->mm->start_data = start_data;
@@ -212,7 +212,8 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
/*
* We are doing an exec(). 'current' is the process
- * doing the exec and bprm->mm is the new process's mm.
+ * doing the exec and bprm->mm is the new process's mm that is not
+ * shared yet, so no synchronization on mmap_sem.
*/
ret = get_user_pages_remote(current, bprm->mm, pos, 1, gup_flags,
&page, NULL, NULL);