The patch titled Subject: binfmt_elf: take the mmap lock around find_extend_vma() has been added to the -mm tree. Its filename is binfmt_elf-take-the-mmap-lock-around-find_extend_vma.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/binfmt_elf-take-the-mmap-lock-around-find_extend_vma.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/binfmt_elf-take-the-mmap-lock-around-find_extend_vma.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Jann Horn <jannh@xxxxxxxxxx> Subject: binfmt_elf: take the mmap lock around find_extend_vma() create_elf_tables() runs after setup_new_exec(), so other tasks can already access our new mm and do things like process_madvise() on it. (At the time I'm writing this commit, process_madvise() is not in mainline yet, but has been in akpm's tree for some time.) While I believe that there are currently no APIs that would actually allow another process to mess up our VMA tree (process_madvise() is limited to MADV_COLD and MADV_PAGEOUT, and uring and userfaultfd cannot reach an mm under which no syscalls have been executed yet), this seems like an accident waiting to happen. Let's make sure that we always take the mmap lock around GUP paths as long as another process might be able to see the mm. (Yes, this diff looks suspicious because we drop the lock before doing anything with `vma`, but that's because we actually don't do anything with it apart from the NULL check.) Link: https://lkml.kernel.org/r/CAG48ez1-PBCdv3y8pn-Ty-b+FmBSLwDuVKFSt8h7wARLy0dF-Q@xxxxxxxxxxxxxx Signed-off-by: Jann Horn <jannh@xxxxxxxxxx> Cc: "Eric W . Biederman" <ebiederm@xxxxxxxxxxxx> Cc: Jason Gunthorpe <jgg@xxxxxxxxxx> Cc: John Hubbard <jhubbard@xxxxxxxxxx> Cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx> Cc: Michel Lespinasse <walken@xxxxxxxxxx> Cc: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/binfmt_elf.c | 3 +++ 1 file changed, 3 insertions(+) --- a/fs/binfmt_elf.c~binfmt_elf-take-the-mmap-lock-around-find_extend_vma +++ a/fs/binfmt_elf.c @@ -310,7 +310,10 @@ create_elf_tables(struct linux_binprm *b * 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 (mmap_read_lock_killable(mm)) + return -EINTR; vma = find_extend_vma(mm, bprm->p); + mmap_read_unlock(mm); if (!vma) return -EFAULT; _ Patches currently in -mm which might be from jannh@xxxxxxxxxx are mm-mmu_notifier-fix-mmget-assert-in-__mmu_interval_notifier_insert.patch binfmt_elf_fdpic-stop-using-dump_emit-on-user-pointers-on-mmu.patch coredump-let-dump_emit-bail-out-on-short-writes.patch coredump-refactor-page-range-dumping-into-common-helper.patch coredump-rework-elf-elf_fdpic-vma_dump_size-into-common-helper.patch binfmt_elf-binfmt_elf_fdpic-use-a-vma-list-snapshot.patch mm-gup-take-mmap_lock-in-get_dump_page.patch mm-remove-the-now-unnecessary-mmget_still_valid-hack.patch mm-gup_benchmark-take-the-mmap-lock-around-gup.patch binfmt_elf-take-the-mmap-lock-around-find_extend_vma.patch mmap-locking-api-dont-check-locking-if-the-mm-isnt-live-yet.patch mm-gup-assert-that-the-mmap-lock-is-held-in-__get_user_pages.patch