summaryrefslogtreecommitdiff
path: root/libexec/ld.so/amd64
AgeCommit message (Collapse)Author
2024-06-04enable -fret-clean on amd64, for libc libcrypto ld.so kernel, and all theTheo de Raadt
ssh tools. The dynamic objects are entirely ret-clean, static binaries will contain a blend of cleaning and non-cleaning callers.
2023-12-20For strange reasons which made sense at the time, the text segment wasTheo de Raadt
placed head of the btext (boot.text) segment. (the boot.text segment is "unmapped" after initization, as a self-protection mechanism). this meant the LOAD's virtual addresses were not in sequence, which clearly isn't what we intended.
2023-12-11Make sure the syscall table entries are aligned on a 4-byte boundary.Theo de Raadt
Required for strict-alignment architectures and a good idea on others. same as kettenis commit to libc
2023-12-10Populate the non-LOAD openbsd.syscalls section (and PT_OPENBSD_SYSCALL)Theo de Raadt
with {uint offset, uint syscall#} entries in libc & ld.so. In libc a few syscall# entries (break, sigprocmask, _tfork, _threxit) are duplicated because additional or inline uses occur (that situation is handled elsewhere) ok kettenis
2023-11-18crt0 uses a helper function in a MD src/libexec/ld.so .h file (rather thanTheo de Raadt
reproducing the relevant defines and code in a different place) to perform minor relocations. If things go very wrong, it would call _dl_exit() -- a locally defined crt0 function which is syscall exit(2). We don't need to call exit(2) for this obscure case which doesn't happen and provides no debugging information. An 'abort' is going to provide better information. So let's change the function name to _dso_abort() and make it a single illegal instruction. ok guenther
2023-05-18If you disable retpolineplt then _dl_bind_start is called with anPhilip Guenther
indirect branch, so include an endbr64 Just In Case. ok deraadt@
2023-04-25endbr64 is potentially neccessary in the syscall stubs.Theo de Raadt
2023-02-02unify spacing for LOAD FLAGS linesTheo de Raadt
2023-01-29Unite all nitems copies in ld.so/util.hGreg Steuck
OK deraadt
2023-01-20amd64 now has xonly support via the PKU feature. Marking ld.so exec-onlyTheo de Raadt
is no longer a NOP on those systems, let's do it.
2023-01-11Add retguard to amd64 syscalls.Todd Mortimer
Since we got rid of padded syscalls we have enough registers to do this. ok deraadt@ ok kettenis@
2022-11-07Since the introduction of automatic immutable from the kernel, the munmap()Theo de Raadt
of ld.so boot.text region is now (silently) failing because the region is contained within the text LOAD, which is immutable. So create a new btext LOAD with flags PF_X|PF_R|PF_OPENBSD_MUTABLE, and place all boot.text objects in there. This LOAD must also be page-aligned so it doesn't skip unmapping some of the object region, previously it was hilariously unaligned. Similar changes for other architectures coming after more testing. ok kettenis and guenther seemed to like it also
2022-05-01Prevent out-of-bounds array access with binaries that use unsupportedMark Kettenis
relocations. ok guenther@
2022-01-17Nothing depends on archdep.h pulling in other #includes anymore,Philip Guenther
so delete the #includes and hide the RELOC_* functions that are only used by lib/csu behind "#ifdef RCRT0" these are the ones I tested; kettenis@ was on board with the concept
2022-01-08Prep .c files for removing the #includes from */archdep.hPhilip Guenther
* replace #include "archdep.h" with #includes of what is used, pulling in "syscall.h", "util.h", and "archdep.h" as needed * delete #include <sys/syscall.h> from syscall.h * only pull in <sys/stat.h> to the three files that use _dl_fstat(), forward declare struct stat in syscall.h for the others * NBBY is for <sys/select.h> macros; just use '8' in dl_printf.c * <machine/vmparam.h> is only needed on i386; conditionalize it * stop using __LDPGSZ: use _MAX_PAGE_SHIFT (already used by malloc.c) where necessary * delete other bogus #includes, order legit per style: <sys/*> then <*/*>, then <*>, then "*" dir.c improvement from jsg@ ok and testing assistance deraadt@
2021-12-23Roll the syscalls that have an off_t argument to remove the explicit padding.Philip Guenther
Switch libc and ld.so to the generic stubs for these calls. WARNING: reboot to updated kernel before installing libc or ld.so! Time for a story... When gcc (back in 1.x days) first implemented long long, it didn't (always) pass 64bit arguments in 'aligned' registers/stack slots, with the result that argument offsets didn't match structure offsets. This affected the nine system calls that pass off_t arguments: ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate To avoid having to do custom ASM wrappers for those, BSD put an explicit pad argument in so that the off_t argument would always start on a even slot and thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use __syscall() and pass an extra '0' argument. The ABIs for different CPUs eventually settled how things should be passed on each and gcc 2.x followed them. The only arch now where it helps is landisk, which needs to skip the last argument register if it would be the first half of a 64bit argument. So: add new syscalls without the pad argument and on landisk do that skipping directly in the syscall handler in the kernel. Keep compat support for the existing syscalls long enough for the transition. ok deraadt@
2021-11-14Delete all the no-op RELOC_GOT() macros and their uses.Philip Guenther
Annotate RELOC_DYN() on non-hppa as only used in lib/csu. Delete some inconsistent comments, adjust whitespace, and reorder mips64's archdep.h so that the ld.so/*/archdep.h files look (almost) the same. ok visa@ kettenis@
2019-12-07Disable ltrace for objects linked with -znow, as at least on amd64, linkingPhilip Guenther
that was deletes the lazy relocation trampoline which ltrace currently depends on problem reported by tb@ directional feedback kettenis@ ok mpi@
2019-11-29Repurpose the "syscalls must be on a writeable page" mechanism toTheo de Raadt
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
2019-11-28Revert yesterday's _dl_md_reloc() and _dl_md_reloc_got() changes:Philip Guenther
something's broken on at least i386.
2019-11-26Clean up _dl_md_reloc(): instead of having tables and piles of conditionalsPhilip Guenther
that handle a dozen relocation types for each, just have a nice little switch for the four specific relocations that actually occur. Besides being smaller and easier to understand, this fixes the COPY relocation handling to only do one symbol lookup, instead of looking up the symbol and then immediately looking it up again (with the correct flags to find the instance it needs). ok kettenis@
2019-11-26Make aarch64, amd64, arm, and i386 more like sparc64: move non-lazyPhilip Guenther
relocation from _dl_md_reloc() to _dl_md_reloc_all_plt() which has the minimal code to do it. Also, avoid division on PLTRELSZ; just use it to offset to the end. ok kettenis@
2019-10-23Prefer the size-independent ELF identifiers over the size-specific ones.Philip Guenther
Strip superfluous parens from return statements while here. Done programatically with two perl invocations idea ok kettenis@ drahn@ ok visa@
2019-10-20For more archs, ld.so itself only needs/uses the arch's "just add load offset"Philip Guenther
'relative' relocation. Take advantage of that to simplify ld.so's self-reloc code: * give the exceptional archs (hppa and mips64) copies of the current boot.c as boot_md.c * teach the Makefile to use boot_md.c when present * reduce boot.c down to the minimum necessary to handle just relative reloc * teach the Makefile to fail if the built ld.so has other types of relocs ok visa@ kettenis@
2019-10-05Delete some obsolete debugging #ifdefs blocksPhilip Guenther
ok mlarkin@, mpi@, krw@, deraadt@
2019-08-06Factor out TEXTREL mprotecting from the per-arch files into _dl_rtld(),Philip Guenther
hiding the actual grotty bits in inline functions ok mpi@
2019-08-04Simplify _dl_find_symbol(). Currently, it returns three values:Philip Guenther
- the symbol it found, returned via the second argument - the base offset of the the object it was found in, via the return value - optionally: the object it was found in, returned via the last argument Instead, return a struct with the symbol and object pointers and let the caller get the base offset from the object's obj_base member. On at least aarch64, amd64, mips64, powerpc, and sparc64, a two word struct like this is passed in registers. ok mpi@, kettenis@
2019-08-03The ABI says JUMP_SLOT relocations don't have an addend, so don't add it inPhilip Guenther
ok kettenis@
2019-08-03Suppress DWARF2 warnings on clang archs by building with -gdwarf-4Philip Guenther
ok deraadt@, kettenis@
2019-07-14ld.so's $ORIGIN handling when argv[0] is a relative path was broken byPhilip Guenther
the change in __getcwd(2)'s return value. Fix it by switching to the __realpath(2) syscall, eliminating the ld.so copy of realpath(). problem caught by regress and noted by bluhm@ ok deraadt@
2019-05-10ld.so boot cleanup support:Philip Guenther
- put functions and data which are only used before calling the executable's start function into their own page-aligned segments for unmapping (only done on amd64, arm64, armv7, powerpc, and sparc64 so far) - pass .init_array and .preinit_array functions an addition argument which is a callback to get a structure which includes a function that frees the boot text and data - sometimes delay doing RELRO processing: for a shared-object marked DF_1_INITFIRST do it after the object's .init_array, for the executable do it after the .preinit_array - improve test-ld.so to link against libpthread and trigger its initialization late libc changes to use this will come later ok kettenis@
2018-11-16Finish ld.so's transition to GNU_RELRO: eliminate support for usingPhilip Guenther
__got_{start,end} to find a region to mark read-only. It was only used for binaries that didn't have a GNU_RELRO segment, but all archs have been using that for over a year. Since support for insecure-PLT layouts on powerpc and alpha have been removed, all archs handle GNU_RELRO the same way and the support can be moved from the MD code to the MI code. ok mpi@
2018-10-25The compilers already put static arrays in .rodata when not written to;Philip Guenther
marking them const will keep a source change from silently moving them back to .data ok deraadt@ kettenis@
2018-07-09unify the various per-arch syscall.h as much as possibleTheo de Raadt
ok kettenis guenther
2018-04-27Make sure ld.so doesn't use floating point registers, as the lazy-bindingPhilip Guenther
stub doesn't preserve them and some may be used for passing arguments ok kettenis@ deraadt@ mlarkin@
2017-10-27Use <elf.h> instead of <elf_abi.h>Martin Pieuchot
ok jasper@, jca@, deraadt@
2017-08-28whitespaceTheo de Raadt
2017-08-27Replace heaps of hand-written syscall stubs with a simpler frameworkTheo de Raadt
which is largely MI. ok visa kettenis
2017-08-15Align text locations to 16 (instead of 4) to match modern recommendationsTheo de Raadt
(generally associated with hardwired BTC limitations). And then fill those alignments with 0xcc (int 3) to match our trapsled model. Resulting binaries show no sequential nop's. ok mlarkin kettenis mortimer
2017-01-24On fatal errors, kill ourselves with thrkill(0,9,NULL) instead ofPhilip Guenther
simply exiting, via helper functions _dl_die(), _dl_diedie(), and _dl_oom(). prompted by a complaint from jsing@ ok jsing@ deraadt@
2017-01-23Fix format string mismatchesPhilip Guenther
2017-01-21_dl_exit() is __dead, so it should return void.Philip Guenther
Move _dl_mmap() and _dl_mquery() inlines from archdep.h to syscall.h and remove pointless casts and unnecessary parens. ok kettenis@
2017-01-20Delete ancient macros and unnecessary #includesPhilip Guenther
ok deraadt@
2017-01-09Remove dependency on __got_{start,end} symbols and look at PT_GNU_RELROMark Kettenis
instead. Result in a few more pages that aren't writable on some platforms (such as hppa). Based on an initial diff from guenther@. Thanks to deraadt@ for testing. ok guenther@
2016-08-28ld.so doesn't need gettimeofday or lstat stubs any morePhilip Guenther
ok deraadt@
2016-07-04Remove prebind support: binding to symbol table indices is too fragilePhilip Guenther
for our development process. ok kettenis@ deraadt@
2016-06-21When handling DT_TEXTREL only set the mapping to READ+WRITE, ignoreTheo de Raadt
possible EXEC permission for the section, because the proper permission is set late, and there are no thread concerns here. Avoids W^X issues in oddball cases. ok guenther kettenis
2016-05-18fix types for mmap wrappers. A few whitespace cleanups snuck in.Theo de Raadt
ok guenther
2016-05-07Use a Thread Information Block in both single and multi-threaded programs.Philip Guenther
This stores errno, the cancelation flags, and related bits for each thread and is allocated by ld.so or libc.a. This is an ABI break from 5.9-stable! Make libpthread dlopen'able by moving the cancelation wrappers into libc and doing locking and fork/errno handling via callbacks that libpthread registers when it first initializes. 'errno' *must* be declared via <errno.h> now! Clean up libpthread's symbol exports like libc. On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec. Testing by various, particularly sthen@ and patrick@ ok kettenis@
2016-03-21Rename the system call sendsyslog2 to sendsyslog. Keep the old oneAlexander Bluhm
as osendsyslog for a while. The three argument variant is the only one that will stay. input kettenis@; OK deraadt@