[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240816111405.11793-9-spasswolf@web.de>
Date: Fri, 16 Aug 2024 13:13:49 +0200
From: Bert Karwatzki <spasswolf@....de>
To: "Liam R . Howlett" <Liam.Howlett@...cle.com>
Cc: Bert Karwatzki <spasswolf@....de>,
Suren Baghdasaryan <surenb@...gle.com>,
Vlastimil Babka <vbabka@...e.cz>,
Lorenzo Stoakes <lstoakes@...il.com>,
Matthew Wilcox <willy@...radead.org>,
sidhartha.kumar@...cle.com,
"Paul E . McKenney" <paulmck@...nel.org>,
Jiri Olsa <olsajiri@...il.com>,
linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
Andrew Morton <akpm@...ux-foundation.org>,
Kees Cook <kees@...nel.org>,
Jeff Xu <jeffxu@...omium.org>,
"Liam R . Howlett" <Liam.Howlett@...cle.com>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Subject: [PATCH v5.1 08/19] mm/mmap: Inline munmap operation in mmap_region()
mmap_region is already passed sanitized addr and len, so change the
call to do_vmi_munmap() to do_vmi_align_munmap() and inline the other
checks.
The inlining of the function and checks is an intermediate step in the
series so future patches are easier to follow.
Signed-off-by: Liam R. Howlett <Liam.Howlett@...cle.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
---
mm/mmap.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index 6aed0b769cc4..6ed27cf12217 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1388,12 +1388,21 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
return -ENOMEM;
}
- /* Unmap any existing mapping in the area */
- error = do_vmi_munmap(&vmi, mm, addr, len, uf, false);
- if (error == -EPERM)
- return error;
- else if (error)
- return -ENOMEM;
+
+ if (unlikely(!can_modify_mm(mm, addr, end)))
+ return -EPERM;
+
+ /* arch_unmap() might do unmaps itself. */
+ arch_unmap(mm, addr, end);
+
+ /* Find the first overlapping VMA */
+ vma = vma_find(&vmi, end);
+ if (vma) {
+ /* Unmap any existing mapping in the area */
+ if (do_vmi_align_munmap(&vmi, vma, mm, addr, end, uf, false))
+ return -ENOMEM;
+ vma = NULL;
+ }
/*
* Private writable mapping: check memory availability
--
2.45.2
Powered by blists - more mailing lists