Intel® Software Guard Extensions (Intel® SGX)
Discussion board focused on hardware-based isolation and memory encryption to provide extended code protection in solutions.

File Handling within Enclave

bergmann__Tina
Beginner
1,280 Views

Hi All,

I have the latest linux SGX SDK. I am trying to do "protected" file handling using the sgx_fread, sgx_fopen etc.

My Enclave code compiles well when the header  sgx_tprotected_fs.h is included. 

However the linking stage return "undefined reference to sgx_fread" etc.

What library should be linked ?

Thanks,

Tina

 

0 Kudos
5 Replies
Rodolfo_S_
New Contributor III
1,280 Views

Hi, Tina.

From the Developer Reference, on page 106-107:

To use the Intel SGX Protected File System libraries:
1. The enclave must be linked with libsgx_tprotected_fs.a
2. The application must be linked with libsgx_uprotected_fs.a
3. The enclave’s EDL file must ‘import’ all the functions from sgx_tprotected_fs.edl
4. The source files should ‘include’ sgx_tprotected_fs.h

Regards,

Rodolfo

0 Kudos
bergmann__Tina
Beginner
1,280 Views

Hi ,

 

Thanks. I linked the required libraries as follows. Somehow one lib seems to depend on the other and finally most of the link errors got resolved by having the following libraries linked:

Enclave_Link_Flags += -lsgx_tprotected_fs -lsgx_tservice -lsgx_tcrypto -lsgx_tstdc
 
However I am unable to resolve to resolve this particular error
sgxsdk/lib64/libsgx_tprotected_fs.a(lru_cache.o): In function `std::__1::__hash_table<std::__1::__hash_value_type<unsigned long, _map_node*>, std::__1::__unordered_map_hasher<unsigned long, std::__1::__hash_value_type<unsigned long, _map_node*>, std::__1::hash<unsigned long>, true>, std::__1::__unordered_map_equal<unsigned long, std::__1::__hash_value_type<unsigned long, _map_node*>, std::__1::equal_to<unsigned long>, true>, std::__1::allocator<std::__1::__hash_value_type<unsigned long, _map_node*> > >::rehash(unsigned long)':
lru_cache.cpp:(.text._ZNSt3__112__hash_tableINS_17__hash_value_typeImP9_map_nodeEENS_22__unordered_map_hasherImS4_NS_4hashImEELb1EEENS_21__unordered_map_equalImS4_NS_8equal_toImEELb1EEENS_9allocatorIS4_EEE6rehashEm[_ZNSt3__112__hash_tableINS_17__hash_value_typeImP9_map_nodeEENS_22__unordered_map_hasherImS4_NS_4hashImEELb1EEENS_21__unordered_map_equalImS4_NS_8equal_toImEELb1EEENS_9allocatorIS4_EEE6rehashEm]+0x77): undefined reference to `std::__1::__next_prime(unsigned long)'
lru_cache.cpp:(.text._ZNSt3__112__hash_tableINS_17__hash_value_typeImP9_map_nodeEENS_22__unordered_map_hasherImS4_NS_4hashImEELb1EEENS_21__unordered_map_equalImS4_NS_8equal_toImEELb1EEENS_9allocatorIS4_EEE6rehashEm[_ZNSt3__112__hash_tableINS_17__hash_value_typeImP9_map_nodeEENS_22__unordered_map_hasherImS4_NS_4hashImEELb1EEENS_21__unordered_map_equalImS4_NS_8equal_toImEELb1EEENS_9allocatorIS4_EEE6rehashEm]+0x104): undefined reference to `std::__1::__next_prime(unsigned long)'
collect2: error: ld returned 1 exit status
Infact I searched the SDK and could not find this function std::__1::__next_prime(unsigned long) 
Please help.
 
Thanks,
Tina
 
 
0 Kudos
you_w_
New Contributor III
1,280 Views

Hi bergmann

I have write a demo to show how to use protected fs, You can compare you makefile with mine.

I think the reason is lru_cache needs libc++-dev but you didn't link it.

The project is here :https://github.com/light1021/SGX-protected-fs-demo

Regards

you

0 Kudos
bergmann__Tina
Beginner
1,280 Views

Hi,

Thanks. The project compiles now after adding libc++-dev.

I have one more question. The sgx_fread and sgx_fseek called in my program returns error. I then use sgx_error(fp) to return the error code. However I don't know what these error codes mean. Which header contains errors corresponding to sgx_ferror?I  get a 0x16 as error code.

Thanks once again!

0 Kudos
you_w_
New Contributor III
1,280 Views

Hi :

The errors are usually defined in sgx_error.h. But I didn't find you error code. Error codes related to protected FS are look like 0x700*. So I don't know what 0x16 stands for.

Kind regards

you

0 Kudos
Reply