Skip to content

Commit a41fceb

Browse files
authored
Merge pull request #119 from datachainlab/audit-202409
Audit-202409 Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
2 parents 881682d + c0dce44 commit a41fceb

File tree

35 files changed

+1918
-1371
lines changed

35 files changed

+1918
-1371
lines changed

Cargo.lock

Lines changed: 1574 additions & 1131 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ description = """
99

1010
[dependencies]
1111
log = "0.4.8"
12-
env_logger = "0.9.0"
12+
env_logger = "0.11.5"
1313
hex = { version = "0.4", default-features = false, features = ["alloc"] }
1414
tokio = { version = "1.0", features = ["full"] }
1515
anyhow = { version = "1.0.56" }
16-
clap = { version = "3.2", features = ["derive"] }
16+
clap = { version = "4.5.21", features = ["derive"] }
1717
dirs = "4.0"
1818
serde = { version = "1.0.184", default-features = false, features = ["alloc"] }
1919
serde_json = { version = "1.0", default-features = false, features = ["alloc", "preserve_order"] }
@@ -28,7 +28,7 @@ keymanager = { path = "../modules/keymanager" }
2828
remote-attestation = { path = "../modules/remote-attestation" }
2929

3030
[build-dependencies]
31-
git2 = "0.17"
31+
git2 = "0.19"
3232

3333
[features]
3434
default = []

enclave-modules/ecall-handler/src/enclave_manage/enclave.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ pub(crate) fn generate_enclave_key(
99
input: GenerateEnclaveKeyInput,
1010
) -> Result<GenerateEnclaveKeyResponse, Error> {
1111
let ek = EnclaveKey::new()?;
12-
let sealed_ek = ek.seal()?;
1312
let ek_pub = ek.get_pubkey();
13+
let sealed_ek = ek.seal()?;
1414
let report_data = ReportData::new(ek_pub.as_address(), input.operator);
1515
let report = match rsgx_create_report(&input.target_info, &report_data.into()) {
1616
Ok(r) => r,

enclave-modules/runtime/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ host-api = { path = "../host-api" }
1717
ecall-handler = { path = "../ecall-handler" }
1818
enclave-environment = { path = "../environment" }
1919
ecall-commands = { path = "../../modules/ecall-commands", default-features = false }
20+
21+
[features]
22+
default = []
23+
panic-logging = []

enclave-modules/runtime/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ mod errors;
3131
static ALLOC: sgx_alloc::System = sgx_alloc::System;
3232

3333
#[cfg(not(test))]
34+
#[allow(unused_variables)]
3435
#[panic_handler]
3536
fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
37+
#[cfg(feature = "panic-logging")]
38+
let msg = alloc::format!("[enclave] panic: {:?}\n", info).into_bytes();
39+
#[cfg(not(feature = "panic-logging"))]
40+
let msg = alloc::format!("[enclave] panic\n").into_bytes();
3641
let _ = host_api::api::execute_command(host_api::ocall_commands::Command::Log(
37-
host_api::ocall_commands::LogCommand {
38-
msg: alloc::format!("[enclave] panic: {:?}\n", info).into_bytes(),
39-
},
42+
host_api::ocall_commands::LogCommand { msg },
4043
));
4144
sgx_abort();
4245
}

enclave-modules/utils/src/pointers.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
use log::*;
2-
use sgx_trts::trts::{rsgx_lfence, rsgx_raw_is_outside_enclave, rsgx_sfence};
2+
use sgx_trts::trts::{rsgx_lfence, rsgx_sfence};
33
use sgx_types::*;
44

5+
/// Validates a mutable pointer and its length.
6+
///
7+
/// Assumes that the `ptr` is a valid pointer of enclave outside memory.
58
pub fn validate_mut_ptr(ptr: *mut u8, ptr_len: usize) -> SgxResult<()> {
6-
if rsgx_raw_is_outside_enclave(ptr, ptr_len) {
7-
warn!("Tried to access memory outside enclave -- rsgx_slice_is_outside_enclave");
9+
if ptr.is_null() || ptr_len == 0 {
10+
warn!("Tried to access an empty pointer - ptr.is_null() || ptr_len == 0");
811
return Err(sgx_status_t::SGX_ERROR_UNEXPECTED);
912
}
1013
rsgx_sfence();
1114
Ok(())
1215
}
1316

17+
/// Validates a constant pointer and its length.
18+
///
19+
/// Assumes that the `ptr` is a valid pointer of enclave outside memory.
1420
pub fn validate_const_ptr(ptr: *const u8, ptr_len: usize) -> SgxResult<()> {
1521
if ptr.is_null() || ptr_len == 0 {
16-
warn!("Tried to access an empty pointer - ptr.is_null()");
22+
warn!("Tried to access an empty pointer - ptr.is_null() || ptr_len == 0");
1723
return Err(sgx_status_t::SGX_ERROR_UNEXPECTED);
1824
}
1925
rsgx_lfence();

0 commit comments

Comments
 (0)