Last active
March 23, 2022 17:43
-
-
Save moyix/f2e101348209ddeb7eba903147a867aa to your computer and use it in GitHub Desktop.
Example of using a constructor to set up the shadow callstack and assign gs appropriately
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 <stdio.h> | |
#include <asm/prctl.h> | |
#include <sys/prctl.h> | |
#include <stdlib.h> | |
// Compile with: clang-8 -fsanitize=shadow-call-stack shadowstack.c -o shadowstack | |
int arch_prctl(int code, unsigned long *addr); | |
void __attribute__ ((constructor)) __attribute__((no_sanitize("shadow-call-stack"))) setupgs() | |
{ | |
void *shadow = malloc(16384); | |
arch_prctl(ARCH_SET_GS, shadow); | |
} | |
int bar() { | |
return 42; | |
} | |
int foo() { | |
return bar() + 1; | |
} | |
int main(int argc, char **argv) { | |
printf("Hello, world %d!\n", foo()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment