You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@teaclave.apache.org by "Hiroki (Haobin) Chen" <no...@github.com.INVALID> on 2023/05/17 02:39:08 UTC

[apache/incubator-teaclave-sgx-sdk] Multi-threading mode causes `EnclaveLost` (Issue #432)

Hi all, recently I am using SDK to develop a simple multi-threading program, but sometimes ECall would fail. The branch we use is `v2.0.0-preview`.

# Steps to reproduce:

I used a modified code from `incubator-teaclave-sgx-sdk/samplecode/helloworld/app/src/main.rs`:

```rust

fn main() {
    let enclave = match SgxEnclave::create(ENCLAVE_FILE, true) {
        Ok(enclave) => {
            println!("[+] Init Enclave Successful {}!", enclave.eid());
            enclave
        }
        Err(err) => {
            println!("[-] Init Enclave Failed {}!", err.as_str());
            return;
        }
    };

    // let enclave = Arc::new(enclave);

    loop {
        let mut v = vec![];
        for _ in 0..16 {
            let eid = enclave.eid();

            let handle = thread::spawn(move || {
                let input_string =
                    String::from("This is a normal world string passed into Enclave!\n");
                let mut retval = SgxStatus::Success;

                let result = unsafe {
                    say_something(
                        eid,
                        &mut retval,
                        input_string.as_ptr() as *const u8,
                        input_string.len(),
                    )
                };
                match result {
                    SgxStatus::Success => println!("[+] ECall Success..."),
                    _ => println!("[-] ECall Enclave Failed {}!", result.as_str()),
                }
            });
            v.push(handle);
        }

        for handle in v {
            handle.join().unwrap();
        }
    }
}
```

The enclave's configuration is

```xml
<EnclaveConfiguration>
  <ProdID>0</ProdID>
  <ISVSVN>0</ISVSVN>
  <StackMaxSize>0x40000</StackMaxSize>
  <HeapMaxSize>0x1000000</HeapMaxSize>
  <TCSNum>32</TCSNum>
  <TCSPolicy>1</TCSPolicy>
  <DisableDebug>0</DisableDebug>
  <MiscSelect>0</MiscSelect>
  <MiscMask>0xFFFFFFFF</MiscMask>
</EnclaveConfiguration>
```

The output is

```sh
$ SGX_MOED=HW make && cd bin && ./app
# Previous outputs omitted.
This is a normal world string passed into Enclave!
This is a normal world string passed into Enclave!
This is a in-Enclave Rust string!
[+] ECall Success...
This is a in-Enclave Rust string!
[+] ECall Success...
[-] ECall Enclave Failed EnclaveLost!
```

I wonder where the root cause of this issue is. Is this caused by Rust SGX SDK or Intel's SDK? Thanks in advance!

-- 
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/432
You are receiving this because you are subscribed to this thread.

Message ID: <ap...@github.com>

Re: [apache/incubator-teaclave-sgx-sdk] Multi-threading mode causes `EnclaveLost` (Issue #432)

Posted by "Hiroki (Haobin) Chen" <no...@github.com.INVALID>.
@mssun, could you help with this? Thank you!

-- 
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/432#issuecomment-1550605902
You are receiving this because you are subscribed to this thread.

Message ID: <ap...@github.com>

Re: [apache/incubator-teaclave-sgx-sdk] Multi-threading mode causes `EnclaveLost` (Issue #432)

Posted by "Hiroki (Haobin) Chen" <no...@github.com.INVALID>.
This error was fixed by increasing the EPC size, although it seemed irrelevant to the memory size. The error was also reported to Intel.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/432#issuecomment-1553935231
You are receiving this because you are subscribed to this thread.

Message ID: <ap...@github.com>

Re: [apache/incubator-teaclave-sgx-sdk] Multi-threading mode causes `EnclaveLost` (Issue #432)

Posted by "Hiroki (Haobin) Chen" <no...@github.com.INVALID>.
Closed #432 as completed.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/432#event-9285299549
You are receiving this because you are subscribed to this thread.

Message ID: <ap...@github.com>