linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: assert mmap write lock held on do_mmap(), mmap_region()
@ 2024-12-12 11:48 Lorenzo Stoakes
  2024-12-13 14:06 ` Vlastimil Babka
  0 siblings, 1 reply; 2+ messages in thread
From: Lorenzo Stoakes @ 2024-12-12 11:48 UTC (permalink / raw)
  To: Andrew Morton, Liam R . Howlett
  Cc: Vlastimil Babka, Jann Horn, linux-mm, linux-kernel

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.

Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
 mm/mmap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/mmap.c b/mm/mmap.c
index df9154b15ef9..43ef85028921 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;
--
2.47.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-13 14:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-12 11:48 [PATCH] mm: assert mmap write lock held on do_mmap(), mmap_region() Lorenzo Stoakes
2024-12-13 14:06 ` Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox