diff options
author | 2014-02-16 00:33:44 +0000 | |
---|---|---|
committer | 2014-02-16 00:33:44 +0000 | |
commit | e026d09d28b43a8ee26685c712c31793a2521911 (patch) | |
tree | 0f98aa0940799d83eae4f4337940e617d8107c71 | |
parent | Further tweak to mpfree(). Don't bother setting about-to-be-freed (diff) | |
download | wireguard-openbsd-e026d09d28b43a8ee26685c712c31793a2521911.tar.xz wireguard-openbsd-e026d09d28b43a8ee26685c712c31793a2521911.zip |
Update ld.so-cookie test which is currently broken and gets in the
way of SSP testing. For some reason this diff keeps escaping from
cvs commit...
Basic idea:
* Use dl_iterate_phdr() to iterate all loaded ELF program headers.
* Check that we actually find a header for ld.so.
* For ld.so, check that we find a PT_OPENBSD_RANDOMIZE segment.
* For each PT_OPENBSD_RANDOMIZE segment, check that at least one
byte in the memory range is non-zero.
Written by matthew@.
"Please go ahaed" kettenis@.
"Move fast" deraadt@, a week ago.
-rw-r--r-- | regress/libexec/ld.so/randomdata/ld.so-cookie/test.c | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/regress/libexec/ld.so/randomdata/ld.so-cookie/test.c b/regress/libexec/ld.so/randomdata/ld.so-cookie/test.c index 3053058913f..4d145096287 100644 --- a/regress/libexec/ld.so/randomdata/ld.so-cookie/test.c +++ b/regress/libexec/ld.so/randomdata/ld.so-cookie/test.c @@ -1,23 +1,53 @@ +#include <sys/types.h> +#include <sys/exec_elf.h> + #include <assert.h> #include <dlfcn.h> +#include <link.h> #include <stddef.h> +#include <string.h> -int -main() +static int +nonzero(char *s, size_t n) { - void *dso; - long *guardptr; - long guard; - extern long __guard[]; + size_t i; - dso = dlopen("ld.so", RTLD_LOCAL|RTLD_LAZY); - assert(dso != NULL); - guardptr = dlsym(dso, "__guard"); - assert(guardptr != NULL); - assert(guardptr != &__guard[0]); + for (i = 0; i < n; i++) + if (s[i] != 0) + return (1); + + return (0); +} + +static int foundldso = 0; + +static int +callback(struct dl_phdr_info *info, size_t size, void *cookie) +{ + int i; + int foundrandomize = 0; - guard = *guardptr; - assert(guard != 0); + assert(size >= sizeof(struct dl_phdr_info)); + if (strcmp(info->dlpi_name, "/usr/libexec/ld.so") != 0) + return (0); + foundldso = 1; + + for (i = 0; i < info->dlpi_phnum; i++) + if (info->dlpi_phdr[i].p_type == PT_OPENBSD_RANDOMIZE) { + foundrandomize = 1; + assert(nonzero((char *)(info->dlpi_phdr[i].p_vaddr + + info->dlpi_addr), info->dlpi_phdr[i].p_memsz)); + } + + assert(foundrandomize); + return (0); +} + +int +main() +{ + dl_iterate_phdr(callback, NULL); + assert(foundldso); return (0); } |