The patch titled Subject: mm: assert mmap write lock held on do_mmap(), mmap_region() has been added to the -mm mm-unstable branch. Its filename is mm-assert-mmap-write-lock-held-on-do_mmap-mmap_region.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-assert-mmap-write-lock-held-on-do_mmap-mmap_region.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm 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 via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx> Subject: mm: assert mmap write lock held on do_mmap(), mmap_region() Date: Thu, 12 Dec 2024 11:48:41 +0000 Both of these functions can be invoked outside of mm, so it is probably a good idea to assert that the required lock is held. Will only have an impact if CONFIG_DEBUG_VM is set, otherwise this amounts to no change at all. Link: https://lkml.kernel.org/r/20241212114841.55185-1-lorenzo.stoakes@xxxxxxxxxx Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx> Cc: Jann Horn <jannh@xxxxxxxxxx> Cc: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/mmap.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/mm/mmap.c~mm-assert-mmap-write-lock-held-on-do_mmap-mmap_region +++ a/mm/mmap.c @@ -291,6 +291,8 @@ unsigned long do_mmap(struct file *file, *populate = 0; + mmap_assert_write_locked(mm); + if (!len) return -EINVAL; @@ -1023,6 +1025,8 @@ unsigned long mmap_region(struct file *f unsigned long ret; bool writable_file_mapping = false; + mmap_assert_write_locked(current->mm); + /* Check to see if MDWE is applicable. */ if (map_deny_write_exec(vm_flags, vm_flags)) return -EACCES; _ Patches currently in -mm which might be from lorenzo.stoakes@xxxxxxxxxx are docs-mm-add-vma-locks-documentation.patch mm-reinstate-ability-to-map-write-sealed-memfd-mappings-read-only.patch selftests-memfd-add-test-for-mapping-write-sealed-memfd-read-only.patch mm-correctly-reference-merged-vma.patch fork-avoid-inappropriate-uprobe-access-to-invalid-mm.patch mm-vma-move-brk-internals-to-mm-vmac.patch mm-vma-move-brk-internals-to-mm-vmac-fix.patch mm-vma-move-unmapped_area-internals-to-mm-vmac.patch mm-abstract-get_arg_page-stack-expansion-and-mmap-read-lock.patch mm-vma-move-stack-expansion-logic-to-mm-vmac.patch mm-vma-move-__vm_munmap-to-mm-vmac.patch selftests-mm-add-fork-cow-guard-page-test.patch mm-enforce-__must_check-on-vma-merge-and-split.patch mm-perform-all-memfd-seal-checks-in-a-single-place.patch mm-perform-all-memfd-seal-checks-in-a-single-place-fix.patch maintainers-update-memory-mapping-section.patch mm-assert-mmap-write-lock-held-on-do_mmap-mmap_region.patch