On systems without xonly mmu hardware-enforcement, we can still mitigate
authorderaadt <deraadt@openbsd.org>
Tue, 31 Jan 2023 15:18:51 +0000 (15:18 +0000)
committerderaadt <deraadt@openbsd.org>
Tue, 31 Jan 2023 15:18:51 +0000 (15:18 +0000)
commitd62ebcb2023f9bedf18a9581f9e426635774d636
tree7aa2773379a77239d941b15695c24222873de4a4
parent81be598de3cfe1801874daf5be6ac5ef83209ba9
On systems without xonly mmu hardware-enforcement, we can still mitigate
against classic BROP with a range-checking wrapper in front of copyin() and
copyinstr() which ensures the userland source doesn't overlap the main program
text, ld.so text, signal tramp text (it's mapping is hard to distinguish
so it comes along for the ride), or libc.so text.  ld.so tells the kernel
libc.so text range with msyscall(2).  The range checking for 2-4 elements is
done without locking (because all 4 ranges are immutable!) and is inexpensive.

write(sock, &open, 400) now fails with EFAULT.  No programs have been
discovered which require reading their own text segments with a system call.

On a machine without mmu enforcement, a test program reports the following:
                  userland   kernel
ld.so             readable   unreadable
mmap xz           unreadable unreadable
mmap x            readable   readable
mmap nrx          readable   readable
mmap nwx          readable   readable
mmap xnwx         readable   readable
main              readable   unreadable
libc unmapped?    readable   unreadable
libc mapped       readable   unreadable

ok kettenis, additional help from miod
33 files changed:
sys/arch/alpha/alpha/fp_complete.c
sys/arch/alpha/alpha/locore.s
sys/arch/alpha/alpha/trap.c
sys/arch/alpha/include/cpu.h
sys/arch/alpha/include/pmap.h
sys/arch/amd64/amd64/copy.S
sys/arch/amd64/include/pmap.h
sys/arch/arm/arm/bcopyinout.S
sys/arch/arm/arm/copystr.S
sys/arch/arm/include/pmap.h
sys/arch/hppa/hppa/db_disasm.c
sys/arch/hppa/include/cpu.h
sys/arch/i386/i386/locore.s
sys/arch/i386/include/pmap.h
sys/arch/m88k/include/cpu.h
sys/arch/m88k/m88k/m88110_fp.c
sys/arch/m88k/m88k/subr.S
sys/arch/m88k/m88k/trap.c
sys/arch/mips64/include/pmap.h
sys/arch/mips64/mips64/lcore_access.S
sys/arch/powerpc/include/pmap.h
sys/arch/powerpc/powerpc/pmap.c
sys/arch/sh/include/pmap.h
sys/arch/sh/sh/locore_subr.S
sys/arch/sparc64/include/pmap.h
sys/arch/sparc64/sparc64/db_interface.c
sys/arch/sparc64/sparc64/locore.s
sys/kern/exec_subr.c
sys/kern/kern_sig.c
sys/kern/kern_subr.c
sys/sys/systm.h
sys/uvm/uvm_map.c
sys/uvm/uvm_map.h