linux/arch/powerpc
Christophe Leroy 59a057a891 powerpc/603: Fix protection of user pages mapped with PROT_NONE
commit c119565a15a628efdfa51352f9f6c5186e506a1c upstream.

On book3s/32, page protection is defined by the PP bits in the PTE
which provide the following protection depending on the access
keys defined in the matching segment register:
- PP 00 means RW with key 0 and N/A with key 1.
- PP 01 means RW with key 0 and RO with key 1.
- PP 10 means RW with both key 0 and key 1.
- PP 11 means RO with both key 0 and key 1.

Since the implementation of kernel userspace access protection,
PP bits have been set as follows:
- PP00 for pages without _PAGE_USER
- PP01 for pages with _PAGE_USER and _PAGE_RW
- PP11 for pages with _PAGE_USER and without _PAGE_RW

For kernelspace segments, kernel accesses are performed with key 0
and user accesses are performed with key 1. As PP00 is used for
non _PAGE_USER pages, user can't access kernel pages not flagged
_PAGE_USER while kernel can.

For userspace segments, both kernel and user accesses are performed
with key 0, therefore pages not flagged _PAGE_USER are still
accessible to the user.

This shouldn't be an issue, because userspace is expected to be
accessible to the user. But unlike most other architectures, powerpc
implements PROT_NONE protection by removing _PAGE_USER flag instead of
flagging the page as not valid. This means that pages in userspace
that are not flagged _PAGE_USER shall remain inaccessible.

To get the expected behaviour, just mimic other architectures in the
TLB miss handler by checking _PAGE_USER permission on userspace
accesses as if it was the _PAGE_PRESENT bit.

Note that this problem only is only for 603 cores. The 604+ have
an hash table, and hash_page() function already implement the
verification of _PAGE_USER permission on userspace pages.

Fixes: f342adca3a ("powerpc/32s: Prepare Kernel Userspace Access Protection")
Cc: stable@vger.kernel.org # v5.2+
Reported-by: Christoph Plattner <christoph.plattner@thalesgroup.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/4a0c6e3bb8f0c162457bf54d9bc6fd8d7b55129f.1612160907.git.christophe.leroy@csgroup.eu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-03-17 17:03:33 +01:00
..
boot powerpc/boot: Fix CONFIG_PPC_MPC52XX references 2020-08-19 08:16:17 +02:00
configs vgacon: remove software scrollback support 2020-09-17 13:47:54 +02:00
crypto
include powerpc/bitops: Fix possible undefined behaviour with fls() and fls64() 2021-01-06 14:48:36 +01:00
kernel powerpc/603: Fix protection of user pages mapped with PROT_NONE 2021-03-17 17:03:33 +01:00
kvm KVM: PPC: Make the VMX instruction emulation routines static 2021-03-04 10:26:31 +01:00
lib powerpc/64s: flush L1D after user accesses 2020-11-22 10:14:10 +01:00
math-emu
mm powerpc/mm: Fix verification of MMU_FTR_TYPE_44x 2020-12-30 11:51:39 +01:00
net
oprofile
perf powerpc/perf: Exclude kernel samples while counting events in user space. 2020-12-30 11:51:35 +01:00
platforms powerpc/pseries: Don't enforce MSI affinity with kdump 2021-03-17 17:03:30 +01:00
purgatory
sysdev powerpc: sysdev: add missing iounmap() on error in mpic_msgr_probe() 2021-01-06 14:48:39 +01:00
tools
xmon powerpc/xmon: Change printk() to pr_cont() 2020-12-30 11:51:39 +01:00
Kbuild
Kconfig powerpc/47x: Disable 256k page size 2021-03-04 10:26:31 +01:00
Kconfig.debug
Makefile powerpc: Drop -me200 addition to build flags 2020-12-16 10:56:55 +01:00
Makefile.postlink