Skip to content

Commit

Permalink
- fin
Browse files Browse the repository at this point in the history
  • Loading branch information
nshyrei committed Mar 6, 2024
1 parent db29630 commit d6c65dc
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 66 deletions.
26 changes: 2 additions & 24 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions intel-sgx/dcap-ql/src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ extern crate libc;

extern crate sgxs_loaders;

use failure::Error;
use anyhow::Error;
use anyhow::anyhow;
use num_traits::FromPrimitive;

pub use self::dcap_ql_sys::Quote3Error;
Expand Down Expand Up @@ -76,7 +77,7 @@ pub fn is_loaded() -> bool {
/// Since DCAP is being used, assume that no EINITTOKEN provider is necessary.
pub fn enclave_loader() -> Result<EnclaveCommonLibrary, Error> {
#[cfg(not(feature = "link"))]
dl::load().map_err(failure::err_msg)?;
dl::load().map_err(|e| anyhow!(e))?;
// NB. libsgx_dcap_ql.so.1 transitively links to libsgx_enclave_common.so.1
// so we should be able to find it already loaded.
// We can't use the library from `mod dl` if `not(feature = "link")`,
Expand Down
7 changes: 3 additions & 4 deletions intel-sgx/enclave-runner/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use std::path::Path;
use std::{arch, str};

use thiserror::Error as ThisError;
use anyhow::Context;
use anyhow::anyhow;
use anyhow::{Context, format_err};

#[cfg(feature = "crypto-openssl")]
use openssl::{
Expand Down Expand Up @@ -167,7 +166,7 @@ impl<'a> EnclaveBuilder<'a> {
let mut enclave = self.enclave.try_clone().unwrap();
let hash = match self.hash_enclave.take() {
Some(f) => f(&mut enclave)?,
None => return Err(anyhow!("either compile with default features or use with_dummy_signature_signer()"))
None => return Err(format_err!("either compile with default features or use with_dummy_signature_signer()"))
};
let mut signer = Signer::new(hash);

Expand All @@ -185,7 +184,7 @@ impl<'a> EnclaveBuilder<'a> {

match self.load_and_sign.take() {
Some(f) => f(signer),
None => Err(anyhow!("either compile with default features or use with_dummy_signature_signer()"))
None => Err(format_err!("either compile with default features or use with_dummy_signature_signer()"))
}
}

Expand Down
17 changes: 9 additions & 8 deletions intel-sgx/fortanix-sgx-tools/src/bin/ftxsgx-elf2sgxs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::num::ParseIntError;
use std::path::{Path, PathBuf};

use crate::anyhow::Context;
use anyhow::anyhow;

use xmas_elf::dynamic::{Dynamic as DynEntry, Tag as DynTag};
use xmas_elf::header::Class as HeaderClass;
Expand Down Expand Up @@ -127,13 +128,13 @@ macro_rules! read_syms {
$(let mut $optional_name=None;)*
for sym in $syms.iter().skip(1) {
if sym.shndx()==SHN_UNDEF {
bail!("Found undefined dynamic symbol: {}", sym.get_name(&$elf).map_err(err_msg)?);
} $(else if sym.get_name(&$elf).map_err(err_msg)?==stringify!($mandatory_name) {
bail!("Found undefined dynamic symbol: {}", sym.get_name(&$elf).map_err(|e| anyhow!(e))?);
} $(else if sym.get_name(&$elf).map_err(|e| anyhow!(e))?==stringify!($mandatory_name) {
if replace(&mut $mandatory_name,Some(sym)).is_some() {
bail!("Found symbol twice: {}", stringify!($mandatory_name));
}
})*
$(else if sym.get_name(&$elf).map_err(err_msg)?==stringify!($optional_name) {
$(else if sym.get_name(&$elf).map_err(|e| anyhow!(e))?==stringify!($optional_name) {
if replace(&mut $optional_name,Some(sym)).is_some() {
bail!("Found symbol twice: {}", stringify!($optional_name));
}
Expand Down Expand Up @@ -222,7 +223,7 @@ impl<'a> LayoutInfo<'a> {
.ok_or_else(|| format_err!("Could not find dynamic symbol table!"))?;

let syms =
if let SectionData::DynSymbolTable64(syms) = dynsym.get_data(&elf).map_err(err_msg)? {
if let SectionData::DynSymbolTable64(syms) = dynsym.get_data(&elf).map_err(|e| anyhow!(e))? {
syms
} else {
bail!(".dynsym section is not a dynamic symbol table!");
Expand Down Expand Up @@ -290,7 +291,7 @@ impl<'a> LayoutInfo<'a> {
.find(|ph| ph.get_type() == Ok(PhType::Dynamic))
.ok_or_else(|| format_err!("Could not found dynamic section!"))?;

let dyns = if let SegmentData::Dynamic64(dyns) = dynh.get_data(&elf).map_err(err_msg)? {
let dyns = if let SegmentData::Dynamic64(dyns) = dynh.get_data(&elf).map_err(|e| anyhow!(e))? {
dyns
} else {
bail!("PT_DYNAMIC segment is not a dynamic section!")
Expand All @@ -300,7 +301,7 @@ impl<'a> LayoutInfo<'a> {
let mut relacount = None;

for dynamic in dyns {
match dynamic.get_tag().map_err(err_msg)? {
match dynamic.get_tag().map_err(|e| anyhow!(e))? {
// 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 Down Expand Up @@ -347,7 +348,7 @@ impl<'a> LayoutInfo<'a> {

let mut count = 0;
for section in elf.section_iter() {
if let SectionData::Rela64(relas) = section.get_data(&elf).map_err(err_msg)? {
if let SectionData::Rela64(relas) = section.get_data(&elf).map_err(|e| anyhow!(e))? {
count += relas.len();
for rela in relas {
let shind = rela.get_symbol_table_index();
Expand Down Expand Up @@ -501,7 +502,7 @@ impl<'a> LayoutInfo<'a> {
let base = start & !0xfff;
let mut end = start + ph.mem_size();
let base_data;
if let SegmentData::Undefined(data) = ph.get_data(&self.elf).map_err(err_msg)? {
if let SegmentData::Undefined(data) = ph.get_data(&self.elf).map_err(|e| anyhow!(e))? {
base_data = data;
} else {
// Reachable if xmas-elf changes definition of SegmentData
Expand Down
4 changes: 2 additions & 2 deletions intel-sgx/sgxs-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ regex = "1" # MIT/Apache-2.0
num = "0.2" # MIT/Apache-2.0
byteorder = "1.1.0" # Unlicense/MIT
openssl = "0.10" # Apache-2.0
failure = "0.1.1" # MIT/Apache-2.0
failure_derive = "0.1.1" # MIT/Apache-2.0
anyhow = "1.0" # MIT/Apache-2.0
thiserror = "1.0" # MIT/Apache-2.0
crypto-hash = "0.3" # MIT
log = "0.4" # MIT/Apache-2.0
env_logger = "0.6" # MIT/Apache-2.0
Expand Down
13 changes: 6 additions & 7 deletions intel-sgx/sgxs-tools/src/bin/sgxs-append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
extern crate byteorder;
extern crate sgx_isa;
extern crate sgxs as sgxs_crate;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate failure_derive;
extern crate anyhow;
extern crate thiserror;

use std::borrow::Cow;
use std::cell::RefCell;
Expand All @@ -22,16 +20,17 @@ use std::ops::{Deref, DerefMut};
use std::rc::Rc;

use byteorder::{LittleEndian, WriteBytesExt};
use failure::{Error, ResultExt};

use sgx_isa::{PageType, SecinfoFlags};
use crate::sgxs_crate::sgxs::{
CanonicalSgxsReader, Meas, PageChunk, SecinfoTruncated, SgxsRead, SgxsWrite,
};
use crate::sgxs_crate::util::size_fit_natural;
use anyhow::{Context, Error, bail, format_err};
use thiserror::Error as ThisError;

#[derive(Debug, Fail)]
#[fail(display = "Usage error")]
#[derive(Debug, ThisError)]
#[error("Usage error")]
struct UsageError(Cow<'static, str>);

struct NamedFile {
Expand Down
4 changes: 2 additions & 2 deletions intel-sgx/sgxs-tools/src/sgx_detect/imp/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::PathBuf;
use std::process::Command;

use byteorder::{ReadBytesExt, LE};
use failure::{Error, Fail, ResultExt};
use anyhow::{bail, Error, Context, anyhow};

use crate::DetectError;
use crate::interpret::{AesmStatus, KmodStatus};
Expand Down Expand Up @@ -41,7 +41,7 @@ pub fn rdmsr(address: u64) -> Result<u64, Error> {
modprobe_msr().context("Failed to load MSR kernel module")?;
continue;
}
Err(e) => bail!(e.context("Failed to open MSR device")),
Err(e) => bail!(anyhow!(e).context("Failed to open MSR device")),
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions intel-sgx/sgxs-tools/src/sgx_detect/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
#[macro_use]
extern crate log;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate failure_derive;

extern crate anyhow;
extern crate thiserror;
#[macro_use]
extern crate mopa;
#[macro_use]
Expand All @@ -52,7 +51,6 @@ use std::rc::Rc;
use std::process::Command;
use std::io::{self, BufRead, Error as IOError, ErrorKind};
use reqwest;
use failure::Error;
use yansi::Paint;
use aesm_client::AesmClient;
use sgx_isa::{Sigstruct, Attributes, Einittoken};
Expand All @@ -63,6 +61,8 @@ use sgxs_loaders::isgx::Device as SgxDevice;
use sgxs_loaders::enclaveapi::Sgx as SgxDevice;
use sgxs_loaders::sgx_enclave_common::Library as EnclCommonLib;
use proc_mounts::MountList;
use anyhow::{bail, Error, format_err};
use thiserror::Error as ThisError;

mod interpret;
#[cfg(windows)]
Expand All @@ -79,15 +79,15 @@ mod tests;
use crate::interpret::*;
use crate::tests::Tests;

#[derive(Debug, Fail)]
#[derive(Debug, ThisError)]
enum DetectError {
#[fail(display = "CPUID leaf {:x}h is not valid", leaf)]
#[error("CPUID leaf {:x}h is not valid", leaf)]
CpuidLeafInvalid { leaf: u32 },
#[fail(display = "Failed access EFI variables")]
EfiFsError(#[cause] io::Error),
#[fail(display = "Failed to read EFI variable")]
EfiVariableError(#[cause] io::Error),
#[fail(display = "Not available when using JSON tests")]
#[error("Failed access EFI variables")]
EfiFsError(#[source] io::Error),
#[error("Failed to read EFI variable")]
EfiVariableError(#[source] io::Error),
#[error("Not available when using JSON tests")]
NotAvailableInTest,
}

Expand All @@ -104,7 +104,7 @@ fn cpuid(eax: u32, ecx: u32) -> Result<CpuidResult, Error> {
mod detect_result {
use std::rc::Rc;

use failure::{Error, err_msg};
use anyhow::{Error, anyhow};
use serde::ser::{Serialize, Serializer};
use serde::de::{Deserialize, Deserializer};

Expand All @@ -115,7 +115,7 @@ mod detect_result {
pub fn deserialize<'de, T: Deserialize<'de>, D: Deserializer<'de>>(deserializer: D) -> Result<Result<T, Rc<Error>>, D::Error> {
match Result::<T, String>::deserialize(deserializer) {
Ok(Ok(v)) => Ok(Ok(v)),
Ok(Err(e)) => Ok(Err(Rc::new(err_msg(e)))),
Ok(Err(e)) => Ok(Err(Rc::new(anyhow!(e)))),
Err(e) => Err(e),
}
}
Expand Down Expand Up @@ -168,7 +168,7 @@ struct FailTrace<'a>(pub &'a Error);
impl<'a> fmt::Display for FailTrace<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.0)?;
for cause in self.0.iter_causes() {
for cause in self.0.chain() {
write!(fmt, "\ncause: {}", cause)?;
}
Ok(())
Expand Down Expand Up @@ -267,7 +267,7 @@ impl SgxSupport {
while let Some(p) = path.parent() {
if let Some(mount_info) = mount_list.0.iter().find(|&x| x.dest == p) {
if mount_info.options.iter().any(|o| o == "noexec") {
return Err(failure::format_err!("{:?} mounted with `noexec` option", mount_info.dest));
return Err(format_err!("{:?} mounted with `noexec` option", mount_info.dest));
}
}
path = p;
Expand Down
3 changes: 2 additions & 1 deletion intel-sgx/sgxs-tools/src/sgx_detect/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ use std::io::ErrorKind;
use std::io::Error as IoError;
use std::process;

use failure::Error;
use anyhow::Error;
use petgraph::visit::EdgeRef;

use enclave_runner::EnclaveBuilder;
use report_test::ReportBuilder;
use sgx_isa::{Attributes, AttributesFlags, Miscselect, Sigstruct};
use sgxs::loader::Load;
use anyhow::format_err;

mod debug;
#[macro_use]
Expand Down

0 comments on commit d6c65dc

Please sign in to comment.