-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/x86: Add a selftest for SGX
Add a selftest for SGX. It is a trivial test where a simple enclave copies one 64-bit word of memory between two memory locations, but ensures that all SGX hardware and software infrastructure is functioning. Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Borislav Petkov <bp@suse.de> Acked-by: Jethro Beekman <jethro@fortanix.com> Cc: linux-kselftest@vger.kernel.org Link: https://lkml.kernel.org/r/20201112220135.165028-21-jarkko@kernel.org
- Loading branch information
Jarkko Sakkinen
authored and
Borislav Petkov
committed
Nov 18, 2020
1 parent
8466436
commit 2adcba7
Showing
12 changed files
with
1,222 additions
and
0 deletions.
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,2 @@ | ||
test_sgx | ||
test_encl.elf |
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,53 @@ | ||
top_srcdir = ../../../.. | ||
|
||
include ../lib.mk | ||
|
||
.PHONY: all clean | ||
|
||
CAN_BUILD_X86_64 := $(shell ../x86/check_cc.sh $(CC) \ | ||
../x86/trivial_64bit_program.c) | ||
|
||
ifndef OBJCOPY | ||
OBJCOPY := $(CROSS_COMPILE)objcopy | ||
endif | ||
|
||
INCLUDES := -I$(top_srcdir)/tools/include | ||
HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC -z noexecstack | ||
ENCL_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -fPIC \ | ||
-fno-stack-protector -mrdrnd $(INCLUDES) | ||
|
||
TEST_CUSTOM_PROGS := $(OUTPUT)/test_sgx | ||
|
||
ifeq ($(CAN_BUILD_X86_64), 1) | ||
all: $(TEST_CUSTOM_PROGS) $(OUTPUT)/test_encl.elf | ||
endif | ||
|
||
$(OUTPUT)/test_sgx: $(OUTPUT)/main.o \ | ||
$(OUTPUT)/load.o \ | ||
$(OUTPUT)/sigstruct.o \ | ||
$(OUTPUT)/call.o | ||
$(CC) $(HOST_CFLAGS) -o $@ $^ -lcrypto | ||
|
||
$(OUTPUT)/main.o: main.c | ||
$(CC) $(HOST_CFLAGS) -c $< -o $@ | ||
|
||
$(OUTPUT)/load.o: load.c | ||
$(CC) $(HOST_CFLAGS) -c $< -o $@ | ||
|
||
$(OUTPUT)/sigstruct.o: sigstruct.c | ||
$(CC) $(HOST_CFLAGS) -c $< -o $@ | ||
|
||
$(OUTPUT)/call.o: call.S | ||
$(CC) $(HOST_CFLAGS) -c $< -o $@ | ||
|
||
$(OUTPUT)/test_encl.elf: test_encl.lds test_encl.c test_encl_bootstrap.S | ||
$(CC) $(ENCL_CFLAGS) -T $^ -o $@ | ||
|
||
EXTRA_CLEAN := \ | ||
$(OUTPUT)/test_encl.elf \ | ||
$(OUTPUT)/load.o \ | ||
$(OUTPUT)/call.o \ | ||
$(OUTPUT)/main.o \ | ||
$(OUTPUT)/sigstruct.o \ | ||
$(OUTPUT)/test_sgx \ | ||
$(OUTPUT)/test_sgx.o \ |
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,44 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/** | ||
* Copyright(c) 2016-20 Intel Corporation. | ||
*/ | ||
|
||
.text | ||
|
||
.global sgx_call_vdso | ||
sgx_call_vdso: | ||
.cfi_startproc | ||
push %r15 | ||
.cfi_adjust_cfa_offset 8 | ||
.cfi_rel_offset %r15, 0 | ||
push %r14 | ||
.cfi_adjust_cfa_offset 8 | ||
.cfi_rel_offset %r14, 0 | ||
push %r13 | ||
.cfi_adjust_cfa_offset 8 | ||
.cfi_rel_offset %r13, 0 | ||
push %r12 | ||
.cfi_adjust_cfa_offset 8 | ||
.cfi_rel_offset %r12, 0 | ||
push %rbx | ||
.cfi_adjust_cfa_offset 8 | ||
.cfi_rel_offset %rbx, 0 | ||
push $0 | ||
.cfi_adjust_cfa_offset 8 | ||
push 0x38(%rsp) | ||
.cfi_adjust_cfa_offset 8 | ||
call *eenter(%rip) | ||
add $0x10, %rsp | ||
.cfi_adjust_cfa_offset -0x10 | ||
pop %rbx | ||
.cfi_adjust_cfa_offset -8 | ||
pop %r12 | ||
.cfi_adjust_cfa_offset -8 | ||
pop %r13 | ||
.cfi_adjust_cfa_offset -8 | ||
pop %r14 | ||
.cfi_adjust_cfa_offset -8 | ||
pop %r15 | ||
.cfi_adjust_cfa_offset -8 | ||
ret | ||
.cfi_endproc |
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,21 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Copyright(c) 2016-20 Intel Corporation. | ||
*/ | ||
|
||
#ifndef DEFINES_H | ||
#define DEFINES_H | ||
|
||
#include <stdint.h> | ||
|
||
#define PAGE_SIZE 4096 | ||
#define PAGE_MASK (~(PAGE_SIZE - 1)) | ||
|
||
#define __aligned(x) __attribute__((__aligned__(x))) | ||
#define __packed __attribute__((packed)) | ||
|
||
#include "../../../../arch/x86/kernel/cpu/sgx/arch.h" | ||
#include "../../../../arch/x86/include/asm/enclu.h" | ||
#include "../../../../arch/x86/include/uapi/asm/sgx.h" | ||
|
||
#endif /* DEFINES_H */ |
Oops, something went wrong.