From: agordeev@linux.ibm.com
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, Alexander Gordeev <agordeev@linux.ibm.com>
Subject: [PATCH 1/2] mm/mmap.c: add more sanity checks to get_unmapped_area()
Date: Mon, 23 Mar 2020 14:29:28 +0100 [thread overview]
Message-ID: <d14f2cff3c891ef2c4b0337d737c6f04beacb124.1584958099.git.agordeev@linux.ibm.com> (raw)
In-Reply-To: <cover.1584958099.git.agordeev@linux.ibm.com>
From: Alexander Gordeev <agordeev@linux.ibm.com>
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.
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
---
mm/mmap.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index d681a20eb4ea..a0fcb5ca0e06 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2168,12 +2168,13 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
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;
@@ -2194,7 +2195,7 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
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;
--
2.23.0
next prev parent reply other threads:[~2020-03-23 13:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-23 13:29 [PATCH 0/2] mm/mmap: check mapping limits more strictly agordeev
2020-03-23 13:29 ` agordeev [this message]
2020-03-23 13:29 ` [PATCH 2/2] mm/mmap.c: do not allow mappings outside of allowed limits agordeev
2020-04-21 2:59 ` Andrew Morton
2020-04-21 5:29 ` Alexander Gordeev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d14f2cff3c891ef2c4b0337d737c6f04beacb124.1584958099.git.agordeev@linux.ibm.com \
--to=agordeev@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox