summaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorCyril Hrubis <chrubis@suse.cz>2013-04-29 15:08:33 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-10-22 09:02:25 +0100
commit9a63af54974c73f5723bf9a5c03d195f4d473c20 (patch)
treec38e05af749c5400104567d26266532cc6f510a0 /security
parent27eea92a6552a4163e17175511791f1951ffc8e9 (diff)
downloadlinux-stable-9a63af54974c73f5723bf9a5c03d195f4d473c20.tar.gz
linux-stable-9a63af54974c73f5723bf9a5c03d195f4d473c20.tar.bz2
linux-stable-9a63af54974c73f5723bf9a5c03d195f4d473c20.zip
mm/mmap: check for RLIMIT_AS before unmapping
commit e8420a8ece80b3fe810415ecf061d54ca7fab266 upstream. Fix a corner case for MAP_FIXED when requested mapping length is larger than rlimit for virtual memory. In such case any overlapping mappings are unmapped before we check for the limit and return ENOMEM. The check is moved before the loop that unmaps overlapping parts of existing mappings. When we are about to hit the limit (currently mapped pages + len > limit) we scan for overlapping pages and check again accounting for them. This fixes situation when userspace program expects that the previous mappings are preserved after the mmap() syscall has returned with error. (POSIX clearly states that successfull mapping shall replace any previous mappings.) This corner case was found and can be tested with LTP testcase: testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c In this case the mmap, which is clearly over current limit, unmaps dynamic libraries and the testcase segfaults right after returning into userspace. I've also looked at the second instance of the unmapping loop in the do_brk(). The do_brk() is called from brk() syscall and from vm_brk(). The brk() syscall checks for overlapping mappings and bails out when there are any (so it can't be triggered from the brk syscall). The vm_brk() is called only from binmft handlers so it shouldn't be triggered unless binmft handler created overlapping mappings. Signed-off-by: Cyril Hrubis <chrubis@suse.cz> Reviewed-by: Mel Gorman <mgorman@suse.de> Reviewed-by: Wanpeng Li <liwanp@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Xishi Qiu <qiuxishi@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'security')
0 files changed, 0 insertions, 0 deletions