Commit fa187188 authored by Adam Blank's avatar Adam Blank
Browse files

adds temporary partial solutions

parent da35a548
Showing with 290 additions and 0 deletions
+290 -0
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "cache.h"
#include "util.h"
void do_access(page_t *pages) {
(void)*(volatile char *)&pages[11];
}
#include <inttypes.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cache.h"
#include "util.h"
#define MAX_CHOICE 256
void do_access(page_t *pages);
int main() {
page_t *pages = malloc(MAX_CHOICE * sizeof(page_t));
for (int i = 0; i < MAX_CHOICE; i++) {
memset(pages[i], 1, sizeof(page_t));
flush_cache_line(&pages[i]);
}
do_access(pages);
uint64_t miss = 0;
uint64_t hit = 0;
for (int i = 0; i < MAX_CHOICE; i++) {
uint64_t miss = time_read(&pages[i]);
uint64_t hit = time_read(&pages[i]);
if (miss < 2 * hit) {
printf("I guess %d\n", i);
}
}
}
#include <inttypes.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cache.h"
#include "util.h"
#define MAX_CHOICE 256
void do_access(page_t *pages);
int main() {
page_t *pages = malloc(MAX_CHOICE * sizeof(page_t));
for (int i = 0; i < MAX_CHOICE; i++) {
memset(pages[i], 1, sizeof(page_t));
flush_cache_line(&pages[i]);
}
do_access(pages);
uint64_t miss = 0;
uint64_t hit = 0;
for (int i = 0; i < MAX_CHOICE; i++) {
uint64_t miss = time_read(&pages[i]);
uint64_t hit = time_read(&pages[i]);
if (miss < 2 * hit) {
printf("I guess %d\n", i);
}
}
}
#include <stdlib.h>
#include <stdio.h>
volatile size_t get_kernel_data_length() {
FILE* kernel_data_length = fopen("/sys/kernel/kernel_data/length", "rt");
volatile size_t length = 0;
fscanf(kernel_data_length, "%zu\n", &length);
fclose(kernel_data_length);
return length;
}
char *get_kernel_data_address() {
FILE* kernel_data_address = fopen("/sys/kernel/kernel_data/address", "rt");
char *addr = NULL;
fscanf(kernel_data_address, "%p\n", &addr);
fclose(kernel_data_address);
return addr;
}
int main() {
size_t addr = 0xffffffffc0105070;
volatile size_t len = get_kernel_data_length();
printf("secret is at %p with length %zu\n", addr, len);
printf("secret is %s\n", addr);
}
#include <inttypes.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cache.h"
#include "util.h"
#define REPEATS 10000
int main() {
page_t *page = malloc(sizeof(page_t));
uint64_t miss = 0;
uint64_t hit = 0;
for (int i = 0; i < 100; i++) {
flush_cache_line(&page);
miss += time_read(page);
hit += time_read(page);
printf("miss = %llu, hit = %llu\n", miss/(i+1), hit/(i + 1));
}
}
#include <inttypes.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cache.h"
#include "util.h"
#define REPEATS 10000
const char *secret = "Don't read me directly!";
char run_trial(oracle_array_t *pages) {
uint64_t latencies[NUM_CHAR_VALUES];
double avg = 0;
for (int i = 0; i < NUM_CHAR_VALUES; i++) {
uint64_t read = time_read(&(pages->oracles[i]));
latencies[i] = read;
avg = (avg*i+read)/((double)i+1);
}
int min_idx = 0;
for (int i = 0; i < NUM_CHAR_VALUES; i++) {
if (latencies[i] < latencies[min_idx]) {
min_idx = i;
}
}
int snd_idx = min_idx == 0 ? 1 : 0;
for (int i = 0; i < NUM_CHAR_VALUES; i++) {
if (i != min_idx && latencies[i] < latencies[snd_idx]) {
snd_idx = i;
}
}
return 2*latencies[min_idx] < latencies[snd_idx] ? min_idx : 0;
}
int main() {
volatile size_t length = strlen(secret);
uint64_t counts[NUM_CHAR_VALUES];
oracle_array_t *pages = malloc(sizeof(oracle_array_t));
for (int i = 0; i < length; i++) {
for (int i = 0; i < NUM_CHAR_VALUES; i++) {
counts[i] = 0;
}
for (int t = 0; t < REPEATS; t++) {
flush_oracle(pages);
force_read(&(pages->oracles[secret[i]]));
char c = run_trial(pages);
if (c) {
counts[c]++;
}
}
int max_idx = 0;
int snd_idx = 0;
for (int j = 0; j < NUM_CHAR_VALUES; j++) {
if (counts[max_idx] < counts[j]) {
snd_idx = max_idx;
max_idx = j;
}
}
printf("%c", counts[max_idx] > 2*counts[snd_idx] ? max_idx : '?');
fflush(stdout);
}
printf("\n");
}
#include <inttypes.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cache.h"
#include "util.h"
#define REPEATS 10000
const char *secret = "Don't read me directly!";
char run_trial(oracle_array_t *pages) {
uint64_t latencies[NUM_CHAR_VALUES];
double avg = 0;
for (int i = 0; i < NUM_CHAR_VALUES; i++) {
uint64_t read = time_read(&(pages->oracles[i]));
latencies[i] = read;
avg = (avg*i+read)/((double)i+1);
}
int min_idx = 0;
for (int i = 0; i < NUM_CHAR_VALUES; i++) {
if (latencies[i] < latencies[min_idx]) {
min_idx = i;
}
}
int snd_idx = min_idx == 0 ? 1 : 0;
for (int i = 0; i < NUM_CHAR_VALUES; i++) {
if (i != min_idx && latencies[i] < latencies[snd_idx]) {
snd_idx = i;
}
}
return 2*latencies[min_idx] < latencies[snd_idx] ? min_idx : 0;
}
int main() {
volatile size_t length = strlen(secret);
uint64_t counts[NUM_CHAR_VALUES];
oracle_array_t *pages = malloc(sizeof(oracle_array_t));
for (int i = 0; i < length; i++) {
for (int i = 0; i < NUM_CHAR_VALUES; i++) {
counts[i] = 0;
}
for (int t = 0; t < REPEATS; t++) {
flush_oracle(pages);
force_read(&(pages->oracles[secret[i]]));
char c = run_trial(pages);
if (c) {
counts[c]++;
}
}
int max_idx = 0;
int snd_idx = 0;
for (int j = 0; j < NUM_CHAR_VALUES; j++) {
if (counts[max_idx] < counts[j]) {
snd_idx = max_idx;
max_idx = j;
}
}
printf("%c", counts[max_idx] > 2*counts[snd_idx] ? max_idx : '?');
fflush(stdout);
}
printf("\n");
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "cache.h"
#include "util.h"
void do_access(page_t *pages) {
(void)*(volatile char *)&pages[11];
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment