@@ -9,6 +9,7 @@
#include <linux/string.h>
#include <linux/userfaultfd_k.h>
#include <linux/swapops.h>
+#include <linux/security.h>
/**
* folio_is_file_lru - Should the folio be on a file LRU or anon LRU?
@@ -613,4 +614,17 @@ static inline bool vma_has_recency(struct vm_area_struct *vma)
return true;
}
+/*
+ * If a hint addr is less than mmap_min_addr change hint to be as
+ * low as possible but still greater than mmap_min_addr
+ */
+static inline unsigned long round_hint_to_min(unsigned long hint)
+{
+ hint &= PAGE_MASK;
+ if (((void *)hint != NULL) &&
+ (hint < mmap_min_addr))
+ return PAGE_ALIGN(mmap_min_addr);
+ return hint;
+}
+
#endif
@@ -215,19 +215,6 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
return origbrk;
}
-/*
- * If a hint addr is less than mmap_min_addr change hint to be as
- * low as possible but still greater than mmap_min_addr
- */
-static inline unsigned long round_hint_to_min(unsigned long hint)
-{
- hint &= PAGE_MASK;
- if (((void *)hint != NULL) &&
- (hint < mmap_min_addr))
- return PAGE_ALIGN(mmap_min_addr);
- return hint;
-}
-
bool mlock_future_ok(struct mm_struct *mm, unsigned long flags,
unsigned long bytes)
{
@@ -1109,6 +1109,9 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
goto out;
}
+ if (!(flags & MREMAP_FIXED))
+ new_addr = round_hint_to_min(new_addr);
+
if (flags & (MREMAP_FIXED | MREMAP_DONTUNMAP)) {
ret = mremap_to(addr, old_len, new_addr, new_len,
&locked, flags, &uf, &uf_unmap_early,
MREMAP_DONTUNMAP allows for a get_unmapped_area() hint when used without MREMAP_FIXED. This was behavior was introduced inadvertently and should be rounded to the mmap_min_address like in mmap(2). Signed-off-by: Brian Geffon <bgeffon@google.com> --- include/linux/mm_inline.h | 14 ++++++++++++++ mm/mmap.c | 13 ------------- mm/mremap.c | 3 +++ 3 files changed, 17 insertions(+), 13 deletions(-)