Skip to content

Commit

Permalink
Merge #268
Browse files Browse the repository at this point in the history
268: Print specific error message on SIGBUS r=AdrianCX a=jethrogb



Co-authored-by: Jethro Beekman <[email protected]>
  • Loading branch information
bors[bot] and Jethro Beekman authored Jul 16, 2020
2 parents 0eaff6c + 6d4987e commit 981505f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 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.

3 changes: 3 additions & 0 deletions fortanix-sgx-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ documentation = "https://edp.fortanix.com/docs/"
homepage = "https://edp.fortanix.com/"
keywords = ["sgx", "enclave", "ftxsgx-runner"]
categories = ["development-tools::build-utils", "command-line-utilities"]
edition = "2018"

[dependencies]
# Project dependencies
Expand All @@ -33,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
20 changes: 10 additions & 10 deletions fortanix-sgx-tools/src/bin/ftxsgx-elf2sgxs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Splice {
pub struct LayoutInfo<'a> {
elf: ElfFile<'a>,
sym: Symbols<'a>,
dyn: Option<Dynamic<'a>>,
dynamic: Option<Dynamic<'a>>,
ssaframesize: u32,
heap_size: u64,
stack_size: u64,
Expand Down Expand Up @@ -299,8 +299,8 @@ impl<'a> LayoutInfo<'a> {
let mut rela = None;
let mut relacount = None;

for dyn in dyns {
match dyn.get_tag().map_err(err_msg)? {
for dynamic in dyns {
match dynamic.get_tag().map_err(err_msg)? {
// Some entries for PLT/GOT checking are currently
// commented out. I *think* that if there were an actual
// PLT/GOT problem, that would be caught by the remaining
Expand All @@ -313,10 +313,10 @@ impl<'a> LayoutInfo<'a> {
bail!("Unsupported dynamic entry: .fini functions"),
Rel | RelSize | RelEnt | DT_RELCOUNT =>
bail!("Unsupported dynamic entry: relocations with implicit addend"),
Rela => if replace(&mut rela, Some(dyn)).is_some() {
Rela => if replace(&mut rela, Some(dynamic)).is_some() {
bail!("Found dynamic entry twice: DT_RELA")
},
DT_RELACOUNT => if replace(&mut relacount, Some(dyn)).is_some() {
DT_RELACOUNT => if replace(&mut relacount, Some(dynamic)).is_some() {
bail!("Found dynamic entry twice: DT_RELACOUNT")
},
_ => {}
Expand Down Expand Up @@ -396,16 +396,16 @@ impl<'a> LayoutInfo<'a> {
}
Self::check_toolchain_version(&elf)?;
let sym = Self::check_symbols(&elf)?;
let dyn = Self::check_dynamic(&elf)?;
Self::check_relocs(&elf, dyn.as_ref())?;
let dynamic = Self::check_dynamic(&elf)?;
Self::check_relocs(&elf, dynamic.as_ref())?;
let ehfrm = Self::check_section(&elf, ".eh_frame")?;
let ehfrm_hdr = Self::check_section(&elf, ".eh_frame_hdr")?;
let text = Self::check_section(&elf, ".text")?;

Ok(LayoutInfo {
elf,
sym,
dyn,
dynamic,
ssaframesize,
heap_size,
stack_size,
Expand All @@ -432,15 +432,15 @@ impl<'a> LayoutInfo<'a> {
Splice::for_sym_u64(self.sym.HEAP_SIZE, self.heap_size),
Splice::for_sym_u64(
self.sym.RELA,
self.dyn
self.dynamic
.as_ref()
.and_then(|d| d.rela.get_ptr().ok())
.unwrap_or(0),

),
Splice::for_sym_u64(
self.sym.RELACOUNT,
self.dyn
self.dynamic
.as_ref()
.and_then(|d| d.relacount.get_val().ok())
.unwrap_or(0),
Expand Down
27 changes: 23 additions & 4 deletions fortanix-sgx-tools/src/bin/ftxsgx-runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

extern crate aesm_client;
extern crate enclave_runner;
extern crate sgxs_loaders;
extern crate failure;
#[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 @@ -30,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 @@ -61,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 981505f

Please sign in to comment.