All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mm: Do not allow non-MAP_FIXED mapping across DEFAULT_MAP_WINDOW border
@ 2017-11-07 13:05 ` Kirill A. Shutemov
  0 siblings, 0 replies; 24+ messages in thread
From: Kirill A. Shutemov @ 2017-11-07 13:05 UTC (permalink / raw)
  To: Ingo Molnar, Linus Torvalds, x86, Thomas Gleixner, H. Peter Anvin
  Cc: Andy Lutomirski, Cyrill Gorcunov, Nicholas Piggin, linux-mm,
	linux-kernel, Kirill A. Shutemov

In case of 5-level paging, we don't put any mapping above 47-bit, unless
userspace explicitly asked for it.

Userspace can ask for allocation from full address space by specifying
hint address above 47-bit.

Nicholas noticed that current implementation violates this interface:
we can get vma partly in high addresses if we ask for a mapping at very
end of 47-bit address space.

Let's make sure that, when consider hint address for non-MAP_FIXED
mapping, start and end of resulting vma are on the same side of 47-bit
border.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reported-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/x86/kernel/sys_x86_64.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
index a63fe77b3217..64b1a0d22247 100644
--- a/arch/x86/kernel/sys_x86_64.c
+++ b/arch/x86/kernel/sys_x86_64.c
@@ -198,11 +198,19 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
 	/* requesting a specific address */
 	if (addr) {
 		addr = PAGE_ALIGN(addr);
+		if (TASK_SIZE - len < addr)
+			goto get_unmapped_area;
+
+		/* The mapping shouldn't cross DEFAULT_MAP_WINDOW border */
+		if ((addr > DEFAULT_MAP_WINDOW) !=
+				(addr + len > DEFAULT_MAP_WINDOW))
+			goto get_unmapped_area;
+
 		vma = find_vma(mm, addr);
-		if (TASK_SIZE - len >= addr &&
-				(!vma || addr + len <= vm_start_gap(vma)))
+		if (!vma || addr + len <= vm_start_gap(vma))
 			return addr;
 	}
+get_unmapped_area:
 
 	info.flags = VM_UNMAPPED_AREA_TOPDOWN;
 	info.length = len;
-- 
2.14.2

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

end of thread, other threads:[~2017-11-14 12:12 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-07 13:05 [PATCH] x86/mm: Do not allow non-MAP_FIXED mapping across DEFAULT_MAP_WINDOW border Kirill A. Shutemov
2017-11-07 13:05 ` Kirill A. Shutemov
2017-11-13 15:43 ` Thomas Gleixner
2017-11-13 15:43   ` Thomas Gleixner
2017-11-13 16:41   ` Kirill A. Shutemov
2017-11-13 16:41     ` Kirill A. Shutemov
2017-11-13 16:57     ` Thomas Gleixner
2017-11-13 16:57       ` Thomas Gleixner
2017-11-13 19:14       ` Thomas Gleixner
2017-11-13 19:14         ` Thomas Gleixner
2017-11-13 20:06         ` Kirill A. Shutemov
2017-11-13 20:06           ` Kirill A. Shutemov
2017-11-13 21:14           ` Thomas Gleixner
2017-11-13 21:14             ` Thomas Gleixner
2017-11-14 12:05             ` Kirill A. Shutemov
2017-11-14 12:05               ` Kirill A. Shutemov
2017-11-14 12:11               ` Thomas Gleixner
2017-11-14 12:11                 ` Thomas Gleixner
2017-11-13 20:00       ` Kirill A. Shutemov
2017-11-13 20:00         ` Kirill A. Shutemov
2017-11-13 21:17         ` Thomas Gleixner
2017-11-13 21:17           ` Thomas Gleixner
2017-11-14 12:06           ` Kirill A. Shutemov
2017-11-14 12:06             ` Kirill A. Shutemov

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.