Skip to content

Commit 43ed0de

Browse files
pqcfoxalevy
authored andcommitted
tutorials: root_of_trust: add 'questionable' hardfault application for last submodule
1 parent bea4a28 commit 43ed0de

File tree

6 files changed

+183
-0
lines changed

6 files changed

+183
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Makefile for user application
2+
3+
# Specify this directory relative to the current application.
4+
TOCK_USERLAND_BASE_DIR = ../../../../
5+
6+
PACKAGE_NAME = org.tockos.tutorials.attestation.questionable
7+
8+
# Which files to compile.
9+
C_SRCS := $(wildcard *.c)
10+
11+
# Include userland master makefile. Contains rules and flags for actually
12+
# building the application.
13+
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Hardware Root of Trust (HWRoT) "Quesitonable" Kernel Attack Application
2+
-----------------------------------------------------------------------
3+
4+
This application implements a denial of service attack on the encryption service
5+
involving a "fault all applications" driver in the Hardware Root of Trust demo.
6+
7+
This is part of a tutorial which improves the encryption application in multiple
8+
steps and mounts multiple attacks on it. A writeup for the tutorial is available
9+
at https://book.tockos.org/.
10+
11+
Specific abilities of this version:
12+
13+
* Does NOT activate the "fault all applications driver"
14+
15+
This version of the application is essentially just a scaffold to build from
16+
while following the tutorial.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Hardware Root of Trust (HWRoT) Hardfault Driver Application
2+
//
3+
// When selected by the main screen HWRoT Demo application, calls a command
4+
// on a driver which is intended to hardfault all applications.
5+
6+
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
10+
#include <libtock/kernel/ipc.h>
11+
#include <libtock/tock.h>
12+
13+
#define LOG_WIDTH 32
14+
15+
bool started = false;
16+
bool log_done = false;
17+
size_t screen_service = -1;
18+
char log_buf[LOG_WIDTH] __attribute__((aligned(LOG_WIDTH)));
19+
20+
const char SCREEN_SERVICE_NAME[] = "org.tockos.tutorials.attestation.screen";
21+
22+
static void ipc_callback(__attribute__ ((unused)) int pid,
23+
__attribute__ ((unused)) int len,
24+
__attribute__ ((unused)) int arg2,
25+
__attribute__ ((unused)) void* ud) {
26+
started = true;
27+
}
28+
29+
static void log_done_callback(__attribute__ ((unused)) int pid,
30+
__attribute__ ((unused)) int len,
31+
__attribute__ ((unused)) int arg2,
32+
__attribute__ ((unused)) void* ud) {
33+
log_done = true;
34+
}
35+
36+
static void wait_for_start(void) {
37+
// Register an IPC callback and wait for it to be called by the
38+
// screen app based on the user's app selection.
39+
ipc_register_service_callback("org.tockos.tutorials.attestation.questionable", ipc_callback,
40+
NULL);
41+
yield_for(&started);
42+
}
43+
44+
static int setup_logging() {
45+
returncode_t ret;
46+
47+
// Find the PID of the screen logging service
48+
ret = ipc_discover(SCREEN_SERVICE_NAME, &screen_service);
49+
if (ret != RETURNCODE_SUCCESS) {
50+
printf("Screen logging service not found.\n");
51+
return ret;
52+
}
53+
54+
// Set up a callback and share so we can supply log messages
55+
// and know when they've been completely logged.
56+
ipc_register_client_callback(screen_service, log_done_callback, NULL);
57+
ipc_share(screen_service, log_buf, LOG_WIDTH);
58+
59+
return 0;
60+
}
61+
62+
static int log_to_screen(const char* message) {
63+
returncode_t ret;
64+
65+
// Copy up to the log buffer's size of the message, with room for a null byte.
66+
uint16_t len = strnlen(message, sizeof(log_buf) - 1);
67+
memcpy(log_buf, message, len);
68+
69+
// Add the null byte.
70+
log_buf[len] = '\0';
71+
72+
// Start the logging process.
73+
ret = ipc_notify_service(screen_service);
74+
if (ret != RETURNCODE_SUCCESS) {
75+
printf("Failed to request a log to screen.\n");
76+
return ret;
77+
}
78+
79+
// Wait for the log to complete.
80+
yield_for(&log_done);
81+
log_done = false;
82+
83+
return 0;
84+
}
85+
86+
int main(void) {
87+
returncode_t ret;
88+
89+
// Wait to receive the signal to start from the app selector.
90+
wait_for_start();
91+
92+
// Set up logging service.
93+
ret = setup_logging();
94+
if (ret < 0) {
95+
printf("ERROR: cannot set up logging\n");
96+
}
97+
98+
// Declare our intention to hardfault everything.
99+
ret = log_to_screen("Faulting all applications...\n");
100+
if (ret < 0) {
101+
printf("ERROR: cannot log to screen\n");
102+
}
103+
104+
// Bring everything down!
105+
syscall_return_t cr = command(0x99998, 1, 0, 0);
106+
if (cr.type != TOCK_SYSCALL_SUCCESS) {
107+
return tock_command_return_novalue_to_returncode(cr);
108+
}
109+
110+
// Note if the application is still running.
111+
ret = log_to_screen("This should never be seen!");
112+
if (ret < 0) {
113+
printf("ERROR: cannot log to screen\n");
114+
}
115+
116+
return 0;
117+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Makefile for user application
2+
3+
# Specify this directory relative to the current application.
4+
TOCK_USERLAND_BASE_DIR = ../../../../
5+
6+
PACKAGE_NAME = org.tockos.tutorials.attestation.questionable
7+
8+
# Which files to compile.
9+
C_SRCS := $(wildcard *.c)
10+
11+
# Include userland master makefile. Contains rules and flags for actually
12+
# building the application.
13+
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Hardware Root of Trust (HWRoT) "Quesitonable" Kernel Attack Application
2+
-----------------------------------------------------------------------
3+
4+
This application implements a denial of service attack on the encryption service
5+
involving a "fault all applications" driver in the Hardware Root of Trust demo.
6+
7+
This is part of a tutorial which improves the encryption application in multiple
8+
steps and mounts multiple attacks on it. A writeup for the tutorial is available
9+
at https://book.tockos.org/.
10+
11+
Specific abilities of this version:
12+
13+
* Does NOT activate the "fault all applications driver"
14+
15+
This version of the application is essentially just a scaffold to build from
16+
while following the tutorial.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Hardware Root of Trust (HWRoT) Hardfault Driver Application
2+
//
3+
// When selected by the main screen HWRoT Demo application, calls a command
4+
// on a driver which is intended to hardfault all applications.
5+
6+
int main(void) {
7+
return 0;
8+
}

0 commit comments

Comments
 (0)