Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-21fa
project05b
Commits
ea98f436
Commit
ea98f436
authored
4 years ago
by
Caleb C. Sander
Browse files
Options
Download
Email Patches
Plain Diff
Update starter code
parent
2ec7b91f
master
No related merge requests found
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
Makefile
+9
-4
Makefile
include/cache_timing.h
+0
-0
include/cache_timing.h
include/exploit.h
+13
-0
include/exploit.h
include/index_guesser.h
+2
-0
include/index_guesser.h
include/recover_local_secret.h
+6
-0
include/recover_local_secret.h
include/recover_protected_local_secret.h
+6
-3
include/recover_protected_local_secret.h
include/util.h
+1
-1
include/util.h
lib/util.c
+2
-2
lib/util.c
src/cache_timing.c
+6
-5
src/cache_timing.c
src/exploit.c
+6
-12
src/exploit.c
src/index_guesser.c
+9
-5
src/index_guesser.c
src/recover_local_secret.c
+6
-4
src/recover_local_secret.c
src/recover_protected_local_secret.c
+6
-4
src/recover_protected_local_secret.c
with
72 additions
and
40 deletions
+72
-40
Makefile
View file @
ea98f436
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/%
This diff is collapsed.
Click to expand it.
include/cache_timing.h
0 → 100644
View file @
ea98f436
This diff is collapsed.
Click to expand it.
include/exploit.h
0 → 100644
View file @
ea98f436
#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
;
}
This diff is collapsed.
Click to expand it.
include/
stage2
.h
→
include/
index_guesser
.h
View file @
ea98f436
#include "util.h"
void
do_access
(
page_t
*
pages
)
{
force_read
(
pages
[
24
]);
}
This diff is collapsed.
Click to expand it.
include/
stage3
.h
→
include/
recover_local_secret
.h
View file @
ea98f436
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
];
}
This diff is collapsed.
Click to expand it.
include/
stage4
.h
→
include/
recover_protected_local_secret
.h
View file @
ea98f436
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
];
}
This diff is collapsed.
Click to expand it.
include/util.h
View file @
ea98f436
#ifndef _UTIL_H
#define _UTIL_H
#include <
std
int.h>
#include <int
types
.h>
#define PAGE_SIZE 4096
...
...
This diff is collapsed.
Click to expand it.
lib/util.c
View file @
ea98f436
#include <x86intrin.h>
#include "util.h"
#include <x86intrin.h>
void
force_read
(
const
void
*
address
)
{
*
(
volatile
uint8_t
*
)
address
;
}
...
...
This diff is collapsed.
Click to expand it.
src/cache_timing.c
View file @
ea98f436
#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
);
}
This diff is collapsed.
Click to expand it.
src/exploit.c
View file @
ea98f436
#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
()
{
}
This diff is collapsed.
Click to expand it.
src/index_guesser.c
View file @
ea98f436
#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
);
}
This diff is collapsed.
Click to expand it.
src/recover_local_secret.c
View file @
ea98f436
#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
)
{
...
...
This diff is collapsed.
Click to expand it.
src/recover_protected_local_secret.c
View file @
ea98f436
#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
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help