Skip to content

Commit 0edaf72

Browse files
bors[bot]ssavvides
andauthored
Merge #339
339: `sgx-detect` support for confidentiality-only protection EPC r=jethrogb a=ssavvides Fixes #332 Co-authored-by: Savvas Savvides <[email protected]>
2 parents 24f7dcd + 2ae8176 commit 0edaf72

File tree

7 files changed

+63
-32
lines changed

7 files changed

+63
-32
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sgxs-tools/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sgxs-tools"
3-
version = "0.8.4"
3+
version = "0.8.5"
44
authors = ["Fortanix, Inc."]
55
license = "MPL-2.0"
66
description = """

sgxs-tools/src/sgx_detect/interpret.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl From<CpuidResult> for Cpuid12h1 {
121121
pub enum EpcType {
122122
Invalid,
123123
ConfidentialityIntegrityProtected,
124+
ConfidentialityProtectedOnly,
124125
Unknown,
125126
}
126127

@@ -146,6 +147,7 @@ impl From<(u32, CpuidResult)> for Cpuid12hEnum {
146147
let ty = match v.ecx & 0xf {
147148
0 => EpcType::Invalid,
148149
1 => EpcType::ConfidentialityIntegrityProtected,
150+
2 => EpcType::ConfidentialityProtectedOnly,
149151
n => {
150152
warn!("CPUID 12h, sub-leaf {} (EPC section) unknown EPC type: {:x}h. EAX={:08x}, EBX={:08x}, ECX={:08x}, EDX={:08x}", subleaf, n, v.eax, v.ebx, v.ecx, v.edx);
151153
EpcType::Unknown
@@ -314,7 +316,7 @@ impl From<Vec<u8>> for EfiSoftwareguardstatus {
314316
pub enum AesmStatus {
315317
Absent,
316318
Installed,
317-
Running
319+
Running,
318320
}
319321

320322
#[derive(Debug, Clone, Default, Serialize, Deserialize)]

sgxs-tools/src/sgx_detect/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl EinittokenProvider for TimeoutHardError<AesmClient> {
219219
}
220220

221221
impl SgxSupport {
222-
fn detect(env_config :tests::EnvConfig) -> Self {
222+
fn detect(env_config: tests::EnvConfig) -> Self {
223223
fn rcerr<T>(v: Result<T, Error>) -> Result<T, Rc<Error>> {
224224
v.map_err(Rc::new)
225225
}
@@ -290,7 +290,7 @@ impl SgxSupport {
290290
let nodeagent_status = (|| {
291291
let mut response = reqwest::get("http://localhost:9092/v1/sys/version")?;
292292
let ver: NodeAgentVersion = response.json()?;
293-
Ok(NodeAgentVersion{version: ver.version})
293+
Ok(NodeAgentVersion { version: ver.version })
294294
})();
295295
let permdaemon_status = (|| -> Result<(), Error> {
296296
let mut isgx = false;
@@ -371,7 +371,7 @@ fn main() {
371371
(@arg PLAIN: --plaintext "Disable color and UTF-8 output")
372372
(@arg VERBOSE: --verbose -v "Print extra information when encountering issues")
373373
(@group environment_type =>
374-
(@arg ENCLAVE_OS: --("enclave-os") "Run extra diagnostics tests for EnclaveOS")
374+
(@arg ENCLAVE_OS: --("enclave-os") "Run extra diagnostics tests for EnclaveOS")
375375
(@arg ENCLAVE_MANAGER: --("enclave-manager") "Run extra diagnostics tests for Enclave Manager")
376376
(@arg DATA_SHIELD: --("data-shield") "Run extra diagnostics tests for Data Shield")
377377
)

sgxs-tools/src/sgx_detect/proc_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub fn dependency(
220220
panic = Some("Adding dependencies after `define_dependencies!` invocation".into());
221221
}
222222
if let Some(msg) = panic {
223-
panic!(msg);
223+
panic!("{}", msg);
224224
}
225225

226226
item

sgxs-tools/src/sgx_detect/tests/mod.rs

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl Print for SgxCpuConfiguration {
155155
struct EnclaveAttributes {
156156
standard_attributes: bool,
157157
kss: bool,
158-
cpuid_12h_1: Result<Cpuid12h1, Rc<Error>>
158+
cpuid_12h_1: Result<Cpuid12h1, Rc<Error>>,
159159
}
160160

161161
#[dependency]
@@ -198,8 +198,16 @@ impl Print for EnclaveAttributes {
198198
#[optional_inner]
199199
#[derive(Clone, Update)]
200200
struct EnclavePageCache {
201-
total_size: u64,
201+
// Total size of confidentiality and integrity protected EPC
202+
total_size_cip: u64,
203+
204+
// Total size of confidentiality protected only EPC
205+
total_size_cpo: u64,
206+
207+
// Whether any pages were identified as unknown
202208
any_unknown: bool,
209+
210+
// Intel SGX Capability Enumeration Leaf
203211
cpuid_12h_epc: Result<Vec<Cpuid12hEnum>, Rc<Error>>,
204212
}
205213

@@ -210,30 +218,38 @@ impl Dependency<SgxCpuSupport> for EnclavePageCache {
210218
fn update_dependency(&mut self, dependency: &SgxCpuSupport, support: &SgxSupport) {
211219
self.inner = match (&dependency.inner, &support.cpuid_12h_epc) {
212220
(Some(SgxCpuSupportInner { sgx: Ok(true) }), Ok(c)) => {
213-
let mut total_size = 0;
221+
let mut total_size_cip = 0;
222+
let mut total_size_cpo = 0;
214223
let mut any_unknown = false;
215224
for section in c {
216225
match section {
217226
Cpuid12hEnum::Epc {
218227
ty: EpcType::ConfidentialityIntegrityProtected,
219228
phys_size,
220229
..
221-
} => total_size += phys_size,
230+
} => total_size_cip += phys_size,
231+
Cpuid12hEnum::Epc {
232+
ty: EpcType::ConfidentialityProtectedOnly,
233+
phys_size,
234+
..
235+
} => total_size_cpo += phys_size,
222236
Cpuid12hEnum::Invalid => unreachable!(),
223237
_ => any_unknown = true,
224238
}
225239
}
226240

227241
Some(EnclavePageCacheInner {
228-
total_size,
242+
total_size_cip,
243+
total_size_cpo,
229244
any_unknown,
230-
cpuid_12h_epc: Ok(c.clone())
245+
cpuid_12h_epc: Ok(c.clone()),
231246
})
232-
},
247+
}
233248
(Some(_), c) => Some(EnclavePageCacheInner {
234-
total_size: 0,
249+
total_size_cip: 0,
250+
total_size_cpo: 0,
235251
any_unknown: true,
236-
cpuid_12h_epc: c.clone()
252+
cpuid_12h_epc: c.clone(),
237253
}),
238254
_ => None,
239255
};
@@ -249,7 +265,7 @@ impl Print for EnclavePageCache {
249265
fn supported(&self) -> Status {
250266
match self.inner {
251267
// Minimum useful EPC size: 1 VA + 1 SECS + 2 REG + 1 TCS
252-
Some(EnclavePageCacheInner { total_size, .. }) if total_size >= 0x5000 => {
268+
Some(EnclavePageCacheInner { total_size_cip, total_size_cpo, .. }) if total_size_cip >= 0x5000 || total_size_cpo >= 0x5000 => {
253269
Status::Supported
254270
}
255271
Some(EnclavePageCacheInner {
@@ -336,14 +352,27 @@ impl Print for EpcSize {
336352
}
337353

338354
fn print(&self, level: usize) {
355+
fn epc_size_unit(total_size: u64) -> (f64, &'static str) {
356+
let mut epc_size = total_size as f64 / 1024.0 / 1024.0;
357+
let mut epc_unit = "MiB";
358+
if epc_size >= 1024.0 {
359+
epc_size /= 1024.0;
360+
epc_unit = "GiB";
361+
}
362+
(epc_size, epc_unit)
363+
}
364+
339365
if let Some(epc) = &self.epc {
340-
println!(
341-
"{:width$}{}: {:.1}MiB",
342-
"",
343-
self.name(),
344-
epc.total_size as f64 / (1048576.),
345-
width = level * 2
346-
);
366+
print!("{:width$}{}:", "", self.name(), width = level * 2);
367+
if epc.total_size_cip > 0 {
368+
let (epc_size, epc_unit) = epc_size_unit(epc.total_size_cip);
369+
print!(" {:.1}{}", epc_size, epc_unit);
370+
}
371+
if epc.total_size_cpo > 0 {
372+
let (epc_size, epc_unit) = epc_size_unit(epc.total_size_cpo);
373+
print!(" {:.1}{} (no integrity protection)", epc_size, epc_unit);
374+
}
375+
println!();
347376
}
348377
}
349378
}
@@ -398,7 +427,7 @@ impl Print for FlcCpuSupport {
398427
#[derive(Clone, Default, Update)]
399428
struct FlcCpuConfiguration {
400429
sgx_conf: Status,
401-
msr_3ah: Option<Result<Msr3ah, Rc<Error>>>
430+
msr_3ah: Option<Result<Msr3ah, Rc<Error>>>,
402431
}
403432

404433
#[dependency]
@@ -533,7 +562,7 @@ impl Update for DeviceLoader {
533562
},
534563
#[cfg(windows)]
535564
devpath: Err(Rc::new(IoError::new(ErrorKind::NotFound, "Device Driver Path not supported in Windows").into())),
536-
modstatus: support.sgxdev_status.clone()
565+
modstatus: support.sgxdev_status.clone(),
537566
});
538567
}
539568
}
@@ -877,7 +906,7 @@ struct EnclaveManager {
877906
version: Result<String, Rc<Error>>,
878907
}
879908

880-
impl Update for EnclaveManager{
909+
impl Update for EnclaveManager {
881910
fn update(&mut self, support: &SgxSupport) {
882911
self.inner = Some(EnclaveManagerInner {
883912
version: match support.node_agent.clone() {
@@ -894,7 +923,7 @@ impl Print for EnclaveManager {
894923
}
895924

896925
fn print(&self, level: usize) {
897-
if self.supported() == Status::Supported {
926+
if self.supported() == Status::Supported {
898927
println!("{:width$}{}{} ({})", "", self.supported().paint(), self.name(), self.inner.as_ref().map(|inner| inner.version.clone().unwrap()).unwrap(), width = level * 2);
899928
} else {
900929
println!("{:width$}{}{}", "", self.supported().paint(), self.name(), width = level * 2);
@@ -908,7 +937,7 @@ struct PermDaemon {
908937
service: Result<(), Rc<Error>>,
909938
}
910939

911-
impl Update for PermDaemon{
940+
impl Update for PermDaemon {
912941
fn update(&mut self, support: &SgxSupport) {
913942
self.inner = Some(PermDaemonInner {
914943
service: support.perm_daemon.clone()
@@ -923,7 +952,7 @@ impl Print for PermDaemon {
923952

924953
fn print(&self, level: usize) {
925954
if self.supported() == Status::Supported {
926-
println!( "{:width$}{}{}", "", self.supported().paint(), self.name(), width = level * 2);
955+
println!("{:width$}{}{}", "", self.supported().paint(), self.name(), width = level * 2);
927956
} else {
928957
println!("{:width$}{}{} {}", "", self.supported().paint(), self.name(), "(Okay if container runtime is CRI-O (openshift))", width = level * 2);
929958
}

sgxs-tools/src/sgx_detect/tests/scaffold.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub enum EnvConfig {
3333
}
3434

3535
impl Default for EnvConfig {
36-
fn default() -> Self {EnvConfig::Generic}
36+
fn default() -> Self { EnvConfig::Generic }
3737
}
3838

3939
pub trait Print: Name {
@@ -97,7 +97,7 @@ pub type TypeIdIdx = u8;
9797
pub struct DetectItemMap {
9898
next: TypeIdIdx,
9999
map: FnvHashMap<TypeId, TypeIdIdx>,
100-
store: Vec<Box<dyn DetectItem>>
100+
store: Vec<Box<dyn DetectItem>>,
101101
}
102102

103103
impl DetectItemMap {

0 commit comments

Comments
 (0)