diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2019-11-29 06:34:47 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2019-11-29 06:34:47 +0000 |
commit | f67b268725d23fd3229f73b136ba575514edf1a1 (patch) | |
tree | 707fd46fa1309120b07da0ff3342c12297961096 /libexec/ld.so/library_mquery.c | |
parent | 6760a6095c934a222278e6d1c4e2209b9b96f736 (diff) |
Repurpose the "syscalls must be on a writeable page" mechanism to
enforce a new policy: system calls must be in pre-registered regions.
We have discussed more strict checks than this, but none satisfy the
cost/benefit based upon our understanding of attack methods, anyways
let's see what the next iteration looks like.
This is intended to harden (translation: attackers must put extra
effort into attacking) against a mixture of W^X failures and JIT bugs
which allow syscall misinterpretation, especially in environments with
polymorphic-instruction/variable-sized instructions. It fits in a bit
with libc/libcrypto/ld.so random relink on boot and no-restart-at-crash
behaviour, particularily for remote problems. Less effective once on-host
since someone the libraries can be read.
For static-executables the kernel registers the main program's
PIE-mapped exec section valid, as well as the randomly-placed sigtramp
page. For dynamic executables ELF ld.so's exec segment is also
labelled valid; ld.so then has enough information to register libc's
exec section as valid via call-once msyscall(2)
For dynamic binaries, we continue to to permit the main program exec
segment because "go" (and potentially a few other applications) have
embedded system calls in the main program. Hopefully at least go gets
fixed soon.
We declare the concept of embedded syscalls a bad idea for numerous
reasons, as we notice the ecosystem has many of
static-syscall-in-base-binary which are dynamically linked against
libraries which in turn use libc, which contains another set of
syscall stubs. We've been concerned about adding even one additional
syscall entry point... but go's approach tends to double the entry-point
attack surface.
This was started at a nano-hackathon in Bob Beck's basement 2 weeks
ago during a long discussion with mortimer trying to hide from the SSL
scream-conversations, and finished in more comfortable circumstances
next to a wood-stove at Elk Lakes cabin with UVM scream-conversations.
ok guenther kettenis mortimer, lots of feedback from others
conversations about go with jsing tb sthen
Diffstat (limited to 'libexec/ld.so/library_mquery.c')
-rw-r--r-- | libexec/ld.so/library_mquery.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/libexec/ld.so/library_mquery.c b/libexec/ld.so/library_mquery.c index 6f061410f51..f7e2baaa747 100644 --- a/libexec/ld.so/library_mquery.c +++ b/libexec/ld.so/library_mquery.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library_mquery.c,v 1.60 2019/10/04 17:42:16 guenther Exp $ */ +/* $OpenBSD: library_mquery.c,v 1.61 2019/11/29 06:34:44 deraadt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -112,7 +112,8 @@ _dl_tryload_shlib(const char *libname, int type, int flags) Elf_Phdr *ptls = NULL; Elf_Addr relro_addr = 0, relro_size = 0; struct stat sb; - char hbuf[4096]; + char hbuf[4096], *exec_start = 0; + size_t exec_size = 0; #define ROUND_PG(x) (((x) + align) & ~(align)) #define TRUNC_PG(x) ((x) & ~(align)) @@ -288,6 +289,11 @@ retry: load_end = (Elf_Addr)ld->start + ROUND_PG(ld->size); } + if ((flags & PROT_EXEC) && exec_start == 0) { + exec_start = ld->start; + exec_size = ROUND_PG(ld->size); + } + phdp = (Elf_Phdr *)(hbuf + ehdr->e_phoff); for (i = 0; i < ehdr->e_phnum; i++, phdp++) { if (phdp->p_type == PT_OPENBSD_RANDOMIZE) @@ -318,6 +324,13 @@ retry: if (ptls != NULL && ptls->p_memsz) _dl_set_tls(object, ptls, (Elf_Addr)lowld->start, libname); + + /* Request permission for system calls in libc.so's text segment */ + if (soname != NULL && + _dl_strncmp(soname, "libc.so.", 8) == 0) { + if (_dl_msyscall(exec_start, exec_size) == -1) + _dl_printf("msyscall %lx %lx error\n"); + } } else { _dl_load_list_free(lowld); } |