All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: don't clobber partially overlapping VMA with MAP_FIXED_NOREPLACE
@ 2018-10-10 15:27 Jann Horn
  2018-10-10 17:19 ` Michal Hocko
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Jann Horn @ 2018-10-10 15:27 UTC (permalink / raw)
  To: linux-mm, Andrew Morton, jannh
  Cc: Khalid Aziz, Michal Hocko, Michael Ellerman,
	Russell King - ARM Linux, Andrea Arcangeli, Florian Weimer,
	John Hubbard, Matthew Wilcox, Abdul Haleem, Joel Stanley,
	Kees Cook, Jason Evans, David Goldblatt,
	Edward Tomasz Napierała, Anshuman Khandual, Daniel Micay

Daniel Micay reports that attempting to use MAP_FIXED_NOREPLACE in an
application causes that application to randomly crash. The existing check
for handling MAP_FIXED_NOREPLACE looks up the first VMA that either
overlaps or follows the requested region, and then bails out if that VMA
overlaps *the start* of the requested region. It does not bail out if the
VMA only overlaps another part of the requested region.

Fix it by checking that the found VMA only starts at or after the end of
the requested region, in which case there is no overlap.

Reported-by: Daniel Micay <danielmicay@gmail.com>
Fixes: a4ff8e8620d3 ("mm: introduce MAP_FIXED_NOREPLACE")
Cc: stable@vger.kernel.org
Signed-off-by: Jann Horn <jannh@google.com>
---
 mm/mmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 5f2b2b184c60..f7cd9cb966c0 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1410,7 +1410,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
 	if (flags & MAP_FIXED_NOREPLACE) {
 		struct vm_area_struct *vma = find_vma(mm, addr);
 
-		if (vma && vma->vm_start <= addr)
+		if (vma && vma->vm_start < addr + len)
 			return -EEXIST;
 	}
 
-- 
2.19.0.605.g01d371f741-goog

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

end of thread, other threads:[~2018-10-15  7:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-10 15:27 [PATCH] mm: don't clobber partially overlapping VMA with MAP_FIXED_NOREPLACE Jann Horn
2018-10-10 17:19 ` Michal Hocko
2018-10-10 17:26   ` Jann Horn
2018-10-10 17:38     ` Michal Hocko
2018-10-10 18:03       ` John Hubbard
2018-10-10 18:03         ` John Hubbard
2018-10-10 18:17     ` John Hubbard
2018-10-10 18:17       ` John Hubbard
2018-10-12 10:23     ` Michael Ellerman
2018-10-12 12:09       ` Jann Horn
2018-10-10 18:36 ` Kees Cook
2018-10-12 12:03 ` Vlastimil Babka
2018-10-15  7:47 ` Khalid Aziz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.