linux-stable/arch/s390/mm
Gerald Schaefer 4b7d98f1b6 s390/mm: fix dynamic pagetable upgrade for hugetlbfs
commit 5f490a520b upstream.

Commit ee71d16d22 ("s390/mm: make TASK_SIZE independent from the number
of page table levels") changed the logic of TASK_SIZE and also removed the
arch_mmap_check() implementation for s390. This combination has a subtle
effect on how get_unmapped_area() for hugetlbfs pages works. It is now
possible that a user process establishes a hugetlbfs mapping at an address
above 4 TB, without triggering a dynamic pagetable upgrade from 3 to 4
levels.

This is because hugetlbfs mappings will not use mm->get_unmapped_area, but
rather file->f_op->get_unmapped_area, which currently is the generic
implementation of hugetlb_get_unmapped_area() that does not know about s390
dynamic pagetable upgrades, but with the new definition of TASK_SIZE, it
will now allow mappings above 4 TB.

Subsequent access to such a mapped address above 4 TB will result in a page
fault loop, because the CPU cannot translate such a large address with 3
pagetable levels. The fault handler will try to map in a hugepage at the
address, but due to the folded pagetable logic it will end up with creating
entries in the 3 level pagetable, possibly overwriting existing mappings,
and then it all repeats when the access is retried.

Apart from the page fault loop, this can have various nasty effects, e.g.
kernel panic from one of the BUG_ON() checks in memory management code,
or even data loss if an existing mapping gets overwritten.

Fix this by implementing HAVE_ARCH_HUGETLB_UNMAPPED_AREA support for s390,
providing an s390 version for hugetlb_get_unmapped_area() with pagetable
upgrade support similar to arch_get_unmapped_area(), which will then be
used instead of the generic version.

Fixes: ee71d16d22 ("s390/mm: make TASK_SIZE independent from the number of page table levels")
Cc: <stable@vger.kernel.org> # 4.12+
Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-02-11 04:33:58 -08:00
..
cmm.c s390/cmm: fix information leak in cmm_timeout_handler() 2019-11-06 13:06:20 +01:00
dump_pagetables.c s390: unify linker symbols usage 2018-02-27 08:05:23 +01:00
extmem.c s390/extmem: fix gcc 8 stringop-overflow warning 2018-07-02 11:24:50 +02:00
fault.c s390/mm: fix address space detection in exception handling 2019-06-11 12:20:53 +02:00
gmap.c s390/mm: Check for valid vma before zapping in gmap_discard 2018-09-12 14:46:37 +02:00
gup.c mm, gup: add missing refcount overflow checks on s390 2019-12-05 09:21:25 +01:00
hugetlbpage.c s390/mm: fix dynamic pagetable upgrade for hugetlbfs 2020-02-11 04:33:58 -08:00
init.c mm/memory_hotplug: shrink zones when offlining memory 2020-01-29 16:43:27 +01:00
maccess.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mem_detect.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mmap.c exec: pass stack rlimit into mm layout functions 2018-04-11 10:28:37 -07:00
page-states.c s390/mm: fix addressing exception after suspend/resume 2018-08-09 08:05:48 +02:00
pageattr.c s390/mm: Clear huge page storage keys on enable_skey 2018-07-30 11:20:18 +01:00
pgalloc.c s390/mm: fix mis-accounting of pgtable_bytes 2018-11-27 16:13:03 +01:00
pgtable.c s390/mm: silence compiler warning when compiling without CONFIG_PGSTE 2019-05-31 06:46:23 -07:00
vmem.c mm: pass the vmem_altmap to vmemmap_free 2018-01-08 11:46:23 -08:00