From: Lorenzo Stoakes Date: Thu, 12 Dec 2024 11:48:41 +0000 (+0000) Subject: mm: assert mmap write lock held on do_mmap(), mmap_region() X-Git-Tag: v6.14-rc1~77^2~200 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=df31155aff025171ae90cce91492e39b2cd5869b;p=thirdparty%2Flinux.git mm: assert mmap write lock held on do_mmap(), mmap_region() 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@oracle.com Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka Cc: Jann Horn Cc: Liam R. Howlett Signed-off-by: Andrew Morton --- diff --git a/mm/mmap.c b/mm/mmap.c index df9154b15ef91..43ef85028921f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -291,6 +291,8 @@ unsigned long do_mmap(struct file *file, unsigned long addr, *populate = 0; + mmap_assert_write_locked(mm); + if (!len) return -EINVAL; @@ -1023,6 +1025,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, 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;