Lines Matching +full:tcs +full:- +full:offset

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2016-20 Intel Corporation. */
30 * instructions (eg. ENCLU[EACCEPT] and ENCLU[EMODPE]) holds meta-data
49 Elf64_Phdr *phdrtab = addr + ehdr->e_phoff; in vdso_get_dyntab()
52 for (i = 0; i < ehdr->e_phnum; i++) in vdso_get_dyntab()
74 symtab->elf_symtab = vdso_get_dyn(addr, dyntab, DT_SYMTAB); in vdso_get_symtab()
75 if (!symtab->elf_symtab) in vdso_get_symtab()
78 symtab->elf_symstrtab = vdso_get_dyn(addr, dyntab, DT_STRTAB); in vdso_get_symtab()
79 if (!symtab->elf_symstrtab) in vdso_get_symtab()
82 symtab->elf_hashtab = vdso_get_dyn(addr, dyntab, DT_HASH); in vdso_get_symtab()
83 if (!symtab->elf_hashtab) in vdso_get_symtab()
117 Elf64_Word bucketnum = symtab->elf_hashtab[0]; in vdso_symtab_get()
118 Elf64_Word *buckettab = &symtab->elf_hashtab[2]; in vdso_symtab_get()
119 Elf64_Word *chaintab = &symtab->elf_hashtab[2 + bucketnum]; in vdso_symtab_get()
125 sym = &symtab->elf_symtab[i]; in vdso_symtab_get()
126 if (!strcmp(name, &symtab->elf_symstrtab[sym->st_name])) in vdso_symtab_get()
134 * Return the offset in the enclave where the TCS segment can be found.
135 * The first RW segment loaded is the TCS.
141 for (i = 0; i < encl->nr_segments; i++) { in encl_get_tcs_offset()
142 struct encl_segment *seg = &encl->segment_tbl[i]; in encl_get_tcs_offset()
144 if (i == 0 && seg->prot == (PROT_READ | PROT_WRITE)) in encl_get_tcs_offset()
145 return seg->offset; in encl_get_tcs_offset()
148 return -1; in encl_get_tcs_offset()
152 * Return the offset in the enclave where the data segment can be found.
153 * The first RW segment loaded is the TCS, skip that to get info on the
160 for (i = 1; i < encl->nr_segments; i++) { in encl_get_data_offset()
161 struct encl_segment *seg = &encl->segment_tbl[i]; in encl_get_data_offset()
163 if (seg->prot == (PROT_READ | PROT_WRITE)) in encl_get_data_offset()
164 return seg->offset; in encl_get_data_offset()
167 return -1; in encl_get_data_offset()
201 for (i = 0; i < encl->nr_segments; i++) { in setup_test_encl()
202 struct encl_segment *seg = &encl->segment_tbl[i]; in setup_test_encl()
204 addr = mmap((void *)encl->encl_base + seg->offset, seg->size, in setup_test_encl()
205 seg->prot, MAP_SHARED | MAP_FIXED, encl->fd, 0); in setup_test_encl()
223 vdso_sgx_enter_enclave = addr + sgx_enter_enclave_sym->st_value; in setup_test_encl()
228 for (i = 0; i < encl->nr_segments; i++) { in setup_test_encl()
229 seg = &encl->segment_tbl[i]; in setup_test_encl()
231 TH_LOG("0x%016lx 0x%016lx 0x%02x", seg->offset, seg->size, seg->prot); in setup_test_encl()
237 maps_line[strlen(maps_line) - 1] = '\0'; in setup_test_encl()
259 encl_delete(&self->encl); in FIXTURE_TEARDOWN()
276 EXPECT_EQ((run)->function, EEXIT); \
277 if ((run)->function != EEXIT) \
278 TH_LOG("0x%02x 0x%02x 0x%016llx", (run)->exception_vector, \
279 (run)->exception_error_code, (run)->exception_addr); \
287 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
289 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
290 self->run.tcs = self->encl.encl_base; in TEST_F()
295 EXPECT_EQ(ENCL_CALL(&put_op, &self->run, false), 0); in TEST_F()
297 EXPECT_EEXIT(&self->run); in TEST_F()
298 EXPECT_EQ(self->run.user_data, 0); in TEST_F()
303 EXPECT_EQ(ENCL_CALL(&get_op, &self->run, false), 0); in TEST_F()
306 EXPECT_EEXIT(&self->run); in TEST_F()
307 EXPECT_EQ(self->run.user_data, 0); in TEST_F()
311 * A section metric is concatenated in a way that @low bits 12-31 define the
312 * bits 12-31 of the metric and @high bits 0-19 define the bits 32-51 of the
360 ASSERT_TRUE(setup_test_encl(total_mem, &self->encl, _metadata)); in TEST_F()
362 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
363 self->run.tcs = self->encl.encl_base; in TEST_F()
368 EXPECT_EQ(ENCL_CALL(&put_op, &self->run, false), 0); in TEST_F()
370 EXPECT_EEXIT(&self->run); in TEST_F()
371 EXPECT_EQ(self->run.user_data, 0); in TEST_F()
376 EXPECT_EQ(ENCL_CALL(&get_op, &self->run, false), 0); in TEST_F()
379 EXPECT_EEXIT(&self->run); in TEST_F()
380 EXPECT_EQ(self->run.user_data, 0); in TEST_F()
404 ASSERT_TRUE(setup_test_encl(total_mem, &self->encl, _metadata));
411 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc);
413 if (ret == -1) {
425 EXPECT_EQ(ret, -1);
428 memset(&self->run, 0, sizeof(self->run));
429 self->run.tcs = self->encl.encl_base;
431 heap = &self->encl.segment_tbl[self->encl.nr_segments - 1];
436 EXPECT_EQ(ENCL_CALL(&put_op, &self->run, false), 0);
438 EXPECT_EEXIT(&self->run);
439 EXPECT_EQ(self->run.user_data, 0);
444 EXPECT_EQ(ENCL_CALL(&get_op, &self->run, false), 0);
447 EXPECT_EEXIT(&self->run);
448 EXPECT_EQ(self->run.user_data, 0);
453 modt_ioc.offset = heap->offset;
454 modt_ioc.length = heap->size;
458 heap->size);
459 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc);
460 errno_save = ret == -1 ? errno : 0;
465 EXPECT_EQ(modt_ioc.count, heap->size);
468 addr = self->encl.encl_base + heap->offset;
474 heap->size);
475 for (i = 0; i < heap->size; i += 4096) {
479 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0);
481 EXPECT_EQ(self->run.exception_vector, 0);
482 EXPECT_EQ(self->run.exception_error_code, 0);
483 EXPECT_EQ(self->run.exception_addr, 0);
485 ASSERT_EQ(self->run.function, EEXIT);
491 remove_ioc.offset = heap->offset;
492 remove_ioc.length = heap->size;
495 heap->size);
496 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc);
497 errno_save = ret == -1 ? errno : 0;
501 EXPECT_EQ(remove_ioc.count, heap->size);
509 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
511 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
512 self->run.tcs = self->encl.encl_base; in TEST_F()
517 EXPECT_EQ(ENCL_CALL(&put_op, &self->run, true), 0); in TEST_F()
519 EXPECT_EEXIT(&self->run); in TEST_F()
520 EXPECT_EQ(self->run.user_data, 0); in TEST_F()
525 EXPECT_EQ(ENCL_CALL(&get_op, &self->run, true), 0); in TEST_F()
528 EXPECT_EEXIT(&self->run); in TEST_F()
529 EXPECT_EQ(self->run.user_data, 0); in TEST_F()
535 run->user_data = 0; in test_handler()
545 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
547 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
548 self->run.tcs = self->encl.encl_base; in TEST_F()
550 self->run.user_handler = (__u64)test_handler; in TEST_F()
551 self->run.user_data = 0xdeadbeef; in TEST_F()
556 EXPECT_EQ(ENCL_CALL(&put_op, &self->run, true), 0); in TEST_F()
558 EXPECT_EEXIT(&self->run); in TEST_F()
559 EXPECT_EQ(self->run.user_data, 0); in TEST_F()
564 EXPECT_EQ(ENCL_CALL(&get_op, &self->run, true), 0); in TEST_F()
567 EXPECT_EEXIT(&self->run); in TEST_F()
568 EXPECT_EQ(self->run.user_data, 0); in TEST_F()
572 * Sanity check that it is possible to enter either of the two hardcoded TCS
578 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
580 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
581 self->run.tcs = self->encl.encl_base; in TEST_F()
585 EXPECT_EQ(ENCL_CALL(&op, &self->run, true), 0); in TEST_F()
587 EXPECT_EEXIT(&self->run); in TEST_F()
588 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
589 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
590 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
592 /* Move to the next TCS. */ in TEST_F()
593 self->run.tcs = self->encl.encl_base + PAGE_SIZE; in TEST_F()
595 EXPECT_EQ(ENCL_CALL(&op, &self->run, true), 0); in TEST_F()
597 EXPECT_EEXIT(&self->run); in TEST_F()
598 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
599 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
600 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
609 * 2) Change PTE permissions (RW -> RO) of target page within enclave.
610 * 3) Repeat (1) - this time expecting a regular #PF communicated via the
623 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
625 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
626 self->run.tcs = self->encl.encl_base; in TEST_F()
628 data_start = self->encl.encl_base + in TEST_F()
629 encl_get_data_offset(&self->encl) + in TEST_F()
642 EXPECT_EQ(ENCL_CALL(&put_addr_op, &self->run, true), 0); in TEST_F()
644 EXPECT_EEXIT(&self->run); in TEST_F()
645 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
646 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
647 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
657 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
660 EXPECT_EEXIT(&self->run); in TEST_F()
661 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
662 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
663 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
671 * PTE permissions of target page changed to read-only, EPCM in TEST_F()
678 EXPECT_EQ(ENCL_CALL(&put_addr_op, &self->run, true), 0); in TEST_F()
680 EXPECT_EQ(self->run.exception_vector, 14); in TEST_F()
681 EXPECT_EQ(self->run.exception_error_code, 0x7); in TEST_F()
682 EXPECT_EQ(self->run.exception_addr, data_start); in TEST_F()
684 self->run.exception_vector = 0; in TEST_F()
685 self->run.exception_error_code = 0; in TEST_F()
686 self->run.exception_addr = 0; in TEST_F()
690 * target page and resume enclave - do not expect any exceptions this in TEST_F()
698 0, ERESUME, 0, 0, &self->run), in TEST_F()
701 EXPECT_EEXIT(&self->run); in TEST_F()
702 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
703 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
704 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
708 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
711 EXPECT_EEXIT(&self->run); in TEST_F()
712 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
713 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
714 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
718 * Modifying permissions of TCS page should not be possible.
725 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
727 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
728 self->run.tcs = self->encl.encl_base; in TEST_F()
737 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS, &ioc); in TEST_F()
738 errno_save = ret == -1 ? errno : 0; in TEST_F()
744 ASSERT_EQ(ret, -1); in TEST_F()
746 /* ret == -1 */ in TEST_F()
754 * Attempt to make TCS page read-only. This is not allowed and in TEST_F()
757 ioc.offset = encl_get_tcs_offset(&self->encl); in TEST_F()
761 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS, &ioc); in TEST_F()
762 errno_save = ret == -1 ? errno : 0; in TEST_F()
764 EXPECT_EQ(ret, -1); in TEST_F()
788 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
790 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
791 self->run.tcs = self->encl.encl_base; in TEST_F()
799 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS, in TEST_F()
801 errno_save = ret == -1 ? errno : 0; in TEST_F()
807 ASSERT_EQ(ret, -1); in TEST_F()
809 /* ret == -1 */ in TEST_F()
825 data_start = self->encl.encl_base + in TEST_F()
826 encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
838 EXPECT_EQ(ENCL_CALL(&put_addr_op, &self->run, true), 0); in TEST_F()
840 EXPECT_EEXIT(&self->run); in TEST_F()
841 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
842 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
843 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
853 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
856 EXPECT_EEXIT(&self->run); in TEST_F()
857 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
858 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
859 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
862 * Change EPCM permissions to read-only. Kernel still considers in TEST_F()
867 restrict_ioc.offset = encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
871 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS, in TEST_F()
873 errno_save = ret == -1 ? errno : 0; in TEST_F()
888 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
890 EXPECT_EEXIT(&self->run); in TEST_F()
891 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
892 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
893 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
897 * EPCM permissions of page is now read-only, expect #PF in TEST_F()
902 EXPECT_EQ(ENCL_CALL(&put_addr_op, &self->run, true), 0); in TEST_F()
904 EXPECT_EQ(self->run.function, ERESUME); in TEST_F()
905 EXPECT_EQ(self->run.exception_vector, 14); in TEST_F()
906 EXPECT_EQ(self->run.exception_error_code, 0x8007); in TEST_F()
907 EXPECT_EQ(self->run.exception_addr, data_start); in TEST_F()
909 self->run.exception_vector = 0; in TEST_F()
910 self->run.exception_error_code = 0; in TEST_F()
911 self->run.exception_addr = 0; in TEST_F()
915 * need different TCS from where EPCM permission can be made writable in TEST_F()
918 self->run.tcs = self->encl.encl_base + PAGE_SIZE; in TEST_F()
921 * Enter enclave at new TCS to change EPCM permissions to be in TEST_F()
930 EXPECT_EQ(ENCL_CALL(&emodpe_op, &self->run, true), 0); in TEST_F()
932 EXPECT_EEXIT(&self->run); in TEST_F()
933 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
934 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
935 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
938 * Attempt to return to main TCS to resume execution at faulting in TEST_F()
941 self->run.tcs = self->encl.encl_base; in TEST_F()
946 * Resume execution in main TCS to re-attempt the memory access. in TEST_F()
948 self->run.tcs = self->encl.encl_base; in TEST_F()
952 &self->run), in TEST_F()
955 EXPECT_EEXIT(&self->run); in TEST_F()
956 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
957 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
958 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
962 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
965 EXPECT_EEXIT(&self->run); in TEST_F()
966 EXPECT_EQ(self->run.user_data, 0); in TEST_F()
967 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
968 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
969 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
989 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
991 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
992 self->run.tcs = self->encl.encl_base; in TEST_F()
994 for (i = 0; i < self->encl.nr_segments; i++) { in TEST_F()
995 struct encl_segment *seg = &self->encl.segment_tbl[i]; in TEST_F()
997 total_size += seg->size; in TEST_F()
1005 EXPECT_LT(total_size + PAGE_SIZE, self->encl.encl_size); in TEST_F()
1015 addr = mmap((void *)self->encl.encl_base + total_size, PAGE_SIZE, in TEST_F()
1017 MAP_SHARED | MAP_FIXED, self->encl.fd, 0); in TEST_F()
1020 self->run.exception_vector = 0; in TEST_F()
1021 self->run.exception_error_code = 0; in TEST_F()
1022 self->run.exception_addr = 0; in TEST_F()
1038 EXPECT_EQ(ENCL_CALL(&put_addr_op, &self->run, true), 0); in TEST_F()
1040 EXPECT_EQ(self->run.function, ERESUME); in TEST_F()
1041 EXPECT_EQ(self->run.exception_vector, 14); in TEST_F()
1042 EXPECT_EQ(self->run.exception_addr, (unsigned long)addr); in TEST_F()
1044 if (self->run.exception_error_code == 0x6) { in TEST_F()
1049 EXPECT_EQ(self->run.exception_error_code, 0x8007); in TEST_F()
1051 self->run.exception_vector = 0; in TEST_F()
1052 self->run.exception_error_code = 0; in TEST_F()
1053 self->run.exception_addr = 0; in TEST_F()
1056 self->run.tcs = self->encl.encl_base + PAGE_SIZE; in TEST_F()
1058 eaccept_op.epc_addr = self->encl.encl_base + total_size; in TEST_F()
1063 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1065 EXPECT_EEXIT(&self->run); in TEST_F()
1066 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1067 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1068 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1071 /* Can now return to main TCS to resume execution. */ in TEST_F()
1072 self->run.tcs = self->encl.encl_base; in TEST_F()
1076 &self->run), in TEST_F()
1079 EXPECT_EEXIT(&self->run); in TEST_F()
1080 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1081 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1082 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1092 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
1095 EXPECT_EEXIT(&self->run); in TEST_F()
1096 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1097 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1098 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1105 * pre-emptive run of EACCEPT on page to be added.
1119 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
1121 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
1122 self->run.tcs = self->encl.encl_base; in TEST_F()
1124 for (i = 0; i < self->encl.nr_segments; i++) { in TEST_F()
1125 struct encl_segment *seg = &self->encl.segment_tbl[i]; in TEST_F()
1127 total_size += seg->size; in TEST_F()
1135 EXPECT_LT(total_size + PAGE_SIZE, self->encl.encl_size); in TEST_F()
1146 addr = mmap((void *)self->encl.encl_base + total_size, PAGE_SIZE, in TEST_F()
1148 self->encl.fd, 0); in TEST_F()
1151 self->run.exception_vector = 0; in TEST_F()
1152 self->run.exception_error_code = 0; in TEST_F()
1153 self->run.exception_addr = 0; in TEST_F()
1156 * Run EACCEPT on new page to trigger the #PF->EAUG->EACCEPT(again in TEST_F()
1159 eaccept_op.epc_addr = self->encl.encl_base + total_size; in TEST_F()
1164 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1166 if (self->run.exception_vector == 14 && in TEST_F()
1167 self->run.exception_error_code == 4 && in TEST_F()
1168 self->run.exception_addr == self->encl.encl_base + total_size) { in TEST_F()
1173 EXPECT_EEXIT(&self->run); in TEST_F()
1174 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1175 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1176 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1180 * New page should be accessible from within enclave - attempt to in TEST_F()
1187 EXPECT_EQ(ENCL_CALL(&put_addr_op, &self->run, true), 0); in TEST_F()
1189 EXPECT_EEXIT(&self->run); in TEST_F()
1190 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1191 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1192 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1202 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
1205 EXPECT_EEXIT(&self->run); in TEST_F()
1206 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1207 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1208 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1216 * Create a new TCS, consisting out of three new pages (stack page with regular
1217 * page type, SSA page with regular page type, and TCS page with TCS page
1221 * same address that previously hosted the TCS page and verify that it can
1233 void *addr, *tcs, *stack_end, *ssa; in TEST_F() local
1240 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, in TEST_F()
1243 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
1244 self->run.tcs = self->encl.encl_base; in TEST_F()
1251 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc); in TEST_F()
1253 if (ret == -1) { in TEST_F()
1265 EXPECT_EQ(ret, -1); in TEST_F()
1268 * Add three regular pages via EAUG: one will be the TCS stack, one in TEST_F()
1269 * will be the TCS SSA, and one will be the new TCS. The stack and in TEST_F()
1270 * SSA will remain as regular pages, the TCS page will need its in TEST_F()
1273 for (i = 0; i < self->encl.nr_segments; i++) { in TEST_F()
1274 struct encl_segment *seg = &self->encl.segment_tbl[i]; in TEST_F()
1276 total_size += seg->size; in TEST_F()
1284 EXPECT_LT(total_size + 3 * PAGE_SIZE, self->encl.encl_size); in TEST_F()
1290 addr = mmap((void *)self->encl.encl_base + total_size, 3 * PAGE_SIZE, in TEST_F()
1292 self->encl.fd, 0); in TEST_F()
1295 self->run.exception_vector = 0; in TEST_F()
1296 self->run.exception_error_code = 0; in TEST_F()
1297 self->run.exception_addr = 0; in TEST_F()
1299 stack_end = (void *)self->encl.encl_base + total_size; in TEST_F()
1300 tcs = (void *)self->encl.encl_base + total_size + PAGE_SIZE; in TEST_F()
1301 ssa = (void *)self->encl.encl_base + total_size + 2 * PAGE_SIZE; in TEST_F()
1305 * EACCEPT->(#PF)->EAUG->EACCEPT(again without a #PF) flow. in TEST_F()
1313 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1315 if (self->run.exception_vector == 14 && in TEST_F()
1316 self->run.exception_error_code == 4 && in TEST_F()
1317 self->run.exception_addr == (unsigned long)stack_end) { in TEST_F()
1322 EXPECT_EEXIT(&self->run); in TEST_F()
1323 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1324 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1325 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1330 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1332 EXPECT_EEXIT(&self->run); in TEST_F()
1333 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1334 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1335 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1338 eaccept_op.epc_addr = (unsigned long)tcs; in TEST_F()
1340 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1342 EXPECT_EEXIT(&self->run); in TEST_F()
1343 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1344 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1345 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1349 * Three new pages added to enclave. Now populate the TCS page with in TEST_F()
1356 * New TCS will use the "encl_dyn_entry" entrypoint that expects in TEST_F()
1357 * stack to begin in page before TCS page. in TEST_F()
1359 val_64 = encl_get_entry(&self->encl, "encl_dyn_entry"); in TEST_F()
1362 init_tcs_page_op.tcs_page = (unsigned long)tcs; in TEST_F()
1367 EXPECT_EQ(ENCL_CALL(&init_tcs_page_op, &self->run, true), 0); in TEST_F()
1369 EXPECT_EEXIT(&self->run); in TEST_F()
1370 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1371 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1372 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1374 /* Change TCS page type to TCS. */ in TEST_F()
1377 modt_ioc.offset = total_size + PAGE_SIZE; in TEST_F()
1381 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc); in TEST_F()
1382 errno_save = ret == -1 ? errno : 0; in TEST_F()
1389 /* EACCEPT new TCS page from enclave. */ in TEST_F()
1390 eaccept_op.epc_addr = (unsigned long)tcs; in TEST_F()
1395 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1397 EXPECT_EEXIT(&self->run); in TEST_F()
1398 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1399 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1400 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1403 /* Run workload from new TCS. */ in TEST_F()
1404 self->run.tcs = (unsigned long)tcs; in TEST_F()
1412 EXPECT_EQ(ENCL_CALL(&put_buf_op, &self->run, true), 0); in TEST_F()
1414 EXPECT_EEXIT(&self->run); in TEST_F()
1415 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1416 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1417 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1422 EXPECT_EQ(ENCL_CALL(&get_buf_op, &self->run, true), 0); in TEST_F()
1425 EXPECT_EEXIT(&self->run); in TEST_F()
1426 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1427 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1428 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1432 * Remove pages associated with new TCS, create a regular page in TEST_F()
1433 * where TCS page used to be and verify it can be used as a regular in TEST_F()
1440 modt_ioc.offset = total_size; in TEST_F()
1444 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc); in TEST_F()
1445 errno_save = ret == -1 ? errno : 0; in TEST_F()
1453 * Enter enclave via TCS #1 and approve page removal by sending in TEST_F()
1456 self->run.tcs = self->encl.encl_base; in TEST_F()
1463 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1465 EXPECT_EEXIT(&self->run); in TEST_F()
1466 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1467 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1468 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1471 eaccept_op.epc_addr = (unsigned long)tcs; in TEST_F()
1474 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1476 EXPECT_EEXIT(&self->run); in TEST_F()
1477 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1478 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1479 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1485 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1487 EXPECT_EEXIT(&self->run); in TEST_F()
1488 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1489 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1490 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1496 remove_ioc.offset = total_size; in TEST_F()
1499 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc); in TEST_F()
1500 errno_save = ret == -1 ? errno : 0; in TEST_F()
1507 * Enter enclave via TCS #1 and access location where TCS #3 was to in TEST_F()
1510 eaccept_op.epc_addr = (unsigned long)tcs; in TEST_F()
1515 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1517 EXPECT_EEXIT(&self->run); in TEST_F()
1518 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1519 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1520 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1524 * New page should be accessible from within enclave - write to it. in TEST_F()
1527 put_addr_op.addr = (unsigned long)tcs; in TEST_F()
1530 EXPECT_EQ(ENCL_CALL(&put_addr_op, &self->run, true), 0); in TEST_F()
1532 EXPECT_EEXIT(&self->run); in TEST_F()
1533 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1534 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1535 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1542 get_addr_op.addr = (unsigned long)tcs; in TEST_F()
1545 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
1548 EXPECT_EEXIT(&self->run); in TEST_F()
1549 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1550 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1551 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1571 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
1573 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
1574 self->run.tcs = self->encl.encl_base; in TEST_F()
1581 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc); in TEST_F()
1583 if (ret == -1) { in TEST_F()
1595 EXPECT_EQ(ret, -1); in TEST_F()
1602 data_start = self->encl.encl_base + in TEST_F()
1603 encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
1615 EXPECT_EQ(ENCL_CALL(&put_addr_op, &self->run, true), 0); in TEST_F()
1617 EXPECT_EEXIT(&self->run); in TEST_F()
1618 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1619 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1620 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1630 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
1633 EXPECT_EEXIT(&self->run); in TEST_F()
1634 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1635 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1636 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1641 modt_ioc.offset = encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
1645 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc); in TEST_F()
1646 errno_save = ret == -1 ? errno : 0; in TEST_F()
1658 remove_ioc.offset = encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
1661 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc); in TEST_F()
1662 errno_save = ret == -1 ? errno : 0; in TEST_F()
1665 EXPECT_EQ(ret, -1); in TEST_F()
1682 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
1684 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
1685 self->run.tcs = self->encl.encl_base; in TEST_F()
1692 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &ioc); in TEST_F()
1694 if (ret == -1) { in TEST_F()
1706 EXPECT_EQ(ret, -1); in TEST_F()
1713 data_start = self->encl.encl_base + in TEST_F()
1714 encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
1726 EXPECT_EQ(ENCL_CALL(&put_addr_op, &self->run, true), 0); in TEST_F()
1728 EXPECT_EEXIT(&self->run); in TEST_F()
1729 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1730 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1731 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1741 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
1744 EXPECT_EEXIT(&self->run); in TEST_F()
1745 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1746 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1747 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1752 ioc.offset = encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
1756 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &ioc); in TEST_F()
1757 errno_save = ret == -1 ? errno : 0; in TEST_F()
1769 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
1777 EXPECT_EQ(self->run.function, ERESUME); in TEST_F()
1778 EXPECT_EQ(self->run.exception_vector, 14); in TEST_F()
1779 EXPECT_EQ(self->run.exception_error_code, 0x8005); in TEST_F()
1780 EXPECT_EQ(self->run.exception_addr, data_start); in TEST_F()
1797 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
1799 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
1800 self->run.tcs = self->encl.encl_base; in TEST_F()
1807 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &ioc); in TEST_F()
1809 if (ret == -1) { in TEST_F()
1821 EXPECT_EQ(ret, -1); in TEST_F()
1828 data_start = self->encl.encl_base + in TEST_F()
1829 encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
1841 EXPECT_EQ(ENCL_CALL(&put_addr_op, &self->run, true), 0); in TEST_F()
1843 EXPECT_EEXIT(&self->run); in TEST_F()
1844 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1845 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1846 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1856 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
1859 EXPECT_EEXIT(&self->run); in TEST_F()
1860 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1861 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1862 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1867 ioc.offset = encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
1871 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &ioc); in TEST_F()
1872 errno_save = ret == -1 ? errno : 0; in TEST_F()
1884 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1886 EXPECT_EEXIT(&self->run); in TEST_F()
1887 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1888 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1889 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1899 EXPECT_EQ(ENCL_CALL(&get_addr_op, &self->run, true), 0); in TEST_F()
1907 EXPECT_EQ(self->run.function, ERESUME); in TEST_F()
1908 EXPECT_EQ(self->run.exception_vector, 14); in TEST_F()
1909 EXPECT_EQ(self->run.exception_error_code, 0x8005); in TEST_F()
1910 EXPECT_EQ(self->run.exception_addr, data_start); in TEST_F()
1921 ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata)); in TEST_F()
1928 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc); in TEST_F()
1930 if (ret == -1) { in TEST_F()
1942 EXPECT_EQ(ret, -1); in TEST_F()
1945 memset(&self->run, 0, sizeof(self->run)); in TEST_F()
1946 self->run.tcs = self->encl.encl_base; in TEST_F()
1948 data_start = self->encl.encl_base + in TEST_F()
1949 encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
1953 modt_ioc.offset = encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
1956 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc); in TEST_F()
1957 errno_save = ret == -1 ? errno : 0; in TEST_F()
1965 * Enter enclave via TCS #1 and approve page removal by sending in TEST_F()
1974 EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0); in TEST_F()
1975 EXPECT_EEXIT(&self->run); in TEST_F()
1976 EXPECT_EQ(self->run.exception_vector, 0); in TEST_F()
1977 EXPECT_EQ(self->run.exception_error_code, 0); in TEST_F()
1978 EXPECT_EQ(self->run.exception_addr, 0); in TEST_F()
1983 remove_ioc.offset = encl_get_data_offset(&self->encl) + PAGE_SIZE; in TEST_F()
1985 ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc); in TEST_F()
1986 errno_save = ret == -1 ? errno : 0; in TEST_F()