Skip to content

Instantly share code, notes, and snippets.

@prattmic

prattmic/vvar.c Secret

Created December 3, 2020 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prattmic/a9816731294715426d7b85eb091d0102 to your computer and use it in GitHub Desktop.
Save prattmic/a9816731294715426d7b85eb091d0102 to your computer and use it in GitHub Desktop.
#include <stdint.h>
#include <stdio.h>
#include <sys/auxv.h>
int main(int argc, char** argv, char** envv) {
uintptr_t vdso_base = getauxval(AT_SYSINFO_EHDR);
vdso_base &= ~0xfff; // round down;
printf("VDSO base: %#llx\n", vdso_base);
// Linux 5.6+ have 4 pages of VVAR.
uintptr_t vvar_offset = 4 * 4096;
// Linux 4.12+ have 3 pages of VVAR.
//vvar_offset = 3 * 4096;
// Linux 4.7+ have 2 pages of VVAR.
//vvar_offset = 2 * 4096;
// Earlier has 1 page.
//vvar_offset = 1 * 4096;
uintptr_t vvar_base = vdso_base - vvar_offset;
// Dump first 512 bytes.
for (int i = 0; i < 512; i += 4) {
uintptr_t addr = vvar_base + i;
if (i % 16 == 0) {
printf("\n%#llx:", addr);
}
printf(" 0x%08x", *(uint32_t*)addr);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment