linux/arch/powerpc/mm
Christophe Leroy a82471a14a powerpc/mm: Fix lockup on kernel exec fault
commit cd5d5e602f502895e47e18cd46804d6d7014e65c upstream.

The powerpc kernel is not prepared to handle exec faults from kernel.
Especially, the function is_exec_fault() will return 'false' when an
exec fault is taken by kernel, because the check is based on reading
current->thread.regs->trap which contains the trap from user.

For instance, when provoking a LKDTM EXEC_USERSPACE test,
current->thread.regs->trap is set to SYSCALL trap (0xc00), and
the fault taken by the kernel is not seen as an exec fault by
set_access_flags_filter().

Commit d7df2443cd ("powerpc/mm: Fix spurious segfaults on radix
with autonuma") made it clear and handled it properly. But later on
commit d3ca587404 ("powerpc/mm: Fix reporting of kernel execute
faults") removed that handling, introducing test based on error_code.
And here is the problem, because on the 603 all upper bits of SRR1
get cleared when the TLB instruction miss handler bails out to ISI.

Until commit cbd7e6ca0210 ("powerpc/fault: Avoid heavy
search_exception_tables() verification"), an exec fault from kernel
at a userspace address was indirectly caught by the lack of entry for
that address in the exception tables. But after that commit the
kernel mainly relies on KUAP or on core mm handling to catch wrong
user accesses. Here the access is not wrong, so mm handles it.
It is a minor fault because PAGE_EXEC is not set,
set_access_flags_filter() should set PAGE_EXEC and voila.
But as is_exec_fault() returns false as explained in the beginning,
set_access_flags_filter() bails out without setting PAGE_EXEC flag,
which leads to a forever minor exec fault.

As the kernel is not prepared to handle such exec faults, the thing to
do is to fire in bad_kernel_fault() for any exec fault taken by the
kernel, as it was prior to commit d3ca587404.

Fixes: d3ca587404 ("powerpc/mm: Fix reporting of kernel execute faults")
Cc: stable@vger.kernel.org # v4.14+
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Acked-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/024bb05105050f704743a0083fe3548702be5706.1625138205.git.christophe.leroy@csgroup.eu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-07-19 08:53:14 +02:00
..
book3s32 powerpc/32s: Don't warn when mapping RO data ROX. 2020-06-24 17:50:34 +02:00
book3s64 powerpc/64s: Fix pte update for kernel memory on radix 2021-05-14 09:44:27 +02:00
kasan Revert "powerpc/kasan: Fix shadow pages allocation failure" 2020-08-11 15:33:39 +02:00
nohash powerpc/fsl_booke: Avoid creating duplicate tlb1 entry 2020-04-17 10:50:22 +02:00
ptdump powerpc/ptdump: Fix build failure in hashpagetable.c 2020-08-21 13:05:24 +02:00
Makefile powerpc/mm: Move ioremap functions out of pgtable_32/64.c 2019-08-27 13:03:35 +10:00
copro_fault.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 153 2019-05-30 11:26:32 -07:00
dma-noncoherent.c powerpc updates for 5.4 2019-09-20 11:48:06 -07:00
drmem.c pseries/drmem: don't cache node id in drmem_lmb struct 2020-10-29 09:57:47 +01:00
fault.c powerpc/mm: Fix lockup on kernel exec fault 2021-07-19 08:53:14 +02:00
highmem.c powerpc/highmem: Change BUG_ON() to WARN_ON() 2019-04-20 22:02:11 +10:00
hugetlbpage.c powerpc/hugetlb: Fix 512k hugepages on 8xx with 16k page size 2020-02-28 17:22:18 +01:00
init-common.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
init_32.c Revert "powerpc/kasan: Fix shadow pages allocation failure" 2020-08-11 15:33:39 +02:00
init_64.c powerpc/book3s64/radix: Fix boot failure with large amount of guest memory 2020-09-23 12:40:39 +02:00
ioremap.c powerpc/mm: split out early ioremap path. 2019-08-27 13:03:35 +10:00
ioremap_32.c powerpc/mm: split out early ioremap path. 2019-08-27 13:03:35 +10:00
ioremap_64.c powerpc/mm: split out early ioremap path. 2019-08-27 13:03:35 +10:00
mem.c powerpc/mm: Fix verification of MMU_FTR_TYPE_44x 2020-12-30 11:51:39 +01:00
mmap.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
mmu_context.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
mmu_decl.h powerpc/mm: make ioremap_bot common to all 2019-08-27 13:03:34 +10:00
numa.c powerpc updates for 5.3 2019-07-13 16:08:36 -07:00
pgtable-frag.c mm: treewide: clarify pgtable_page_{ctor,dtor}() naming 2019-09-26 10:10:44 -07:00
pgtable.c powerpc updates for 5.3 2019-07-13 16:08:36 -07:00
pgtable_32.c powerpc/mm: Fix conditions to perform MMU specific management by blocks on PPC32. 2020-06-22 09:31:13 +02:00
pgtable_64.c powerpc/mm: Move ioremap functions out of pgtable_32/64.c 2019-08-27 13:03:35 +10:00
slice.c powerpc/mm: Mark get_slice_psize() & slice_addr_is_low() as notrace 2020-01-09 10:20:04 +01:00