Commit ea98f436 authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Update starter code

parent 2ec7b91f
No related merge requests found
Showing with 72 additions and 40 deletions
+72 -40
CC = gcc
CFLAGS = -O3 -Wall -Wextra -Iinclude
CC = clang
CFLAGS = -Iinclude -Wall -Wextra -O3 -g
all: bin/cache_timing bin/index_guesser bin/recover_local_secret bin/recover_protected_local_secret bin/exploit
bin/%: src/%.c lib/util.c
$(CC) $(CFLAGS) $^ -o $@
bin/%.o: lib/%.c
$(CC) $(CFLAGS) -c $^ -o $@
bin/%: src/%.c bin/util.o include/%.h
$(CC) $(CFLAGS) $(filter-out %.h,$^) -o $@
clean:
rm -f bin/*
.PRECIOUS: bin/%.o bin/%
#include <assert.h>
#include <stdio.h>
static inline void *get_kernel_data_address(void) {
FILE *address_file = fopen("/sys/kernel/kernel_data/address", "r");
assert(address_file != NULL);
size_t address;
int scanned = fscanf(address_file, "%zx\n", &address);
assert(scanned == 1);
fclose(address_file);
return (void *) address;
}
#include "util.h"
void do_access(page_t *pages) {
force_read(pages[24]);
}
const uint8_t SECRET[] = "CLOCK";
#include <inttypes.h>
#include <stddef.h>
static inline uint8_t access_secret(size_t i) {
return SECRET[i];
return "CLOCK"[i];
}
const uint8_t SECRET[] = "CACHE";
#include <inttypes.h>
#include <stddef.h>
const char SECRET[] = "CACHE";
static inline void cache_secret(void) {
volatile const uint8_t *secret = SECRET;
volatile const char *secret = SECRET;
while (*secret != '\0') {
secret++;
}
}
static inline uint8_t access_secret(size_t i) {
*(volatile uint8_t *) (i << 16 | 0xFFFF);
*(volatile uint8_t *) NULL;
return SECRET[i];
}
#ifndef _UTIL_H
#define _UTIL_H
#include <stdint.h>
#include <inttypes.h>
#define PAGE_SIZE 4096
......
#include <x86intrin.h>
#include "util.h"
#include <x86intrin.h>
void force_read(const void *address) {
*(volatile uint8_t *) address;
}
......
#include <inttypes.h>
#include "cache_timing.h"
#include <stdio.h>
#include <stdlib.h>
......@@ -7,11 +8,11 @@
const size_t REPEATS = 100000;
int main() {
uint64_t min_miss = UINT64_MAX;
uint64_t max_hit = 0;
uint64_t sum_miss = 0;
uint64_t sum_hit = 0;
// TODO: Implement the algorithm as described in the specification here
printf("min miss = %" PRIu64 "\n", min_miss);
printf("max hit = %" PRIu64 "\n", max_hit);
printf("average miss = %" PRIu64 "\n", sum_miss / REPEATS);
printf("average hit = %" PRIu64 "\n", sum_hit / REPEATS);
}
#include "exploit.h"
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -8,18 +9,11 @@
#include "util.h"
static inline void *get_kernel_data_address(void) {
FILE *address_file = fopen("/sys/kernel/kernel_data/address", "r");
assert(address_file != NULL);
size_t address;
int scanned = fscanf(address_file, "%zx\n", &address);
assert(scanned == 1);
fclose(address_file);
return (void *) address;
}
/* TODO: Copy your code from the previous stage and edit do_access().
* Note that this code WILL NOT WORK on labradoodle.
* You must push it to GitLab to run it on one of the meltdown machines.
*/
int main() {
}
#include <inttypes.h>
#include "index_guesser.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
#include "stage2.h"
const size_t MIN_CHOICE = 1;
const size_t MAX_CHOICE = 255;
static inline page_t *init_pages(void) {
return calloc(MAX_CHOICE + 1, sizeof(page_t));
page_t *pages = calloc(UINT8_MAX + 1, PAGE_SIZE);
assert(pages != NULL);
return pages;
}
static inline void flush_all_pages(page_t *pages) {
......@@ -19,7 +21,6 @@ static inline void flush_all_pages(page_t *pages) {
static inline size_t guess_accessed_page(page_t *pages) {
// TODO: Implement me!
return 0;
}
......@@ -33,6 +34,9 @@ int main() {
size_t guess = guess_accessed_page(pages);
if (guess > 0) {
printf("%zu\n", guess);
} else {
printf("No page was accessed\n");
}
free(pages);
}
#include <inttypes.h>
#include "recover_local_secret.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
#include "stage3.h"
const size_t MIN_CHOICE = 'A' - 1;
const size_t MAX_CHOICE = 'Z' + 1;
const size_t SECRET_LENGTH = 5;
static inline page_t *init_pages(void) {
return calloc(MAX_CHOICE + 1, sizeof(page_t));
page_t *pages = calloc(UINT8_MAX + 1, PAGE_SIZE);
assert(pages != NULL);
return pages;
}
static inline void flush_all_pages(page_t *pages) {
......
#include <inttypes.h>
#include "recover_protected_local_secret.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -7,8 +9,6 @@
#include "util.h"
#include "stage4.h"
extern uint8_t label[];
const size_t MIN_CHOICE = 'A' - 1;
......@@ -16,7 +16,9 @@ const size_t MAX_CHOICE = 'Z' + 1;
const size_t SECRET_LENGTH = 5;
static inline page_t *init_pages(void) {
return calloc(MAX_CHOICE + 1, sizeof(page_t));
page_t *pages = calloc(UINT8_MAX + 1, PAGE_SIZE);
assert(pages != NULL);
return pages;
}
static inline void flush_all_pages(page_t *pages) {
......
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