-
Notifications
You must be signed in to change notification settings - Fork 1
[RISCV] Added TPM DRoT support with Tychools verification #96
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
Open
alex-douk
wants to merge
26
commits into
main
Choose a base branch
from
alex-rv-drot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a0679fe
Initial commit - RV setup works!
papa b72b110
Added TPM fields in the EnclaveReport struct
neeluk7 aea3c5b
Added the rest of Tyche-side support for TPM attestation
neeluk7 1b5d35c
Modified Tyche calls to support TPM attestation
neeluk7 1bbc3dd
Sample application showing TPM attestation verification
neeluk7 4ef675f
Forgot build tools for RoT enclave
neeluk7 6d3bce2
Added TPM signature verification on Tychools's side
neeluk7 c1dd64e
Compile successful after rebase
neeluk7 6e64adf
Added modular tags for x86 compilation and a tpm-riscv comman in the …
neeluk7 661be47
Added RISC-V launch with TPM support. Added TPM attestation to Manifest
neeluk7 a91c69a
Added the rest of Tyche-side support for TPM attestation
neeluk7 8b98d9e
Added TPM signature verification on Tychools's side
neeluk7 32af8e1
Added modular tags for x86 compilation and a tpm-riscv comman in the …
neeluk7 0fd444d
Examples work after rebase. RoT example needs to be fixed.
neeluk7 f5846ea
Fixed rot_enclave example to match simple_enclave behavior
neeluk7 db093d6
Removed unused dependency
neeluk7 b41021c
Modularized if-else ladder into another file for RISC-V attestation
neeluk7 04e7281
Fixed justfile
neeluk7 9e78954
Fixed call number in rot_enclave example
neeluk7 5cdbc5e
Passed TPM information from OSBI to Tyche
neeluk7 3d34f22
Added changes after rebase
neeluk7 a534797
Added to allow unused_imports to bypass the static mutable warning
neeluk7 8372d8e
Fix memory leak on x86_64 patforms
CharlyCst 994a067
Fixing compilation error for linux
aghosn 8aed19b
Changes made according to PR review comments
neeluk7 40c40a4
Added output to file for PCR digest check
neeluk7 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 hidden or 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 hidden or 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,3 @@ | ||
| make ARCH=riscv ubuntu_mount || exit | ||
| make ARCH=riscv update_disk | ||
| make ARCH=riscv ubuntu_umount |
This file contains hidden or 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,4 @@ | ||
| app | ||
| enclave | ||
| simple_enclave | ||
| enclave_iso |
139 changes: 139 additions & 0 deletions
139
C/libraries/sdktyche/example/enclave_rot_riscv/Makefile
This file contains hidden or 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,139 @@ | ||
| all: rot_enclave | ||
|
|
||
| GCC ?=gcc | ||
| KVM ?=1 | ||
|
|
||
| ifeq ($(ARCH), riscv) | ||
| GCC = riscv64-unknown-linux-gnu-gcc | ||
| KVM = 0 | ||
| endif | ||
|
|
||
| ifeq ($(KVM), 1) | ||
| LOADER_BACKEND = -DRUN_WITH_KVM=1 | ||
| endif | ||
|
|
||
|
|
||
| ## ————————————————————————————————— Paths —————————————————————————————————— ## | ||
| LIB_PATH=../../../ | ||
| LIB_DRIVER=../../../../../linux/drivers/tyche/libraries/ | ||
| DRIVERS_PATH=../../../../../linux/drivers/ | ||
| LINKER_SCRIPT=../../../../../configs/riscv-linker-script-domain.x | ||
|
|
||
| ## ——————————————————————————————— Libraries ———————————————————————————————— ## | ||
| SDK=$(LIB_PATH)/sdktyche | ||
| DLL_LIB= $(LIB_DRIVER)/dll | ||
| CAPA_LIB=$(LIB_DRIVER)/capabilities | ||
| COMMON_LIB=$(LIB_DRIVER)/common | ||
| ELF64=$(LIB_PATH)/elf64 | ||
| PTS=$(LIB_PATH)/pts | ||
| DRIVER=$(DRIVERS_PATH)/tyche | ||
| CONTALLOC=$(DRIVERS_PATH)/contalloc | ||
|
|
||
| ## ——————————————————————— Untrusted code and headers ——————————————————————— ## | ||
| CODE_UNTRUSTED=$(wildcard untrusted/*.c) | ||
| HDRS_UNTRUSTED=$(wildcard include/*.h) | ||
|
|
||
| ## ———————————————————————— Trusted code and headers ———————————————————————— ## | ||
| CODE_TRUSTED=$(wildcard trusted/*.c) | ||
| HDRS_TRUSTED=$(wildcard include/*.h) | ||
|
|
||
| ## ———————————————————————— Runtime code and headers ———————————————————————— ## | ||
| ifeq ($(ARCH), x86) | ||
| CODE_RUNTIME = $(wildcard $(SDK)/runtime/*.c) $(wildcard $(SDK)/runtime/asm.S) | ||
| HDRS_RUNTIME = $(wildcard $(SDK)/include/*.h) | ||
| else ifeq ($(ARCH), riscv) | ||
| CODE_RUNTIME = $(wildcard $(SDK)/runtime/*.c) $(wildcard $(SDK)/runtime/riscv_asm.S) | ||
| HDRS_RUNTIME = $(wildcard $(SDK)/include/*.h) | ||
| endif | ||
| # ———————————————————————— Code capabilities library ————————————————————————— # | ||
| CODE_CAPAS=$(wildcard $(CAPA_LIB)/src/*.c) | ||
| ## ———————————————————————— Loader code and headers ————————————————————————— ## | ||
| CODE_LOADER=$(wildcard $(SDK)/loader/*.c) $(wildcard $(SDK)/loader/*.S) | ||
| HDRS_LOADER=$(wildcard $(SDK)/include/*.h) | ||
|
|
||
| ifeq ($(KVM), 1) | ||
| CODE_LOADER+=$(SDK)/loader/backends/back_kvm.c | ||
| else | ||
| CODE_LOADER+=$(SDK)/loader/backends/back_tyche.c | ||
| endif | ||
|
|
||
| ## ————————————————————————— ELF64 code and headers ————————————————————————— ## | ||
| CODE_ELF64=$(wildcard $(ELF64)/src/*.c) | ||
| HDRS_ELF64=$(wildcard $(ELF64)/include/*.h) | ||
|
|
||
| ## —————————————————————— Page table code and headers ——————————————————————— ## | ||
| CODE_PTS=$(wildcard $(PTS)/src/*.c) | ||
| HDRS_PTS=$(wildcard $(PTS)/include/*.h) | ||
|
|
||
| ## —————————————————————— Application code and headers —————————————————————— ## | ||
| CODE_APP=$(CODE_ELF64) $(CODE_PTS) $(CODE_LOADER) $(CODE_UNTRUSTED) | ||
| HDRS_APP=$(HDRS_ELF64) $(HDRS_PTS) $(HDRS_LOADER) $(HDRS_UNTRUSTED) | ||
|
|
||
| ## ———————————————————————— Enclave code and headers ———————————————————————— ## | ||
| CODE_ENCLAVE=$(CODE_RUNTIME) $(CODE_TRUSTED) $(CODE_CAPAS) | ||
| HDRS_ENCLAVE=$(HDRS_RUNTIME) $(HDRS_TRUSTED) | ||
|
|
||
| ## ———————————————————————————————— Includes ———————————————————————————————— ## | ||
| COMMON_INCLUDES = -Iinclude -I$(CAPA_LIB)/include -I$(COMMON_LIB)/include -I$(DLL_LIB)/include -I$(SDK)/include | ||
| APP_INCLUDES = $(COMMON_INCLUDES) -I$(ELF64)/include -I$(PTS)/include -I$(DRIVER)/include | ||
|
|
||
| ifeq ($(KVM), 1) | ||
| APP_INCLUDES+=-I$(CONTALLOC)/include | ||
| endif | ||
|
|
||
| ifeq ($(ARCH), riscv) | ||
| APP_INCLUDES+=-pthread | ||
| endif | ||
|
|
||
| ## ————————————————————— Configuration for the install —————————————————————— ## | ||
| ifeq ($(ARCH), riscv) | ||
| DISK_PATH ?= /tmp/ubuntu_riscv_mount/tyche/programs | ||
| endif | ||
|
|
||
| TYCHOOLS_PATH ?= ../../../../../crates/tychools/ | ||
|
|
||
| ## ———————————————————————————————— Targets ————————————————————————————————— ## | ||
|
|
||
| app: $(CODE_APP) $(HDRS_APP) | ||
| $(GCC) -DTYCHE_USER_SPACE=1 $(LOADER_BACKEND) -g $(APP_INCLUDES) -o $@ $(CODE_APP) | ||
|
|
||
|
|
||
| ifeq ($(ARCH), riscv) | ||
|
|
||
| enclave: $(CODE_ENCLAVE) $(HDRS_ENCLAVE) | ||
| echo "riscv" | ||
| echo $(GCC) | ||
| $(GCC) -DTYCHE_USER_SPACE=2 -DTYCHE_ENCLAVE=1 -DCONFIG_RISCV=1 -g $(COMMON_INCLUDES) -nostdlib -static -o $@ $(CODE_ENCLAVE) -Wl,--section-start=.data=0x16000 | ||
|
|
||
| rot_iso: app enclave | ||
| cargo -C $(TYCHOOLS_PATH) install --path . --locked | ||
| tychools instrument -s manifests/rot_iso.json --riscv-enabled | ||
| chmod +x rot_iso | ||
| rm app enclave | ||
|
|
||
| rot_enclave: app enclave | ||
| cargo -Z unstable-options -C $(TYCHOOLS_PATH) install --path . --locked | ||
| tychools instrument -s manifests/default.json --riscv-enabled | ||
| chmod +x rot_enclave | ||
| rm app enclave | ||
|
|
||
| attestation_enclave: app enclave | ||
| echo "Building attestation enclave for RISCV with TPM RoT" | ||
| cargo -Z unstable-options -C $(TYCHOOLS_PATH) install --path . --locked | ||
| tychools instrument -s manifests/default.json --riscv-enabled | ||
| chmod +x rot_enclave | ||
| tychools instrument -s manifests/rot_iso.json --riscv-enabled | ||
| chmod +x rot_iso | ||
| rm app enclave | ||
| endif | ||
|
|
||
| install_disk: all | ||
| mkdir -p $(DISK_PATH) | ||
| cp -t $(DISK_PATH) rot_enclave | ||
| cp -t $(DISK_PATH) rot_iso | ||
|
|
||
| .PHONY: clean | ||
|
|
||
| clean: | ||
| rm rot_enclave | ||
| rm rot_iso |
This file contains hidden or 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,35 @@ | ||
| # Simple Enclave Example | ||
|
|
||
|
|
||
| ## How to run | ||
|
|
||
| This application runs by default or if you type: | ||
|
|
||
| ``` | ||
| ./simple_enclave | ||
| ``` | ||
|
|
||
| ### What it does | ||
|
|
||
| The application loads the enclave and performs two calls to it, printing two different messages. | ||
|
|
||
| ### Sample output | ||
|
|
||
| ``` | ||
| dev@tyche:/tyche/programs$ ./simple_enclave | ||
| [LOG @../../..//sdktyche/loader/lib.c:269 parse_domain] Parsed tychools binary | ||
| [LOG @untrusted/main.c:92 main] The binary enclave has been loaded! | ||
| [LOG @untrusted/main.c:100 main] Calling the enclave, good luck! | ||
| [LOG @untrusted/main.c:49 hello_world] Executing HELLO_WORLD enclave | ||
|
|
||
| [ERROR | capa_engine::domain] Removing from a core in which the domains was NOT executing | ||
| [LOG @untrusted/main.c:56 hello_world] First enclave message: | ||
| Hello World! | ||
|
|
||
| [LOG @untrusted/main.c:63 hello_world] Second enclave message: | ||
| Bye Bye! :)! | ||
|
|
||
| [LOG @untrusted/main.c:70 hello_world] All done! | ||
| [LOG @untrusted/main.c:106 main] Done, have a good day! | ||
|
|
||
| ``` |
34 changes: 34 additions & 0 deletions
34
C/libraries/sdktyche/example/enclave_rot_riscv/include/enclave_app.h
This file contains hidden or 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,34 @@ | ||
| #ifndef __INCLUDE_ENCLAVE_APP_H__ | ||
| #define __INCLUDE_ENCLAVE_APP_H__ | ||
|
|
||
| /// Configuration for the enclave. | ||
| /// This allows to select which example to run via shared memory. | ||
| typedef struct { | ||
| /// arguments for this application. | ||
| void* args; | ||
| } config_t; | ||
|
|
||
| typedef unsigned long long nonce_t; | ||
| typedef unsigned long long phys_offset_t; | ||
| #define PUB_KEY_SIZE 32 | ||
| #define SIGNED_DATA_SIZE 64 | ||
| #define TPM_ATTESTATION_SIZE 129 | ||
| #define TPM_SIGNATURE_SIZE 384 | ||
| #define TPM_MODULUS_SIZE 384 | ||
| #define SUPPOSED_ATTESTATION_SIZE 993 | ||
| #define CALC_REPORT 0 | ||
| #define READ_REPORT 1 | ||
| /// Hello world argument. | ||
| typedef struct { | ||
| char reply[30]; | ||
| unsigned long long report_size; | ||
| nonce_t nonce; | ||
| char pub_key[PUB_KEY_SIZE]; | ||
| char signed_enclave_data[SIGNED_DATA_SIZE]; | ||
| char tpm_signature[TPM_SIGNATURE_SIZE]; | ||
| char tpm_modulus[TPM_MODULUS_SIZE]; | ||
| char tpm_attestation[TPM_ATTESTATION_SIZE]; | ||
| } __attribute__((__packed__)) hello_world_t; | ||
|
|
||
|
|
||
| #endif |
28 changes: 28 additions & 0 deletions
28
C/libraries/sdktyche/example/enclave_rot_riscv/manifests/default.json
This file contains hidden or 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,28 @@ | ||
| { | ||
| "untrusted_bin": { | ||
| "path": "app" | ||
| }, | ||
| "kern_bin": { | ||
| "path":"enclave", | ||
| "ops":[ | ||
| { | ||
| "AddSegment":{ | ||
| "size":8192, | ||
| "tpe":"KernelStackConf", | ||
| "write":true,"exec":false | ||
| } | ||
| }, | ||
| { | ||
| "AddSegment":{ | ||
| "start": 3145728, | ||
| "size":8192, | ||
| "tpe":"KernelShared", | ||
| "write":true, | ||
| "exec":false | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "generate_pts": true, | ||
| "output": "rot_enclave" | ||
| } |
26 changes: 26 additions & 0 deletions
26
C/libraries/sdktyche/example/enclave_rot_riscv/manifests/rot_iso.json
This file contains hidden or 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,26 @@ | ||
| { | ||
| "kern_bin": { | ||
| "path":"enclave", | ||
| "ops":[ | ||
| { | ||
| "AddSegment":{ | ||
| "size":8192, | ||
| "tpe":"KernelStackConf", | ||
| "write":true,"exec":false | ||
| } | ||
| }, | ||
| { | ||
| "AddSegment":{ | ||
| "start": 3145728, | ||
| "size":8192, | ||
| "tpe":"KernelShared", | ||
| "write":true, | ||
| "exec":false | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "generate_pts": true, | ||
| "output": "rot_iso" | ||
| } | ||
|
|
|
Collaborator
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. We generally don't include the binaries and they are rebuilt locally by everyone so we may not end up facing any environment configuration/portability issues ^ ^ |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
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.
I guess this one hasn't been modified since being fetched from simple enclave. ^ ^
Maybe it could be edited to replace the simple enclave explanation with rot enclave explanation and same for the sample output too?
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.
Can you also add the sample output for when TPM fields are set to zero?