Skip to content

Commit 61e2658

Browse files
committed
Merge tag 'x86_sgx_for_v5.18_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 SGX updates from Borislav Petkov: - A couple of fixes and improvements to the SGX selftests * tag 'x86_sgx_for_v5.18_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: selftests/sgx: Treat CC as one argument selftests/x86: Add validity check and allow field splitting selftests/sgx: Remove extra newlines in test output selftests/sgx: Ensure enclave data available during debug print selftests/sgx: Do not attempt enclave build without valid enclave selftests/sgx: Fix NULL-pointer-dereference upon early test failure
2 parents 88f30ac + 6170abb commit 61e2658

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

tools/testing/selftests/sgx/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include ../lib.mk
44

55
.PHONY: all clean
66

7-
CAN_BUILD_X86_64 := $(shell ../x86/check_cc.sh $(CC) \
7+
CAN_BUILD_X86_64 := $(shell ../x86/check_cc.sh "$(CC)" \
88
../x86/trivial_64bit_program.c)
99

1010
ifndef OBJCOPY

tools/testing/selftests/sgx/load.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
void encl_delete(struct encl *encl)
2323
{
24-
struct encl_segment *heap_seg = &encl->segment_tbl[encl->nr_segments - 1];
24+
struct encl_segment *heap_seg;
2525

2626
if (encl->encl_base)
2727
munmap((void *)encl->encl_base, encl->encl_size);
@@ -32,10 +32,11 @@ void encl_delete(struct encl *encl)
3232
if (encl->fd)
3333
close(encl->fd);
3434

35-
munmap(heap_seg->src, heap_seg->size);
36-
37-
if (encl->segment_tbl)
35+
if (encl->segment_tbl) {
36+
heap_seg = &encl->segment_tbl[encl->nr_segments - 1];
37+
munmap(heap_seg->src, heap_seg->size);
3838
free(encl->segment_tbl);
39+
}
3940

4041
memset(encl, 0, sizeof(*encl));
4142
}

tools/testing/selftests/sgx/main.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ static bool setup_test_encl(unsigned long heap_size, struct encl *encl,
146146

147147
if (!encl_load("test_encl.elf", encl, heap_size)) {
148148
encl_delete(encl);
149-
TH_LOG("Failed to load the test enclave.\n");
149+
TH_LOG("Failed to load the test enclave.");
150+
return false;
150151
}
151152

152153
if (!encl_measure(encl))
@@ -185,8 +186,6 @@ static bool setup_test_encl(unsigned long heap_size, struct encl *encl,
185186
return true;
186187

187188
err:
188-
encl_delete(encl);
189-
190189
for (i = 0; i < encl->nr_segments; i++) {
191190
seg = &encl->segment_tbl[i];
192191

@@ -205,7 +204,9 @@ static bool setup_test_encl(unsigned long heap_size, struct encl *encl,
205204
fclose(maps_file);
206205
}
207206

208-
TH_LOG("Failed to initialize the test enclave.\n");
207+
TH_LOG("Failed to initialize the test enclave.");
208+
209+
encl_delete(encl);
209210

210211
return false;
211212
}

tools/testing/selftests/x86/check_cc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CC="$1"
77
TESTPROG="$2"
88
shift 2
99

10-
if "$CC" -o /dev/null "$TESTPROG" -O0 "$@" 2>/dev/null; then
10+
if [ -n "$CC" ] && $CC -o /dev/null "$TESTPROG" -O0 "$@" 2>/dev/null; then
1111
echo 1
1212
else
1313
echo 0

0 commit comments

Comments
 (0)