Skip to contentSkip to conversation

selftests/x86/sgx: Merge test_sgx and sgxsign

PATCH In review Jarkko Sakkinen 1 participant 2 messages Mar 20, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/x86/sgx: Merge test_sgx and sgxsign

Sign enclaves on fly in test_sgx instead of using a precompiled sigstruct. This simplifies both the build process and the test program.

Cc Sean Christopherson <[email protected]>
---
 tools/testing/selftests/x86/sgx/.gitignore    |   2 -
 tools/testing/selftests/x86/sgx/Makefile      |  21 +-
 .../selftests/x86/sgx/{sgx_call.S => call.S}  |   0
 tools/testing/selftests/x86/sgx/defines.h     |   2 +
 tools/testing/selftests/x86/sgx/main.c        |  27 +--
 .../selftests/x86/sgx/{sgx_call.h => main.h}  |   8 +-
 .../selftests/x86/sgx/{sgxsign.c => sign.c}   | 184 ++++++------------
 7 files changed, 72 insertions(+), 172 deletions(-)
 rename tools/testing/selftests/x86/sgx/{sgx_call.S => call.S} (100%)
 rename tools/testing/selftests/x86/sgx/{sgx_call.h => main.h} (60%)
 rename tools/testing/selftests/x86/sgx/{sgxsign.c => sign.c} (66%)
tools/testing/selftests/x86/sgx/.gitignore +0 -2
index 98eb2d439606..828490670951 100644
@@ -1,3 +1 @@
-encl.ss
-sgxsign
 test_sgx
tools/testing/selftests/x86/sgx/Makefile +8 -13
index ff0136310c2b..789ebbbfddcb 100644
@@ -11,37 +11,32 @@ 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 $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
+TEST_CUSTOM_PROGS := $(OUTPUT)/test_sgx $(OUTPUT)/encl.bin
 
 all: $(TEST_CUSTOM_PROGS)
 
-$(OUTPUT)/test_sgx: $(OUTPUT)/main.o $(OUTPUT)/sgx_call.o
-	$(CC) $(HOST_CFLAGS) -o $@ $^
+$(OUTPUT)/test_sgx: $(OUTPUT)/main.o $(OUTPUT)/sign.o $(OUTPUT)/call.o
+	$(CC) $(HOST_CFLAGS) -o $@ $^ -lcrypto
 
 $(OUTPUT)/main.o: main.c
 	$(CC) $(HOST_CFLAGS) -c $< -o $@
 
-$(OUTPUT)/sgx_call.o: sgx_call.S
+$(OUTPUT)/sign.o: sign.c
 	$(CC) $(HOST_CFLAGS) -c $< -o $@
 
-$(OUTPUT)/encl.bin: $(OUTPUT)/encl.elf $(OUTPUT)/sgxsign
+$(OUTPUT)/call.o: call.S
+	$(CC) $(HOST_CFLAGS) -c $< -o $@
+
+$(OUTPUT)/encl.bin: $(OUTPUT)/encl.elf
 	$(OBJCOPY) -O binary $< $@
 
 $(OUTPUT)/encl.elf: encl.lds encl.c encl_bootstrap.S
 	$(CC) $(ENCL_CFLAGS) -T $^ -o $@
 
-$(OUTPUT)/encl.ss: $(OUTPUT)/encl.bin
-	$(OUTPUT)/sgxsign $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
-
-$(OUTPUT)/sgxsign: sgxsign.c
-	$(CC) $(INCLUDES) -o $@ $< -lcrypto
-
 EXTRA_CLEAN := \
 	$(OUTPUT)/encl.bin \
 	$(OUTPUT)/encl.elf \
-	$(OUTPUT)/encl.ss \
 	$(OUTPUT)/sgx_call.o \
-	$(OUTPUT)/sgxsign \
 	$(OUTPUT)/test_sgx \
 	$(OUTPUT)/test_sgx.o \
 
tools/testing/selftests/x86/sgx/call.S renamed from tools/testing/selftests/x86/sgx/sgx_call.S +0 -0
similarity index 100%
rename from tools/testing/selftests/x86/sgx/sgx_call.S
rename to tools/testing/selftests/x86/sgx/call.S
tools/testing/selftests/x86/sgx/defines.h +2 -0
index 87264f85cb9f..0f91175088f6 100644
@@ -8,6 +8,8 @@
 
 #include <stdint.h>
 
+#define PAGE_SIZE 4096
+
 #define __aligned(x) __attribute__((__aligned__(x)))
 #define __packed __attribute__((packed))
 
tools/testing/selftests/x86/sgx/main.c +2 -25
index 5a6f5c0656c1..af16dd6f4b92 100644
@@ -16,9 +16,7 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include "defines.h"
-#include "sgx_call.h"
-
-#define PAGE_SIZE  4096
+#include "main.h"
 
 static const uint64_t MAGIC = 0x1122334455667788ULL;
 void *eenter;
@@ -298,27 +296,6 @@ bool encl_data_map(const char *path, void **bin, off_t *bin_size)
 	return false;
 }
 
-bool load_sigstruct(const char *path, void *sigstruct)
-{
-	int fd;
-
-	fd = open(path, O_RDONLY);
-	if (fd == -1)  {
-		fprintf(stderr, "open() %s failed, errno=%d.\n", path, errno);
-		return false;
-	}
-
-	if (read(fd, sigstruct, sizeof(struct sgx_sigstruct)) !=
-	    sizeof(struct sgx_sigstruct)) {
-		fprintf(stderr, "read() %s failed, errno=%d.\n", path, errno);
-		close(fd);
-		return false;
-	}
-
-	close(fd);
-	return true;
-}
-
 int main(int argc, char *argv[], char *envp[])
 {
 	struct sgx_enclave_exception exception;
@@ -334,7 +311,7 @@ int main(int argc, char *argv[], char *envp[])
 	if (!encl_data_map("encl.bin", &bin, &bin_size))
 		exit(1);
 
-	if (!load_sigstruct("encl.ss", &sigstruct))
+	if (!encl_create_sigstruct(bin, bin_size, &sigstruct))
 		exit(1);
 
 	if (!encl_build(&secs, bin, bin_size, &sigstruct))
tools/testing/selftests/x86/sgx/main.h renamed from tools/testing/selftests/x86/sgx/sgx_call.h +5 -3
similarity index 60%
rename from tools/testing/selftests/x86/sgx/sgx_call.h
rename to tools/testing/selftests/x86/sgx/main.h
index 133f7f18c3df..5de6cd492adc 100644
@@ -3,10 +3,12 @@
  * Copyright(c) 2016-19 Intel Corporation.
  */
 
-#ifndef SGX_CALL_H
-#define SGX_CALL_H
+#ifndef MAIN_H
+#define MAIN_H
 
+bool encl_create_sigstruct(const void *bin, unsigned long size,
+			   struct sgx_sigstruct *sigstruct);
 int sgx_call_vdso(void *rdi, void *rsi, long rdx, void *rcx, void *r8, void *r9,
 		  void *tcs, struct sgx_enclave_exception *ei, void *cb);
 
-#endif /* SGX_CALL_H */
+#endif /* MAIN_H */
tools/testing/selftests/x86/sgx/sign.c renamed from tools/testing/selftests/x86/sgx/sgxsign.c +55 -129

247 lines not on this page · raw message

Signature · 1 line
2.25.1