Last active
April 23, 2020 17:21
-
-
Save kunigami/e61154d66fbd7b135827a87b5c8ba3b7 to your computer and use it in GitHub Desktop.
This file contains 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 <setjmp.h> | |
#include <signal.h> | |
#include <stdio.h> | |
#include <string.h> | |
void primer(char probe[256]) { | |
// Some specific address | |
int addr = 136322; | |
// This will throw segmentation fault, but we're "catching it" | |
char v = *(char *)addr; | |
// This will be executed spectulatively by the CPU | |
probe[v] = 1; | |
} | |
sigjmp_buf point; | |
// segfault signal handling | |
static void handler(int sig, siginfo_t *dont_care, void *dont_care_either) { | |
longjmp(point, 1); | |
} | |
int main() { | |
struct sigaction sa; | |
memset(&sa, 0, sizeof(sigaction)); | |
sigemptyset(&sa.sa_mask); | |
sa.sa_flags = SA_NODEFER; | |
sa.sa_sigaction = handler; | |
sigaction(SIGSEGV, &sa, NULL); | |
char probe[256]; | |
if (setjmp(point) == 0) { | |
primer(probe); | |
} else { | |
printf("Read chunks of probe and check which one is cached\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment