Ver código fonte

[Pal/Linux-SGX] OCALL cleanup: rename ocall_{un}map_untrusted() to m{un}map

Dmitrii Kuvaiskii 4 anos atrás
pai
commit
c317610e0b

+ 6 - 6
Pal/src/host/Linux-SGX/db_files.c

@@ -86,7 +86,7 @@ static int file_open(PAL_HANDLE* handle, const char* type, const char* uri, int
 
     if (hdl->file.stubs) {
         /* case of trusted file: mmap the whole file in untrusted memory for future reads/writes */
-        ret = ocall_map_untrusted(hdl->file.fd, 0, hdl->file.total, PROT_READ, &hdl->file.umem);
+        ret = ocall_mmap_untrusted(hdl->file.fd, 0, hdl->file.total, PROT_READ, &hdl->file.umem);
         if (IS_ERR(ret)) {
             /* note that we don't free stubs because they are re-used in same trusted file */
             free(hdl);
@@ -174,7 +174,7 @@ static int file_close(PAL_HANDLE handle) {
 
     if (handle->file.stubs) {
         /* case of trusted file: the whole file was mmapped in untrusted memory */
-        ocall_unmap_untrusted(handle->file.umem, handle->file.total);
+        ocall_munmap_untrusted(handle->file.umem, handle->file.total);
     }
 
     ocall_close(fd);
@@ -210,7 +210,7 @@ static int file_map(PAL_HANDLE handle, void** addr, int prot, uint64_t offset, u
      * does not request a specific address.
      */
     if (!mem && !stubs && !(prot & PAL_PROT_WRITECOPY)) {
-        ret = ocall_map_untrusted(handle->file.fd, offset, size, HOST_PROT(prot), &mem);
+        ret = ocall_mmap_untrusted(handle->file.fd, offset, size, HOST_PROT(prot), &mem);
         if (!IS_ERR(ret))
             *addr = mem;
         return IS_ERR(ret) ? unix_to_pal_error(ERRNO(ret)) : ret;
@@ -240,7 +240,7 @@ static int file_map(PAL_HANDLE handle, void** addr, int prot, uint64_t offset, u
         map_end   = ALLOC_ALIGNUP(end);
     }
 
-    ret = ocall_map_untrusted(handle->file.fd, map_start, map_end - map_start, PROT_READ, &umem);
+    ret = ocall_mmap_untrusted(handle->file.fd, map_start, map_end - map_start, PROT_READ, &umem);
     if (IS_ERR(ret)) {
         SGX_DBG(DBG_E, "file_map - ocall returned %d\n", ret);
         return unix_to_pal_error(ERRNO(ret));
@@ -252,14 +252,14 @@ static int file_map(PAL_HANDLE handle, void** addr, int prot, uint64_t offset, u
 
         if (ret < 0) {
             SGX_DBG(DBG_E, "file_map - verify trusted returned %d\n", ret);
-            ocall_unmap_untrusted(umem, map_end - map_start);
+            ocall_munmap_untrusted(umem, map_end - map_start);
             return ret;
         }
     } else {
         memcpy(mem, umem + (offset - map_start), end - offset);
     }
 
-    ocall_unmap_untrusted(umem, map_end - map_start);
+    ocall_munmap_untrusted(umem, map_end - map_start);
     *addr = mem;
     return 0;
 }

+ 1 - 1
Pal/src/host/Linux-SGX/db_memory.c

@@ -110,7 +110,7 @@ int _DkVirtualMemoryFree (void * addr, uint64_t size)
     } else {
         /* Possible to have untrusted mapping. Simply unmap
            the memory outside the enclave */
-        ocall_unmap_untrusted(addr, size);
+        ocall_munmap_untrusted(addr, size);
     }
     return 0;
 }

+ 4 - 4
Pal/src/host/Linux-SGX/db_rtld.c

@@ -65,9 +65,9 @@ void _DkDebugAddMap (struct link_map * map)
         unsigned long s = ALLOC_ALIGNDOWN(ehdr->e_shoff);
         unsigned long e = ALLOC_ALIGNUP(ehdr->e_shoff + shdrsz);
         void * umem;
-        ocall_map_untrusted(fd, s, e - s, PROT_READ, &umem);
+        ocall_mmap_untrusted(fd, s, e - s, PROT_READ, &umem);
         memcpy(shdr, umem + ehdr->e_shoff - s, shdrsz);
-        ocall_unmap_untrusted(umem, e - s);
+        ocall_munmap_untrusted(umem, e - s);
     }
 
     ElfW(Shdr) * shdrend = (void *) shdr + shdrsz;
@@ -89,9 +89,9 @@ void _DkDebugAddMap (struct link_map * map)
         unsigned long s = ALLOC_ALIGNDOWN(shstroff);
         unsigned long e = ALLOC_ALIGNUP(shstroff + shstrsz);
         void * umem;
-        ocall_map_untrusted(fd, s, e - s, PROT_READ, &umem);
+        ocall_mmap_untrusted(fd, s, e - s, PROT_READ, &umem);
         memcpy((void *) shstrtab, umem + shstroff - s, shstrsz);
-        ocall_unmap_untrusted(umem, e - s);
+        ocall_munmap_untrusted(umem, e - s);
     }
 
     ocall_close(fd);

+ 2 - 2
Pal/src/host/Linux-SGX/enclave_framework.c

@@ -384,7 +384,7 @@ int load_trusted_file (PAL_HANDLE file, sgx_stub_t ** stubptr,
         if (ret < 0)
             goto failed;
 
-        ret = ocall_map_untrusted(fd, offset, mapping_size, PROT_READ, &umem);
+        ret = ocall_mmap_untrusted(fd, offset, mapping_size, PROT_READ, &umem);
         if (IS_ERR(ret)) {
             ret = unix_to_pal_error(ERRNO(ret));
             goto unmap;
@@ -423,7 +423,7 @@ int load_trusted_file (PAL_HANDLE file, sgx_stub_t ** stubptr,
         /* Store the checksum for one file chunk for checking */
         ret = lib_AESCMACFinish(&aes_cmac, (uint8_t *) s, sizeof *s);
 unmap:
-        ocall_unmap_untrusted(umem, mapping_size);
+        ocall_munmap_untrusted(umem, mapping_size);
         if (ret < 0)
             goto failed;
     }

+ 15 - 15
Pal/src/host/Linux-SGX/enclave_ocalls.c

@@ -61,12 +61,12 @@ int ocall_alloc_untrusted (uint64_t size, void ** mem)
     return retval;
 }
 
-int ocall_map_untrusted (int fd, uint64_t offset,
+int ocall_mmap_untrusted (int fd, uint64_t offset,
                          uint64_t size, unsigned short prot,
                          void ** mem)
 {
     int retval = 0;
-    ms_ocall_map_untrusted_t * ms;
+    ms_ocall_mmap_untrusted_t * ms;
 
     ms = sgx_alloc_on_ustack(sizeof(*ms));
     if (!ms) {
@@ -79,7 +79,7 @@ int ocall_map_untrusted (int fd, uint64_t offset,
     ms->ms_size = size;
     ms->ms_prot = prot;
 
-    retval = sgx_ocall(OCALL_MAP_UNTRUSTED, ms);
+    retval = sgx_ocall(OCALL_MMAP_UNTRUSTED, ms);
 
     if (!retval) {
         if (!sgx_copy_ptr_to_enclave(mem, ms->ms_mem, size)) {
@@ -92,10 +92,10 @@ int ocall_map_untrusted (int fd, uint64_t offset,
     return retval;
 }
 
-int ocall_unmap_untrusted (const void * mem, uint64_t size)
+int ocall_munmap_untrusted (const void * mem, uint64_t size)
 {
     int retval = 0;
-    ms_ocall_unmap_untrusted_t * ms;
+    ms_ocall_munmap_untrusted_t * ms;
 
     if (!sgx_is_completely_outside_enclave(mem, size)) {
         sgx_reset_ustack();
@@ -111,7 +111,7 @@ int ocall_unmap_untrusted (const void * mem, uint64_t size)
     ms->ms_mem  = mem;
     ms->ms_size = size;
 
-    retval = sgx_ocall(OCALL_UNMAP_UNTRUSTED, ms);
+    retval = sgx_ocall(OCALL_MUNMAP_UNTRUSTED, ms);
 
     sgx_reset_ustack();
     return retval;
@@ -233,7 +233,7 @@ int ocall_read (int fd, void * buf, unsigned int count)
 out:
     sgx_reset_ustack();
     if (obuf)
-        ocall_unmap_untrusted(obuf, ALLOC_ALIGNUP(count));
+        ocall_munmap_untrusted(obuf, ALLOC_ALIGNUP(count));
     return retval;
 }
 
@@ -283,7 +283,7 @@ int ocall_write (int fd, const void * buf, unsigned int count)
 out:
     sgx_reset_ustack();
     if (obuf && obuf != buf)
-        ocall_unmap_untrusted(obuf, ALLOC_ALIGNUP(count));
+        ocall_munmap_untrusted(obuf, ALLOC_ALIGNUP(count));
     return retval;
 }
 
@@ -786,7 +786,7 @@ int ocall_sock_recv (int sockfd, void * buf, unsigned int count,
 out:
     sgx_reset_ustack();
     if (obuf)
-        ocall_unmap_untrusted(obuf, ALLOC_ALIGNUP(count));
+        ocall_munmap_untrusted(obuf, ALLOC_ALIGNUP(count));
     return retval;
 }
 
@@ -839,7 +839,7 @@ int ocall_sock_send (int sockfd, const void * buf, unsigned int count,
 out:
     sgx_reset_ustack();
     if (obuf && obuf != buf)
-        ocall_unmap_untrusted(obuf, ALLOC_ALIGNUP(count));
+        ocall_munmap_untrusted(obuf, ALLOC_ALIGNUP(count));
     return retval;
 }
 
@@ -1162,7 +1162,7 @@ int ocall_get_attestation (const sgx_spid_t* spid, const char* subkey, bool link
             goto reset;
         }
 
-        // For calling ocall_unmap_untrusted, need to reset the untrusted stack
+        // For calling ocall_munmap_untrusted, need to reset the untrusted stack
         sgx_reset_ustack();
 
         // Copy each field inside and free the untrusted buffers
@@ -1171,7 +1171,7 @@ int ocall_get_attestation (const sgx_spid_t* spid, const char* subkey, bool link
             sgx_quote_t* quote = malloc(len);
             if (!sgx_copy_to_enclave(quote, len, attestation->quote, len))
                 retval = -EACCES;
-            ocall_unmap_untrusted(attestation->quote, ALLOC_ALIGNUP(len));
+            ocall_munmap_untrusted(attestation->quote, ALLOC_ALIGNUP(len));
             attestation->quote = quote;
         }
 
@@ -1180,7 +1180,7 @@ int ocall_get_attestation (const sgx_spid_t* spid, const char* subkey, bool link
             char* ias_report = malloc(len + 1);
             if (!sgx_copy_to_enclave(ias_report, len, attestation->ias_report, len))
                 retval = -EACCES;
-            ocall_unmap_untrusted(attestation->ias_report, ALLOC_ALIGNUP(len));
+            ocall_munmap_untrusted(attestation->ias_report, ALLOC_ALIGNUP(len));
             ias_report[len] = 0; // Ensure null-ending
             attestation->ias_report = ias_report;
         }
@@ -1190,7 +1190,7 @@ int ocall_get_attestation (const sgx_spid_t* spid, const char* subkey, bool link
             uint8_t* ias_sig = malloc(len);
             if (!sgx_copy_to_enclave(ias_sig, len, attestation->ias_sig, len))
                 retval = -EACCES;
-            ocall_unmap_untrusted(attestation->ias_sig, ALLOC_ALIGNUP(len));
+            ocall_munmap_untrusted(attestation->ias_sig, ALLOC_ALIGNUP(len));
             attestation->ias_sig = ias_sig;
         }
 
@@ -1199,7 +1199,7 @@ int ocall_get_attestation (const sgx_spid_t* spid, const char* subkey, bool link
             char* ias_certs = malloc(len + 1);
             if (!sgx_copy_to_enclave(ias_certs, len, attestation->ias_certs, len))
                 retval = -EACCES;
-            ocall_unmap_untrusted(attestation->ias_certs, ALLOC_ALIGNUP(len));
+            ocall_munmap_untrusted(attestation->ias_certs, ALLOC_ALIGNUP(len));
             ias_certs[len] = 0; // Ensure null-ending
             attestation->ias_certs = ias_certs;
         }

+ 2 - 2
Pal/src/host/Linux-SGX/enclave_ocalls.h

@@ -12,11 +12,11 @@ noreturn void ocall_exit (int exitcode, int is_exitgroup);
 
 int ocall_alloc_untrusted (uint64_t size, void ** mem);
 
-int ocall_map_untrusted (int fd, uint64_t offset,
+int ocall_mmap_untrusted (int fd, uint64_t offset,
                          uint64_t size, unsigned short prot,
                          void ** mem);
 
-int ocall_unmap_untrusted (const void * mem, uint64_t size);
+int ocall_munmap_untrusted (const void * mem, uint64_t size);
 
 int ocall_cpuid (unsigned int leaf, unsigned int subleaf,
                  unsigned int values[4]);

+ 1 - 1
Pal/src/host/Linux-SGX/enclave_untrusted.c

@@ -39,7 +39,7 @@ static inline void* __malloc(int size) {
 #define system_malloc(size) __malloc(size)
 
 static inline void __free(void* addr, int size) {
-    ocall_unmap_untrusted(addr, size);
+    ocall_munmap_untrusted(addr, size);
 }
 
 #define system_free(addr, size) __free(addr, size)

+ 4 - 4
Pal/src/host/Linux-SGX/ocall_types.h

@@ -22,8 +22,8 @@ typedef int (*sgx_ocall_fn_t)(void*);
 enum {
     OCALL_EXIT = 0,
     OCALL_ALLOC_UNTRUSTED,
-    OCALL_MAP_UNTRUSTED,
-    OCALL_UNMAP_UNTRUSTED,
+    OCALL_MMAP_UNTRUSTED,
+    OCALL_MUNMAP_UNTRUSTED,
     OCALL_CPUID,
     OCALL_OPEN,
     OCALL_CLOSE,
@@ -78,12 +78,12 @@ typedef struct {
     uint64_t ms_size;
     unsigned short ms_prot;
     void * ms_mem;
-} ms_ocall_map_untrusted_t;
+} ms_ocall_mmap_untrusted_t;
 
 typedef struct {
     const void * ms_mem;
     uint64_t ms_size;
-} ms_ocall_unmap_untrusted_t;
+} ms_ocall_munmap_untrusted_t;
 
 typedef struct {
     unsigned int ms_leaf;

+ 8 - 8
Pal/src/host/Linux-SGX/sgx_enclave.c

@@ -59,11 +59,11 @@ static int sgx_ocall_alloc_untrusted(void * pms)
     return 0;
 }
 
-static int sgx_ocall_map_untrusted(void * pms)
+static int sgx_ocall_mmap_untrusted(void * pms)
 {
-    ms_ocall_map_untrusted_t * ms = (ms_ocall_map_untrusted_t *) pms;
+    ms_ocall_mmap_untrusted_t * ms = (ms_ocall_mmap_untrusted_t *) pms;
     void * addr;
-    ODEBUG(OCALL_MAP_UNTRUSTED, ms);
+    ODEBUG(OCALL_MMAP_UNTRUSTED, ms);
     addr = (void *) INLINE_SYSCALL(mmap, 6, NULL, ms->ms_size,
                                    ms->ms_prot,
                                    MAP_FILE|MAP_SHARED,
@@ -75,10 +75,10 @@ static int sgx_ocall_map_untrusted(void * pms)
     return 0;
 }
 
-static int sgx_ocall_unmap_untrusted(void * pms)
+static int sgx_ocall_munmap_untrusted(void * pms)
 {
-    ms_ocall_unmap_untrusted_t * ms = (ms_ocall_unmap_untrusted_t *) pms;
-    ODEBUG(OCALL_UNMAP_UNTRUSTED, ms);
+    ms_ocall_munmap_untrusted_t * ms = (ms_ocall_munmap_untrusted_t *) pms;
+    ODEBUG(OCALL_MUNMAP_UNTRUSTED, ms);
     INLINE_SYSCALL(munmap, 2, ALLOC_ALIGNDOWN(ms->ms_mem),
                    ALLOC_ALIGNUP(ms->ms_mem + ms->ms_size) -
                    ALLOC_ALIGNDOWN(ms->ms_mem));
@@ -690,8 +690,8 @@ static int sgx_ocall_get_attestation(void* pms) {
 sgx_ocall_fn_t ocall_table[OCALL_NR] = {
         [OCALL_EXIT]            = sgx_ocall_exit,
         [OCALL_ALLOC_UNTRUSTED] = sgx_ocall_alloc_untrusted,
-        [OCALL_MAP_UNTRUSTED]   = sgx_ocall_map_untrusted,
-        [OCALL_UNMAP_UNTRUSTED] = sgx_ocall_unmap_untrusted,
+        [OCALL_MMAP_UNTRUSTED]  = sgx_ocall_mmap_untrusted,
+        [OCALL_MUNMAP_UNTRUSTED]= sgx_ocall_munmap_untrusted,
         [OCALL_CPUID]           = sgx_ocall_cpuid,
         [OCALL_OPEN]            = sgx_ocall_open,
         [OCALL_CLOSE]           = sgx_ocall_close,