[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <88d4e091d2905e49f6bed4fd7d98cbab1e9f0fec.1586876678.git.agordeev@linux.ibm.com>
Date: Tue, 14 Apr 2020 17:08:22 +0200
From: Alexander Gordeev <agordeev@...ux.ibm.com>
To: linux-kernel@...r.kernel.org
Cc: Alexander Gordeev <agordeev@...ux.ibm.com>, linux-mm@...ck.org
Subject: [PATCH RESEND 1/2] mm/mmap.c: add more sanity checks to get_unmapped_area()
Generic get_unmapped_area() function does sanity checks
of address and length of the area to be mapped. Yet, it
lacks checking against mmap_min_addr and mmap_end limits.
At the same time the default implementation of functions
arch_get_unmapped_area[_topdown]() and some architecture
callbacks do mmap_min_addr and mmap_end checks on its own.
Put additional checks into the generic code and do not let
architecture callbacks to get away with a possible area
outside of the allowed limits.
That could also relieve arch_get_unmapped_area[_topdown]()
callbacks of own address and length sanity checks.
CC: linux-mm@...ck.org
Signed-off-by: Alexander Gordeev <agordeev@...ux.ibm.com>
---
mm/mmap.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index 0681bd5..5b22d47 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2208,12 +2208,13 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info)
unsigned long (*get_area)(struct file *, unsigned long,
unsigned long, unsigned long, unsigned long);
+ const unsigned long mmap_end = arch_get_mmap_end(addr);
unsigned long error = arch_mmap_check(addr, len, flags);
if (error)
return error;
/* Careful about overflows.. */
- if (len > TASK_SIZE)
+ if (len > mmap_end - mmap_min_addr)
return -ENOMEM;
get_area = current->mm->get_unmapped_area;
@@ -2234,7 +2235,7 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info)
if (IS_ERR_VALUE(addr))
return addr;
- if (addr > TASK_SIZE - len)
+ if ((addr < mmap_min_addr) || (addr > mmap_end - len))
return -ENOMEM;
if (offset_in_page(addr))
return -EINVAL;
--
1.8.3.1
Powered by blists - more mailing lists