Created
April 26, 2017 06:09
-
-
Save machinaut/a08b581c921775263cf0e20ccc974cbd to your computer and use it in GitHub Desktop.
drop vdso
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <elf.h> | |
#include <linux/auxvec.h> | |
#include <stdio.h> | |
#include <sys/syscall.h> | |
#include <time.h> | |
void drop_vdso(char *envp[]) { | |
Elf64_auxv_t *auxv, *ehdr, *last; | |
while(*envp++ != NULL); // skip the environment vars | |
for (auxv = (Elf64_auxv_t*)envp; auxv->a_type != AT_NULL; auxv++) { | |
if (auxv->a_type == AT_SYSINFO_EHDR) { | |
ehdr = auxv; | |
} else { | |
last = auxv; | |
} | |
} | |
*ehdr = *last; // replace the EHDR with the last non-ehdr entry | |
last->a_type = AT_NULL; // drop the last one off the bottom | |
} | |
__attribute__ ((constructor)) | |
void init(int argc, char *argv[], char *envp[]) { | |
drop_vdso(envp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty much. It's arch, which AFAIK is a slightly patched mainline.
That sounds fun, but I think I figured it out (see below). I'm in PST too.
no error, it just doesn't appear to drop vdsoI figured it out. I didn't realize the importance of
__attribute__((constructor))
and was just calling drop_vdso as the first line in main(), which simply doesn't drop vdso. Then, I was getting segfaults because I added__attribute__((constructor))
, and ended up callingdrop_vdso
twice *facepalm*. That was all in a C project I whipped up to test your exact code, but I'm trying to remove vdso in Rust, which doesn't have any__attribute__((constructor))
-like mechanisms to run code before main (or before glibc finds vdso). Luckily, it seems I can use a dlopen trick to overwrite the symbols from vdso.Unfortunately this trick fails when compiled with statically-linked musl because it doesn't support dlopen. I'd rather musl works, so I'm still in search of a better trick.Musl doesn't use vdso!