-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix broken sigining of EXT2 rootfs #1456
Merged
+128
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
TOP=$(abspath ../..) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test should live in the tests/myst directory with the other signing tests |
||
include $(TOP)/defs.mak | ||
|
||
APPDIR = appdir | ||
CFLAGS = -fPIC | ||
LDFLAGS = -Wl,-rpath=$(MUSL_LIB) | ||
|
||
all: | ||
$(MAKE) myst | ||
$(MAKE) rootfs | ||
|
||
rootfs: hello.c | ||
mkdir -p $(APPDIR)/bin | ||
$(CC) $(CFLAGS) -o $(APPDIR)/bin/hello hello.c $(LDFLAGS) | ||
$(MYST) mkext2 $(APPDIR) rootfs | ||
|
||
OPTS = | ||
|
||
ifdef STRACE | ||
OPTS += --strace | ||
endif | ||
|
||
ifdef PERF | ||
OPTS += --perf | ||
endif | ||
|
||
OPTS += --thread-stack-size=1048576 | ||
|
||
tests: all | ||
$(RUNTEST) $(MYST_EXEC) rootfs /bin/hello $(OPTS) | ||
$(MAKE) sign | ||
$(MAKE) verify | ||
$(MAKE) fail | ||
@ echo "=== passed all tests" | ||
|
||
private.pem: | ||
openssl genrsa -out private.pem -3 3072 | ||
|
||
sign: private.pem | ||
$(MYST) fssig --roothash rootfs > roothash | ||
rm -rf hello.signed | ||
$(MYST) sign-sgx rootfs private.pem config.json --roothash=roothash | ||
|
||
verify: | ||
( cd hello.signed; ./bin/myst exec-sgx rootfs /bin/hello $(OPTS) ) | ||
|
||
myst: | ||
$(MAKE) -C $(TOP)/tools/myst | ||
|
||
clean: | ||
rm -rf $(APPDIR) rootfs export ramfs hello.signed roothash private.pem | ||
|
||
## | ||
## Negative test to verify that hacking rootfs fails loading. | ||
## | ||
fail: | ||
$(MAKE) sign | ||
$(MYST) mkext2 --force $(APPDIR) hello.signed/rootfs | ||
$(MAKE) verify 2> /dev/null; test $$? -eq 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sign | ||
==== | ||
|
||
This test verifies that a simple Mystikos application can be signed and | ||
executed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"version": "0.1", | ||
"Debug": 1, | ||
"ProductID": 1, | ||
"SecurityVersion": 1, | ||
"MemorySize": "40m", | ||
"ThreadStackSize": "16m", | ||
"ApplicationPath": "/bin/hello", | ||
"ApplicationParameters": [], | ||
"HostApplicationParameters": false, | ||
"EnvironmentVariables": [], | ||
"HostEnvironmentVariables": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include <assert.h> | ||
#include <limits.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
int main(int argc, const char* argv[]) | ||
{ | ||
printf("Hello!\n"); | ||
printf("=== passed test (%s)\n", argv[0]); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
#include <myst/file.h> | ||
#include <myst/strings.h> | ||
#include <myst/types.h> | ||
#include <myst/cpio.h> | ||
#include <openenclave/host.h> | ||
#include "../config.h" | ||
#include "myst_u.h" | ||
|
@@ -67,6 +68,11 @@ and <options> are one of:\n\ | |
--outdir <path> -- optional output directory path. If not\n\ | ||
specified goes into the configurations\n\ | ||
<appdir>.signed directpry\n\ | ||
--roothash=<filename> -- add the root hash given by filename to\n\ | ||
the image when siging, which permits\n\ | ||
mounting of EXT2 root file systems.\n\ | ||
The file argument contains an ASCII root\n\ | ||
hash.\n\ | ||
\n\ | ||
" | ||
|
||
|
@@ -293,6 +299,7 @@ int _sign(int argc, const char* argv[]) | |
const char* signing_engine_name = NULL; | ||
const char* signing_engine_path = NULL; | ||
myst_buf_t roothash_buf = MYST_BUF_INITIALIZER; | ||
char rootfs_path[] = "/tmp/mystXXXXXX"; | ||
|
||
// We are in the right operation, right? | ||
assert( | ||
|
@@ -341,6 +348,7 @@ int _sign(int argc, const char* argv[]) | |
|
||
const char* program_file = get_program_file(); | ||
const char* rootfs_file = argv[2]; | ||
const char* rootfs = rootfs_file; | ||
const char* pem_file = argv[3]; | ||
const char* config_file = argv[4]; | ||
const char* target = NULL; // Extracted from config file | ||
|
@@ -440,10 +448,28 @@ int _sign(int argc, const char* argv[]) | |
assert(myst_validate_file_path(program_file)); | ||
assert(myst_validate_file_path(temp_oeconfig_file)); | ||
|
||
/* if not a CPIO archive, create a zero-filled file with one page */ | ||
if (myst_cpio_test(rootfs) == -ENOTSUP) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check |
||
{ | ||
int fd; | ||
uint8_t page[PAGE_SIZE]; | ||
|
||
if ((fd = mkstemp(rootfs_path)) < 0) | ||
_err("failed to create temporary file"); | ||
|
||
memset(page, 0, sizeof(page)); | ||
|
||
if (write(fd, page, sizeof(page)) != sizeof(page)) | ||
_err("failed to create file"); | ||
|
||
close(fd); | ||
rootfs = rootfs_path; | ||
} | ||
|
||
// Setup all the regions | ||
if ((details = create_region_details_from_files( | ||
target, | ||
rootfs_file, | ||
rootfs, | ||
pubkeys_opt, | ||
roothashes_opt, | ||
config_file, | ||
|
@@ -453,6 +479,10 @@ int _sign(int argc, const char* argv[]) | |
_err("Creating region data failed."); | ||
} | ||
|
||
// Remove temporary file: | ||
if (rootfs == rootfs_path) | ||
unlink(rootfs); | ||
|
||
if (copy_files_to_signing_directory( | ||
sign_dir, | ||
program_file, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does it mean when both roothash and appdir are present in args? Should this be prevented(we should not change what we have, just wondering..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TEE_aware sample also takes appdir as a command line arg