Skip to content

Commit 4f18914

Browse files
authored
Merge pull request #524 from pqcfox/root-of-trust-tutorial-hardfault-app
tutorials: root_of_trust: Add App for Last Submodule of Root of Trust Tutorial
2 parents 27c1491 + d81ed02 commit 4f18914

File tree

6 files changed

+180
-0
lines changed

6 files changed

+180
-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: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
#include <string.h>
10+
11+
#include <libtock/kernel/ipc.h>
12+
#include <libtock/tock.h>
13+
14+
#define LOG_WIDTH 32
15+
16+
bool started = false;
17+
bool log_done = false;
18+
size_t screen_service = -1;
19+
char log_buf[LOG_WIDTH] __attribute__((aligned(LOG_WIDTH)));
20+
21+
const char SCREEN_SERVICE_NAME[] = "org.tockos.tutorials.attestation.screen";
22+
23+
static void ipc_callback(__attribute__ ((unused)) int pid,
24+
__attribute__ ((unused)) int len,
25+
__attribute__ ((unused)) int arg2,
26+
__attribute__ ((unused)) void* ud) {
27+
started = true;
28+
}
29+
30+
static void log_done_callback(__attribute__ ((unused)) int pid,
31+
__attribute__ ((unused)) int len,
32+
__attribute__ ((unused)) int arg2,
33+
__attribute__ ((unused)) void* ud) {
34+
log_done = true;
35+
}
36+
37+
static void wait_for_start(void) {
38+
// Register an IPC callback and wait for it to be called by the
39+
// screen app based on the user's app selection.
40+
ipc_register_service_callback("org.tockos.tutorials.attestation.questionable", ipc_callback,
41+
NULL);
42+
yield_for(&started);
43+
}
44+
45+
static int setup_logging() {
46+
returncode_t ret;
47+
48+
// Find the PID of the screen logging service
49+
ret = ipc_discover(SCREEN_SERVICE_NAME, &screen_service);
50+
if (ret != RETURNCODE_SUCCESS) {
51+
printf("Screen logging service not found.\n");
52+
return ret;
53+
}
54+
55+
// Set up a callback and share so we can supply log messages
56+
// and know when they've been completely logged.
57+
ipc_register_client_callback(screen_service, log_done_callback, NULL);
58+
ipc_share(screen_service, log_buf, LOG_WIDTH);
59+
60+
return 0;
61+
}
62+
63+
static int log_to_screen(const char* message) {
64+
returncode_t ret;
65+
66+
// Load the log buffer with our message
67+
strlcpy(log_buf, message, LOG_WIDTH);
68+
69+
// Start the logging process.
70+
ret = ipc_notify_service(screen_service);
71+
if (ret != RETURNCODE_SUCCESS) {
72+
printf("Failed to request a log to screen.\n");
73+
return ret;
74+
}
75+
76+
// Wait for the log to complete.
77+
yield_for(&log_done);
78+
log_done = false;
79+
80+
return 0;
81+
}
82+
83+
int main(void) {
84+
returncode_t ret;
85+
86+
// Wait to receive the signal to start from the app selector.
87+
wait_for_start();
88+
89+
// Set up logging service.
90+
ret = setup_logging();
91+
if (ret < 0) {
92+
printf("ERROR: cannot set up logging\n");
93+
}
94+
95+
// Declare our intention to hardfault everything.
96+
ret = log_to_screen("Faulting all applications...\n");
97+
if (ret < 0) {
98+
printf("ERROR: cannot log to screen\n");
99+
}
100+
101+
// Bring everything down!
102+
syscall_return_t cr = command(0x99998, 1, 0, 0);
103+
if (cr.type != TOCK_SYSCALL_SUCCESS) {
104+
return tock_command_return_novalue_to_returncode(cr);
105+
}
106+
107+
// Note if the application is still running.
108+
ret = log_to_screen("This should never be seen!");
109+
if (ret < 0) {
110+
printf("ERROR: cannot log to screen\n");
111+
}
112+
113+
return 0;
114+
}
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)