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

How to pass a structure pointer of a recursive structure between Enclave and Untrust memory

wwfbear789
Beginner
1,180 Views

Dear All,

 

I am trying to pass a recursive structure to Untrust memory with Ocall. However, when I try to access the next member of the structure, I get a Segmentation Fault.
What should I do to correctly pass the structure of the recursive structure? I would like to know if anyone can help me.

 

In the sample below, the process transits to the Enclave with ecall_enter(), creates an instance of the recursive structure there, and passes it to the Untrust area with ocall_struct_test_func4.

 

recursive structure in edl (OcallClassTest4)

struct OcallStructTest4 {
        [size=100] char* ident;
        struct OcallStructTest4* next;
};

ecall_enter

void ecall_enter() {
    OcallStructTest4* ocall_struct_test4 = new OcallStructTest4();
    ocall_struct_test4->ident            = "hello struct!";
    ocall_struct_test4->next             = new OcallStructTest4();
    OcallStructTest4* next               = ocall_struct_test4->next;
    next->ident                          = "hello next!!!";
    ocall_struct_test_func4(ocall_struct_test4);
}

 ocall_struct_test_func4

void ocall_struct_test_func4(OcallStructTest4* ocall_struct_test4) {
    std::cout << "ocall struct test func4 start.\n";
    std::cout << ocall_struct_test4->ident << std::endl;

    OcallStructTest4* next = ocall_struct_test4->next;
    std::cout << "next ident" << next->ident << std::endl;
}

ocall definition in edl

void ocall_struct_test_func4([in] struct OcallStructTest4* ocall_struct_test);

Execution result

ocall struct test func4 start.
hello struct!
Segmentation fault

 

0 Kudos
1 Solution
Sahira_Intel
Moderator
1,072 Views

Hi,

No trouble at all.

In the SGX Developer Guide, there is a section on Structure Deep Copy: https://download.01.org/intel-sgx/latest/linux-latest/docs/Intel_SGX_Developer_Reference_Linux_2.17_Open_Source.pdf#page=56

There is a sample there that you can follow that might help


Sincerely,

Sahira




View solution in original post

0 Kudos
5 Replies
Sahira_Intel
Moderator
1,160 Views

Hi,


You might need to increase heap size. Seg fault usually means there is not enough memory allocated to the enclave

Can you please send over your enclave config file so I can take a look.


Sincerely,

Sahira


0 Kudos
wwfbear789
Beginner
1,144 Views

Thanks for the reply!
The config file for Enclave is below (the application I am currently making is based on SampleEnclave from SampleCode, and the config file has not been changed).

Enclave.config.xml

<EnclaveConfiguration>
  <ProdID>0</ProdID>
  <ISVSVN>0</ISVSVN>
  <StackMaxSize>0x40000</StackMaxSize>
  <HeapMaxSize>0x100000</HeapMaxSize>
  <TCSNum>10</TCSNum>
  <TCSPolicy>1</TCSPolicy>
  <!-- Recommend changing 'DisableDebug' to 1 to make the enclave undebuggable for enclave release -->
  <DisableDebug>0</DisableDebug>
  <MiscSelect>0</MiscSelect>
  <MiscMask>0xFFFFFFFF</MiscMask>
</EnclaveConfiguration>

Also, I have a question, is it not possible to access the next referenced data just by passing the pointer of the self-reference structure from the Enclave to the Untrust area (or vice versa)?
Currently I am not able to do that, so I am using a technique such as passing a uint8_t* converted to a byte string. Is there another smarter way?

0 Kudos
Sahira_Intel
Moderator
1,110 Views

Hi,

I have escalated this issue further. I will let you know when I have more information. 

Sincerely,

Sahira 

0 Kudos
wwfbear789
Beginner
1,100 Views

Thanks for the reply!

I am sorry for the trouble. I look forward to hearing back from you.

 

Sincerely

 

wwfbear789

0 Kudos
Sahira_Intel
Moderator
1,073 Views

Hi,

No trouble at all.

In the SGX Developer Guide, there is a section on Structure Deep Copy: https://download.01.org/intel-sgx/latest/linux-latest/docs/Intel_SGX_Developer_Reference_Linux_2.17_Open_Source.pdf#page=56

There is a sample there that you can follow that might help


Sincerely,

Sahira




0 Kudos
Reply