Files
kernel_arpi/arch/powerpc/include/asm
Christophe Leroy 5a85790059 powerpc/book3e: Fix set_memory_x() and set_memory_nx()
[ Upstream commit b6cb20fdc2735f8b2e082937066c33fe376c2ee2 ]

set_memory_x() calls pte_mkexec() which sets _PAGE_EXEC.
set_memory_nx() calls pte_exprotec() which clears _PAGE_EXEC.

Book3e has 2 bits, UX and SX, which defines the exec rights
resp. for user (PR=1) and for kernel (PR=0).

_PAGE_EXEC is defined as UX only.

An executable kernel page is set with either _PAGE_KERNEL_RWX
or _PAGE_KERNEL_ROX, which both have SX set and UX cleared.

So set_memory_nx() call for an executable kernel page does
nothing because UX is already cleared.

And set_memory_x() on a non-executable kernel page makes it
executable for the user and keeps it non-executable for kernel.

Also, pte_exec() always returns 'false' on kernel pages, because
it checks _PAGE_EXEC which doesn't include SX, so for instance
the W+X check doesn't work.

To fix this:
  - change tlb_low_64e.S to use _PAGE_BAP_UX instead of _PAGE_USER
  - sets both UX and SX in _PAGE_EXEC so that pte_exec() returns
    true whenever one of the two bits is set and pte_exprotect()
    clears both bits.
  - Define a book3e specific version of pte_mkexec() which sets
    either SX or UX based on UR.

Fixes: 1f9ad21c3b ("powerpc/mm: Implement set_memory() routines")
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/c41100f9c144dc5b62e5a751b810190c6b5d42fd.1635226743.git.christophe.leroy@csgroup.eu
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-18 19:16:57 +01:00
..
2021-09-08 15:32:35 -07:00
2021-04-08 21:17:42 +10:00
2021-08-10 23:14:55 +10:00
2020-10-07 22:34:47 +11:00
2020-12-05 21:49:52 +11:00
2021-03-24 14:09:29 +11:00
2021-05-07 00:26:34 -07:00
2021-03-24 14:09:30 +11:00
2021-07-01 11:06:03 -07:00
2021-02-09 01:09:44 +11:00
2021-09-03 22:54:12 +10:00
2021-08-10 23:14:55 +10:00
2021-06-25 00:07:10 +10:00
2021-07-08 11:48:23 -07:00
2021-08-23 19:28:20 +10:00
2020-12-04 01:01:19 +11:00
2021-02-09 00:10:50 +11:00