Skip to content

Commit

Permalink
Print specific error message on SIGBUS
Browse files Browse the repository at this point in the history
  • Loading branch information
Jethro Beekman committed Jul 12, 2020
1 parent 0a6df32 commit 6d4987e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions fortanix-sgx-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ serde_derive = "1.0.84" # MIT/Apache-2.0
serde = "1.0.84" # MIT/Apache-2.0
toml = "0.4.10" # MIT/Apache-2.0
num_cpus = "1.9.0" # MIT/Apache-2.0
libc = "0.2.48" # MIT/Apache-2.0
nix = "0.13.0" # MIT
23 changes: 23 additions & 0 deletions fortanix-sgx-tools/src/bin/ftxsgx-runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
#[macro_use]
extern crate clap;

#[cfg(unix)]
use std::io::{stderr, Write};

use aesm_client::AesmClient;
use enclave_runner::EnclaveBuilder;
use failure::{Error, ResultExt};
#[cfg(unix)]
use libc::{c_int, c_void, siginfo_t};
#[cfg(unix)]
use nix::sys::signal;
#[cfg(unix)]
use sgxs_loaders::isgx::Device as IsgxDevice;
#[cfg(windows)]
use sgxs_loaders::enclaveapi::Sgx as IsgxDevice;
Expand All @@ -26,6 +33,20 @@ arg_enum!{
}
}

#[cfg(unix)]
fn catch_sigbus() {
unsafe {
extern "C" fn handle_bus(_signo: c_int, _info: *mut siginfo_t, _context: *mut c_void) {
eprintln!("SIGBUS triggered: likely caused by stack overflow in enclave.");
let _ = stderr().flush();
}

let hdl = signal::SigHandler::SigAction(handle_bus);
let sig_action = signal::SigAction::new(hdl, signal::SaFlags::SA_RESETHAND, signal::SigSet::empty());
signal::sigaction(signal::SIGBUS, &sig_action).unwrap();
}
}

fn main() -> Result<(), Error> {
let args = App::new("ftxsgx-runner")
.arg(
Expand Down Expand Up @@ -57,6 +78,8 @@ fn main() -> Result<(), Error> {

let enclave = enclave_builder.build(&mut device).context("While loading SGX enclave")?;

#[cfg(unix)] catch_sigbus();

enclave.run().map_err(|e| {
eprintln!("Error while executing SGX enclave.\n{}", e);
std::process::exit(-1)
Expand Down

0 comments on commit 6d4987e

Please sign in to comment.