Skip to content

Commit ac559fe

Browse files
committed
fix(mxc): bind ETW attribution to process generation
Signed-off-by: Drew Newberry <[email protected]>
1 parent 333c114 commit ac559fe

5 files changed

Lines changed: 241 additions & 290 deletions

File tree

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ miette = { version = "7", features = ["fancy"] }
5656
thiserror = "2"
5757

5858
# Windows platform APIs (ETW/TDH audit consumer in openshell-driver-mxc; Windows-only)
59-
windows = { version = "0.62", features = ["Win32_Foundation", "Win32_System_Diagnostics_Etw", "Win32_System_Performance", "Win32_System_Time"] }
59+
windows = { version = "0.62", features = ["Wdk_System_Threading", "Win32_Foundation", "Win32_System_Diagnostics_Etw", "Win32_System_Time"] }
6060
anyhow = "1"
6161

6262
# Logging/Tracing

‎architecture/security-policy.md‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,10 @@ arguments from structured fields and messages. Raw ETW debug summaries replace
398398
the `commandLine` value with `[REDACTED]`, including pending-buffer eviction
399399
diagnostics.
400400
MXC ETW attribution never treats command text as ownership evidence. It uses the
401-
driver-owned `wxc-exec` PID as the initial anchor and retains bounded PID
402-
lifetime records plus established identity, activity, and correlation-vector
403-
links for a five-second late-event window. PID resolution compares the event's
404-
ETW producer timestamp with those lifetimes and delays PID-only attribution long
405-
enough for launch registration to expose reuse. A recorded process retirement
406-
provides an exact generation boundary. If a new owner displaces an unretired PID,
407-
PID-only events in the unknowable interval fail closed instead of being assigned
408-
to either sandbox; established strong correlations remain eligible during the
409-
late-event window.
401+
driver-owned `wxc-exec` PID plus its kernel process start key as the initial
402+
anchor. ETW attaches that generation key to each record, and the driver queries
403+
the same key from its child process handle. PID attribution requires both values
404+
to match, so reuse cannot transfer ownership between process generations.
405+
Retired PID evidence is discarded; established identity, activity, and
406+
correlation-vector links remain eligible during the five-second late-event
407+
window. Records without matching generation evidence fail closed.

‎crates/openshell-driver-mxc/README.md‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,14 @@ blocking the ETW pump or growing gateway memory. The gateway emits an immediate
7777
warning identifying the audit coverage gap and rate-limits follow-up warnings
7878
to once every 30 seconds while overload continues.
7979

80-
Audit attribution bootstraps only from the driver-owned `wxc-exec` PID while
81-
that child is alive; command text is never an ownership key. The process monitor
82-
retires the live PID at exit. Its bounded process lifetime and any identity,
83-
activity, and correlation-vector links learned from it remain available for five
84-
seconds so already in-flight ETW records can arrive. PID resolution uses the
85-
event's ETW producer timestamp and holds PID-only records for two seconds so a
86-
new launch registration can expose PID reuse before attribution. A normal
87-
retirement provides an exact generation boundary for delayed delivery. If a new
88-
owner displaces a still-live registration, the boundary is unknowable and
89-
PID-only records in that gap remain unattributed; established strong correlations
90-
can still resolve legitimate late records.
80+
Audit attribution bootstraps only when the driver-owned `wxc-exec` PID and its
81+
kernel process start key both match the values attached to the ETW record;
82+
command text is never an ownership key. This generation key prevents a recycled
83+
PID from inheriting the previous process's attribution regardless of delivery
84+
delay. The process monitor retires the live PID at exit. Established identity,
85+
activity, and correlation-vector links remain available for five seconds so
86+
already in-flight ETW records can arrive, but retired PID evidence cannot resolve
87+
them. Records without matching generation evidence remain unattributed.
9188

9289
## Prerequisites (live runs)
9390

‎crates/openshell-driver-mxc/src/driver.rs‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,23 @@ async fn run_lifecycle(
799799
// anchor that ties the `Sandboxing` provider's events back to this
800800
// `sandbox_id` while the child is alive. Command text is never an
801801
// attribution key. No-op unless the ETW consumer is running.
802-
if let Some(pid) = child.id() {
803-
if let Ok(mut idx) = attribution.lock() {
804-
idx.register_launch(&sandbox_id, &sandbox_name, pid);
802+
if config.etw_audit
803+
&& let Some(pid) = child.id()
804+
{
805+
match crate::etw_consumer::child_process_start_key(&child) {
806+
Ok(process_start_key) => {
807+
if let Ok(mut idx) = attribution.lock() {
808+
idx.register_launch(&sandbox_id, &sandbox_name, pid, process_start_key);
809+
}
810+
}
811+
Err(error) => {
812+
warn!(
813+
sandbox = %sandbox_name,
814+
pid,
815+
error,
816+
"failed to obtain wxc-exec process generation key; PID-based ETW attribution disabled for this launch"
817+
);
818+
}
805819
}
806820
}
807821

0 commit comments

Comments
 (0)