Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello-world exits with Init(Io(Os { code: 22, kind: InvalidInput, message: "Invalid argument" })) error #526

Closed
pbeza opened this issue Sep 6, 2023 · 4 comments

Comments

@pbeza
Copy link

pbeza commented Sep 6, 2023

I'm trying to run hello-world as described in the README but I'm getting the following error:

$ cargo run --target x86_64-fortanix-unknown-sgx
   Compiling hello-world v0.1.0 (/tmp/hello-world)
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `ftxsgx-runner-cargo target/x86_64-fortanix-unknown-sgx/debug/hello-world`
Error: Init(Io(Os { code: 22, kind: InvalidInput, message: "Invalid argument" }))

While loading SGX enclave
ERROR: while running "ftxsgx-runner" "target/x86_64-fortanix-unknown-sgx/debug/hello-world.sgxs" got exit status: 1

Any idea what I'm doing wrong?

Full log:

$ RUST_BACKTRACE=1 cargo run --target x86_64-fortanix-unknown-sgx
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `ftxsgx-runner-cargo target/x86_64-fortanix-unknown-sgx/debug/hello-world`
Error: Init(Io(Os { code: 22, kind: InvalidInput, message: "Invalid argument" }))

   0: failure::backtrace::Backtrace::new
   1: <failure::error::error_impl::ErrorImpl as core::convert::From<F>>::from
   2: sgxs_loaders::generic::Device<D>::load
   3: enclave_runner::loader::EnclaveBuilder::build
   4: ftxsgx_runner::main
   5: std::sys_common::backtrace::__rust_begin_short_backtrace
   6: std::rt::lang_start::{{closure}}
   7: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:284:13
      std::panicking::try::do_call
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:500:40
      std::panicking::try
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:464:19
      std::panic::catch_unwind
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal::{{closure}}
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:148:48
      std::panicking::try::do_call
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:500:40
      std::panicking::try
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:464:19
      std::panic::catch_unwind
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:148:20
   8: main
   9: <unknown>
  10: __libc_start_main
  11: _start


While loading SGX enclave
ERROR: while running "ftxsgx-runner" "target/x86_64-fortanix-unknown-sgx/debug/hello-world.sgxs" got exit status: 1

sgx-detect output:

$ sudo $(which sgx-detect) --verbose
Detecting SGX, this may take a minute...
✔  SGX instruction set
  ✔  CPU support
  ✔  CPU configuration
  ✔  Enclave attributes
  ✔  Enclave Page Cache
  SGX features
    ✔  SGX2  ✔  EXINFO  ✘  ENCLV  ✘  OVERSUB  ✔  KSS
    Total EPC size: 32.0GiB (no integrity protection)
✔  Flexible launch control
  ✔  CPU support
  ✔  CPU configuration
  ✔  Able to launch production mode enclave
✘  SGX system software
  ✔  SGX kernel device (/dev/sgx_enclave)
  ✔  libsgx_enclave_common
  ✔  AESM service
  ✘  Able to launch enclaves
    ✘  Debug mode
    ✔  Production mode

🕮  SGX system software > Able to launch enclaves > Debug mode
The enclave could not be launched.

debug: failed to load report enclave
debug: cause: Failed to call EINIT.
debug: cause: I/O ctl failed.
debug: cause: Invalid argument (os error 22)

More information: https://edp.fortanix.com/docs/installation/help/#run-enclave-debug
@kostko
Copy link

kostko commented Sep 6, 2023

It looks like this is related to the in-kernel SGX driver (a bug preventing debug enclaves from being launched?) and upgrading to Linux 6.5 may fix the issue.

At least that was the case when we encountered a similar issue so do try it out.

@pbeza
Copy link
Author

pbeza commented Sep 6, 2023

Thank you for the quick reply! I was about to update my post with this link claiming what you just mentioned.

I will try to upgrade the kernel on the system I'm using which is Ubuntu 22.04.3 LTS (jammy).

@pbeza
Copy link
Author

pbeza commented Sep 6, 2023

Unbelievable! Running:

sudo apt install linux-oem-22.04d

(that effectively installed Linux kernel version 6.5) and rebooting my machine worked! 🙌🏼

$ cargo new --bin hello-world
     Created binary (application) `hello-world` package
$ cd hello-world/
$ cargo run --target x86_64-fortanix-unknown-sgx
   Compiling hello-world v0.1.0 (/tmp/hello-world)
    Finished dev [unoptimized + debuginfo] target(s) in 0.53s
     Running `ftxsgx-runner-cargo target/x86_64-fortanix-unknown-sgx/debug/hello-world`
Hello, world!

sgx-detect is fixed now too:

$ sgx-detect
Detecting SGX, this may take a minute...
✔  SGX instruction set
  ✔  CPU support
  ✔  CPU configuration
  ✔  Enclave attributes
  ✔  Enclave Page Cache
  SGX features
    ✔  SGX2  ✔  EXINFO  ✘  ENCLV  ✘  OVERSUB  ✔  KSS
    Total EPC size: 32.0GiB (no integrity protection)
✔  Flexible launch control
  ✔  CPU support
  ? CPU configuration
  ✔  Able to launch production mode enclave
✔  SGX system software
  ✔  SGX kernel device (/dev/sgx_enclave)
  ✔  libsgx_enclave_common
  ✔  AESM service
  ✔  Able to launch enclaves
    ✔  Debug mode
    ✔  Production mode
    ✔  Production mode (Intel whitelisted)

You're all set to start running SGX programs!

Thank you @kostko!

@pbeza pbeza closed this as completed Sep 6, 2023
@jethrogb
Copy link
Member

jethrogb commented Sep 7, 2023

https://bugs.launchpad.net/ubuntu/+source/linux-signed-azure-5.15/+bug/2034745

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants