Skip to content

Commit edc8c71

Browse files
committed
refactor(simulator): use safe securityfs mount wrapper
1 parent 32cd940 commit edc8c71

2 files changed

Lines changed: 12 additions & 18 deletions

File tree

dstack/tee-simulator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dstack-types.workspace = true
2121
dstack-mr.workspace = true
2222
fuser.workspace = true
2323
libc.workspace = true
24+
nix = { workspace = true, features = ["mount"] }
2425
sd-notify.workspace = true
2526
sha2.workspace = true
2627
tracing.workspace = true

dstack/tee-simulator/src/tpm.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//! template and certificate NV indices consumed by `tpm-attest`.
77
88
use std::{
9-
ffi::CString,
109
io::{Read, Write},
1110
os::{
1211
fd::{AsRawFd, FromRawFd},
@@ -225,23 +224,17 @@ fn install_fixture_event_log() -> Result<()> {
225224
// securityfs does not permit userspace to create a synthetic TPM event
226225
// log hierarchy. Shadow it in this development-only guest before
227226
// publishing the fixture that was replayed into the simulated PCRs.
228-
let source = CString::new("dstack-tee-simulator")?;
229-
let target = CString::new("/sys/kernel/security")?;
230-
let fstype = CString::new("tmpfs")?;
231-
let data = CString::new("mode=0755")?;
232-
let rc = unsafe {
233-
libc::mount(
234-
source.as_ptr(),
235-
target.as_ptr(),
236-
fstype.as_ptr(),
237-
libc::MS_NOSUID | libc::MS_NODEV | libc::MS_NOEXEC,
238-
data.as_ptr().cast(),
239-
)
240-
};
241-
if rc != 0 {
242-
return Err(std::io::Error::last_os_error())
243-
.context("failed to mount simulated securityfs shadow");
244-
}
227+
let flags = nix::mount::MsFlags::MS_NOSUID
228+
| nix::mount::MsFlags::MS_NODEV
229+
| nix::mount::MsFlags::MS_NOEXEC;
230+
nix::mount::mount(
231+
Some("dstack-tee-simulator"),
232+
security_root,
233+
Some("tmpfs"),
234+
flags,
235+
Some("mode=0755"),
236+
)
237+
.context("failed to mount simulated securityfs shadow")?;
245238
fs_err::create_dir_all(tpm_dir)
246239
.context("failed to create TPM event-log directory in securityfs shadow")?;
247240
fs_err::write(

0 commit comments

Comments
 (0)