# git rev-parse -q --verify dc8b1290efbbe974d9968106a03077823d0863d6^{commit} dc8b1290efbbe974d9968106a03077823d0863d6 already have revision, skipping fetch # git checkout -q -f -B kisskb dc8b1290efbbe974d9968106a03077823d0863d6 # git clean -qxdf # < git log -1 # commit dc8b1290efbbe974d9968106a03077823d0863d6 # Author: Russell Currey # Date: Fri Mar 1 01:49:17 2019 +1100 # # powerpc/64s: Implement KUAP for Radix MMU # # Kernel Userspace Access Prevention utilises a feature of the Radix MMU # which disallows read and write access to userspace addresses. By # utilising this, the kernel is prevented from accessing user data from # outside of trusted paths that perform proper safety checks, such as # copy_{to/from}_user() and friends. # # Userspace access is disabled from early boot and is only enabled when # performing an operation like copy_{to/from}_user(). The register that # controls this (AMR) does not prevent userspace from accessing itself, # so there is no need to save and restore when entering and exiting # userspace. # # This feature has a slight performance impact which I roughly measured # to be 3% slower in the worst case (performing 1GB of 1 byte # read()/write() syscalls), and is gated behind the CONFIG_PPC_KUAP # option for performance-critical builds. # # This feature can be tested by using the lkdtm driver (CONFIG_LKDTM=y) # and performing the following: # # # (echo ACCESS_USERSPACE) > [debugfs]/provoke-crash/DIRECT # # If enabled, this should send SIGSEGV to the thread. # # mpe: # - Drop the unused paca flags. # - Zero the UAMOR to be safe. # - Save the AMR when we enter the kernel from the kernel and then # block user access again if it's not already blocked. # - Restore on the way back to the kernel. # - This means we handle nesting of interrupts properly, ie. we are # protected inside the page fault handler caused by a user access. # - Add paranoid checking of AMR in switch and syscall return. # - Add isync()'s around AMR writes as per the ISA. # - Support selectively disabling read or write, with no support for # nesting. # # Co-authored-by: Michael Ellerman # Signed-off-by: Russell Currey # Signed-off-by: Michael Ellerman # --- # # v5: # - On kernel entry check if the AMR is already blocking user access # and if so don't do the mtspr again (pointed out by Nick). # - Rework the constants to make the asm a bit cleaner and avoid any # hard coded shifts. # - Selectively disable read or write, we don't support nesting and # shouldn't need to (famous last words). # < /opt/cross/kisskb/br-mipsel-o32-full-2016.08-613-ge98b4dd/bin/mipsel-linux-gcc --version # < /opt/cross/kisskb/br-mipsel-o32-full-2016.08-613-ge98b4dd/bin/mipsel-linux-ld --version # < git log --format=%s --max-count=1 dc8b1290efbbe974d9968106a03077823d0863d6 # < make -s -j 48 ARCH=mips O=/kisskb/build/powerpc-next_mips-defconfig_mipsel CROSS_COMPILE=/opt/cross/kisskb/br-mipsel-o32-full-2016.08-613-ge98b4dd/bin/mipsel-linux- defconfig # make -s -j 48 ARCH=mips O=/kisskb/build/powerpc-next_mips-defconfig_mipsel CROSS_COMPILE=/opt/cross/kisskb/br-mipsel-o32-full-2016.08-613-ge98b4dd/bin/mipsel-linux- /kisskb/src/arch/mips/boot/dts/xilfpga/nexys4ddr.dts:109.16-112.8: Warning (i2c_bus_reg): /i2c@10A00000/ad7420@4B: I2C bus unit address format error, expected "4b" FIT description: Linux 5.0.0-rc2-gdc8b1290efbb Created: Sat Mar 2 21:23:29 2019 Image 0 (kernel@0) Description: Linux 5.0.0-rc2-gdc8b1290efbb Created: Sat Mar 2 21:23:29 2019 Type: Kernel Image Compression: gzip compressed Data Size: 4501572 Bytes = 4396.07 KiB = 4.29 MiB Architecture: MIPS OS: Linux Load Address: 0x80100000 Entry Point: 0x80854830 Hash algo: sha1 Hash value: 2e2e93249eeceeeafbc5495b57d9fa4554a859e0 Image 1 (fdt@boston) Description: img,boston Device Tree Created: Sat Mar 2 21:23:29 2019 Type: Flat Device Tree Compression: uncompressed Data Size: 3793 Bytes = 3.70 KiB = 0.00 MiB Architecture: MIPS Hash algo: sha1 Hash value: 4799f50d688573234da6e9d7701234d394759ef4 Image 2 (fdt@ni169445) Description: NI 169445 device tree Created: Sat Mar 2 21:23:29 2019 Type: Flat Device Tree Compression: uncompressed Data Size: 1871 Bytes = 1.83 KiB = 0.00 MiB Architecture: MIPS Hash algo: sha1 Hash value: 51b89b31605ee62038c8468c429af091dfc75ec7 Image 3 (fdt@xilfpga) Description: MIPSfpga (xilfpga) Device Tree Created: Sat Mar 2 21:23:29 2019 Type: Flat Device Tree Compression: uncompressed Data Size: 2708 Bytes = 2.64 KiB = 0.00 MiB Architecture: MIPS Hash algo: sha1 Hash value: 509ce58e44c561d54539e64e9d4b47054e696fc6 Default Configuration: 'conf@default' Configuration 0 (conf@default) Description: Generic Linux kernel Kernel: kernel@0 Configuration 1 (conf@boston) Description: Boston Linux kernel Kernel: kernel@0 FDT: fdt@boston Configuration 2 (conf@ni169445) Description: NI 169445 Linux Kernel Kernel: kernel@0 FDT: fdt@ni169445 Configuration 3 (conf@xilfpga) Description: MIPSfpga Linux kernel Kernel: kernel@0 FDT: fdt@xilfpga Completed OK # rm -rf /kisskb/build/powerpc-next_mips-defconfig_mipsel # Build took: 0:01:28.115018