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

Simplify starter code

parent 45a94661
No related merge requests found
Showing with 36 additions and 51 deletions
+36 -51
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
const char SECRET[] = "CACHE";
char *SECRET = "CACHE";
static inline void cache_secret() {
for (size_t i = 0; i < strlen(SECRET); i++) {
*(volatile char *)(SECRET + i);
static inline void cache_secret(void) {
volatile const char *secret = SECRET;
while (*secret != '\0') {
secret++;
}
}
static inline char access_secret(size_t i) {
*(volatile char *)(0xFFFF|(i << 10));
*(volatile uint8_t *) (i << 16 | 0xFFFF);
return SECRET[i];
}
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
......
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define __USE_GNU
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "util.h"
static inline void *get_kernel_data_address() {
FILE *address_file;
address_file = fopen("/sys/kernel/kernel_data/address", "r");
if (address_file != NULL) {
uint64_t address;
if (fscanf(address_file, "%lx\n", &address) == 1) {
fclose(address_file);
return (void *) address;
}
fclose(address_file);
}
return 0;
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 make the necessary edits to do_access()
// TODO: Copy your code from the previous stage and make the necessary edits to do_access()
// Note that this code WILL NOT WORK on compute-cpu2. You must push it to gitlab to get it to run
// on one of the meltdown machines.
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
......
#include <stdlib.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
......@@ -22,8 +23,8 @@ static inline size_t guess_accessed_page(page_t *pages) {
return 0;
}
static inline void do_access(page_t *pages, size_t idx) {
// TODO: Implement me using force_read. I am a very short function.
static inline void do_access(page_t *pages, size_t secret_index) {
// TODO: Implement me using force_read(). I am a very short function.
}
int main() {
......
#include <inttypes.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define __USE_GNU
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "util.h"
#include "stage4.h"
extern char label[];
extern uint8_t label[];
const uint64_t MIN_CHOICE = 'A' - 1;
const uint64_t MAX_CHOICE = 'Z' + 1;
const uint64_t SECRET_LENGTH = 5;
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() {
return calloc(MAX_CHOICE, sizeof(page_t));
static inline page_t *init_pages(void) {
return calloc(MAX_CHOICE + 1, sizeof(page_t));
}
static inline void flush_all_pages(page_t *pages) {
// TODO: Copy me from the previous stage
}
......@@ -33,18 +28,17 @@ static inline size_t guess_accessed_page(page_t *pages) {
return 0;
}
static inline void do_access(page_t *probe_array, size_t idx) {
// TODO: Copy me from the previous stage.
static inline void do_access(page_t *pages, size_t secret_index) {
// TODO: Copy me from the previous stage.
// Don't forget to call cache_secret() to ensure the secret is in memory.
}
// TODO: Implement a SIGSEGV handler
int main() {
// TODO: Implement install your SIGSEGV handler
// TODO: Install your SIGSEGV handler
// TODO: For the remainder of the function, copy from the previous stage and edit the following:
// 1. Add asm volatile("label:") to the location you want the SIGSEGV handler to return to.
// 2. For each letter, it might take more than one attempt to get a valid guess. Throw all the logic in an inner loop.
......
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