Qualify Windows system delegation and crash-safe mirror adapter on native VM
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-14 07:43:36 +01:00
parent 655572aa5b
commit 4aff116b84
13 changed files with 3115 additions and 115 deletions
+160 -6
View File
@@ -25,7 +25,10 @@ use fs2::FileExt;
use rmm_agent_core::{
auth::{Binding, HelperIdentity, Outcome, Request},
crypto::DalekVerifier,
helper_reconcile::{BootSource, ExecutorLedgerGuard, HelperSync},
helper_reconcile::{
BootSource, ExecutorLedgerGuard, HelperSync, NoDispatchObservation, NoStartAnchor,
NoStartGuard,
},
ledger,
};
use rmm_domain::jobs::{Action, ExecutionPermitPayload, JobPayload, hash};
@@ -275,6 +278,48 @@ impl ExecutorLedgerGuard for LedgerGuard {
}
}
/// All data other than the immutable intent reference comes from held local
/// handles. The IPC caller cannot manufacture a NoDispatchObservation.
struct DenialGuard<'a> {
ledger: &'a LedgerGuard,
pin: &'a Pin,
intent: Option<(Uuid, &'a str)>,
}
impl ExecutorLedgerGuard for DenialGuard<'_> {
fn check(&self, db: &Connection) -> Result<()> {
ipc::require_self(&self.pin.helper)?;
self.ledger.check(db)
}
}
impl NoStartGuard for DenialGuard<'_> {
fn live_instance_sha256(&self) -> Result<String> {
let pid = std::process::id();
let peer = ipc::PeerProof::for_service(&self.pin.helper, pid)?;
Ok(hash(&serde_json::to_vec(&(
peer.identity(),
self.ledger.ledger.identity,
self.ledger.lock.identity,
))?))
}
fn verify_no_dispatch(
&self,
original: &Request,
anchor: &NoStartAnchor,
) -> Result<NoDispatchObservation> {
let (id, digest) = self
.intent
.context("SYSTEM_NO_DISPATCH_REFERENCE_REQUIRED")?;
let mut store = crate::helper_runtime::intent::Store::open(false)?;
let (intent, _) = store.load(id)?;
ensure!(
intent.policy_sha256 == self.pin.policy_sha256
&& intent.helper_binary_sha256 == self.pin.helper.binary_sha256,
"SYSTEM_NO_DISPATCH_PIN_BINDING"
);
store.verify_no_dispatch(id, digest, original, anchor)
}
}
struct ServiceHandle(SC_HANDLE);
impl Drop for ServiceHandle {
fn drop(&mut self) {
@@ -727,6 +772,7 @@ pub struct SystemHelper {
clock: NativeClock,
boot: WindowsBoot,
sync: Option<HelperSync<DalekVerifier>>,
last_diagnostic: Option<Instant>,
}
impl SystemHelper {
pub fn open() -> Result<Self> {
@@ -749,11 +795,59 @@ impl SystemHelper {
clock,
boot,
sync,
last_diagnostic: None,
})
}
pub fn pin(&self) -> &Pin {
&self.pin
}
/// One bounded private bootstrap diagnostic, never inventory or payload.
/// Diagnostic failure is intentionally ignored by the service loop; the
/// original security failure still closes Sync and disconnects the pipe.
fn record_pipe_error(&mut self, error: &anyhow::Error) -> Result<()> {
if self
.last_diagnostic
.is_some_and(|at| at.elapsed() < Duration::from_secs(30))
{
return Ok(());
}
self.last_diagnostic = Some(Instant::now());
self.recheck()?;
let path = Path::new(STATE_ROOT).join("pipe-last-error.json");
let pending = Path::new(STATE_ROOT).join(".pipe-last-error.pending");
let writers = vec![self.settings.helper.service_sid.clone()];
if path.try_exists()? {
let _old = PinnedFile::open(&path, false, &[], &writers, false)?;
}
let diagnostic = ipc::diagnostic(error);
let bytes = serde_json::to_vec(
&serde_json::json!({"pid":std::process::id(),"observed_at_utc":chrono::Utc::now(),"diagnostic":diagnostic}),
)?;
ensure!(bytes.len() <= 1024, "SYSTEM_DIAGNOSTIC_BOUND");
use std::io::Write;
let mut file = OpenOptions::new()
.write(true)
.create_new(true)
.open(&pending)?;
let identity = ipc::file_identity(&file)?;
let result = (|| -> Result<()> {
{
let _check = PinnedFile::open_read_shared(&pending, false, &[], &writers)?;
}
file.write_all(&bytes)?;
file.sync_all()?;
Ok(())
})();
drop(file);
result?;
std::fs::rename(&pending, &path)?;
let saved = PinnedFile::open(&path, false, &[], &writers, false)?;
ensure!(
saved.identity == identity,
"SYSTEM_DIAGNOSTIC_FILE_REPLACED"
);
Ok(())
}
fn recheck(&mut self) -> Result<()> {
ipc::require_self(&self.settings.helper)?;
for file in &mut self.files {
@@ -829,10 +923,33 @@ impl SystemHelper {
&self.clock,
&self.boot,
)?;
let no_start_anchor = if value.ready && self.settings.enable_effects {
let guard = DenialGuard {
ledger: &self.guard,
pin: &self.pin,
intent: None,
};
let generation = self
.sync
.as_ref()
.unwrap()
.active_generation()
.context("SYSTEM_READY_GENERATION_REQUIRED")?;
Some(Box::new(self.sync.as_ref().unwrap().no_start_anchor(
&self.db,
&guard,
generation,
&self.clock,
&self.boot,
)?))
} else {
None
};
Ok(ReplyBody::Applied {
snapshot: value.snapshot,
unlocked_grants: value.unlocked_grants,
ready: value.ready && self.settings.enable_effects,
no_start_anchor,
})
}
Operation::Execute {
@@ -841,6 +958,40 @@ impl SystemHelper {
} => Ok(ReplyBody::Executed {
outcome: self.execute(*generation, request, peer)?,
}),
Operation::Abandon {
anchor,
request,
intent_id,
intent_sha256,
} => {
ensure!(
!intent_id.is_nil() && ipc::digest(intent_sha256),
"SYSTEM_NO_DISPATCH_REFERENCE_REQUIRED"
);
let job = self.settings.binding.job(&request.job_bytes)?;
ensure!(
job.execution_identity == "system"
&& job.max_runtime_seconds <= self.settings.max_runtime_seconds
&& matches!(&job.action,Action::SetServiceState{unit,state} if matches!(state.as_str(),"running"|"stopped")&&self.settings.allowed_services.iter().any(|r|r.name==*unit)),
"SYSTEM_ABANDON_POLICY_DENIED"
);
self.sync()?;
let guard = DenialGuard {
ledger: &self.guard,
pin: &self.pin,
intent: Some((*intent_id, intent_sha256)),
};
Ok(ReplyBody::Abandoned {
outcome: self.sync.as_mut().unwrap().abandon_no_start(
&mut self.db,
&guard,
anchor,
request,
&self.clock,
&self.boot,
)?,
})
}
};
let response = response?;
peer.check()?;
@@ -1028,19 +1179,22 @@ unsafe extern "system" fn service_main(_: u32, _: *mut *mut u16) {
match server.receive() {
Ok(Some(mut incoming)) => {
let reply = helper.handle(&incoming.call, &mut incoming.peer);
if server.reply(&reply).is_err()
&& let Some(sync) = &mut helper.sync
{
sync.close();
if let Err(error) = server.reply(&reply) {
if let Some(sync) = &mut helper.sync {
sync.close();
}
server.disconnect();
let _diagnostic = helper.record_pipe_error(&error);
}
server.disconnect();
}
Ok(None) => {}
Err(_) => {
Err(error) => {
if let Some(sync) = &mut helper.sync {
sync.close();
}
server.disconnect();
let _diagnostic = helper.record_pipe_error(&error);
}
}
}