Skip to content

Commit b9efa1e

Browse files
fix(mxc): attribute ETW audit events through the launched process (#5586)
* fix(mxc): attribute ETW audit events through the launched process On some Windows builds every Sandboxing provider event comes from the shared OS broker process and none from the wxc-exec the driver spawned. The consumer attributes events by matching that wxc-exec's PID and process start key, and uses the first events that match to learn the identity, activity and correlation-vector keys that link the broker's events to the sandbox. With no event from wxc-exec nothing ever matched: every event was buffered, aged out and dropped, the OCSF log stayed empty, and the only trace was a debug line. Anchor attribution on ProcessLaunched as well. It names the process the OS started inside the sandbox (processId). When that process is a child of a live registered wxc-exec, and the parent still carries the registered process start key, the event belongs to that sandbox and its keys are cross-linked, so the rest of the create burst attributes through the existing correlators. The parent lookup uses NtQueryInformationProcess; PROCESS_BASIC_INFORMATION needs the Win32_System_Kernel feature on the driver's windows dependency (no new crates, no lockfile change). The buffer now replays until a pass resolves nothing new, so a chain of keys (activity, then correlation vector, then identity) resolves in one drain. Make the loss visible. Events that reach the consumer but are discarded without ever being attributed are now counted, published to the session health (EtwSession::unattributed_event_count) and reported with a rate-limited warning at the default log level. Only events the emitter writes to the audit trail count, so the key-less BrokeredCreateProcessLaunchResult that every healthy host drops does not raise it. Tests: 93 of 93 openshell-driver-mxc tests pass on Windows x64 and on native ARM64, 17 of them new: the anchor and its guards (recycled PID, unreadable or unregistered parent, exited process, other event names), two concurrent sandboxes kept apart, a replay of the create burst captured on the GB300, multi-pass replay, drop counting, the reporter, and a live parent lookup. cargo fmt and clippy with the CI flags are clean on x64. Audit run (run-ocsf-audit.ps1) with etw_audit on: on a GB300 (ARM64, build 28000.3231, wxc-exec 1.0.1) it went from 0 of 7 event types and 0 OCSF events to 4 of 7 types and 5 events in 3 classes, with all 16 provider events coming from the broker; on x64 (build 28120.3272, wxc-exec 1.0.0) it stays at 4 of 7 types and 5 events and logs no warning. The runs used a copy of the audit script whose readiness probe connects to the port (Get-NetTCPConnection under-reports listeners on the test hosts) and a gateway log level of info,mxc_etw=trace for diagnostics. The remaining three types are missing because this OS emits different event names; that is addressed separately. Refs #5585 Signed-off-by: ashwind <ashwind@nvidia.com> * fix(mxc): map the renamed ETW events of the released MXC Three of the seven audit event types never fired because the released MXC emits different event names than the consumer looks up (the consumer was written against a development build that MXC later renamed). With attribution working, they were the only gap left in the audit trail. - SetUILimitsOnJob is the released name of ApplyUILimits: report it as "UI restrictions applied" (Config State Change [5019]). The older name still maps the same way. - SandboxLaunchDetails replaces CreateProcessInSandbox and Win32kLockdownApplied. Emit the process launch row (Process Activity [1007], executable only, arguments omitted as before) from its commandLine, and the win32k lockdown row (5019) when disallowWin32kSystemCalls is 1. Either row is skipped when its field is absent. disallowWin32kSystemCalls is attached to the row as an unmapped field. - Both events count as audited, so losing them raises the unattributed warning like the other mapped events. The mappings are pure functions (map_config_state_as, map_launch_details) so they are tested without the audit sink. Tests: 100 of 100 openshell-driver-mxc tests pass on Windows x64 and on native ARM64, 7 of them new: the UI-limits row, the older name, the launch and win32k rows from one event, no leaked command-line arguments, the win32k row only for flag 1, sparse events, and the audited-name contract. They use field values captured from a real SandboxLaunchDetails event. cargo fmt and clippy with the CI flags are clean on x64. Audit run (run-ocsf-audit.ps1, etw_audit on, one sandbox): on a GB300 (ARM64, build 28000.3231, wxc-exec 1.0.1) 4 of 7 types and 5 events became 7 of 7 types and 8 events, and on x64 (build 28120.3272, wxc-exec 1.0.0) 4 of 7 and 5 events became 7 of 7 and 8 events, in 3 OCSF classes, with no unattributed warning. The script's overall verdict stays FAIL because its sandbox workload does not produce its artifact, which is unrelated to the event types. Refs #5585 Signed-off-by: ashwind <ashwind@nvidia.com> * fix(mxc): run the audit workload inline in run-ocsf-audit.ps1 run-ocsf-audit.ps1 reported "audit workload did not produce its artifact" and verdict FAIL even when the audit trail was complete. Its sandbox workload was a batch file (audit-workload.cmd) that the script wrote into the shared folder before creating the sandbox. The sandbox cannot run a batch file the host created beforehand: the workload fails about 37 ms after it starts and cmd reports "The process cannot access the file because it is being used by another process". The same sandbox can write new files, read and copy the pre-existing file, and run a batch file it created itself; waiting before running the batch, turning ETW audit off, or using --no-tty instead of --detach made no difference. Run the workload inline instead: cmd /d /c "echo ... 1> hello.txt". It writes hello.txt relative to its working directory (the share), so the command needs no path and also works when -ShareDir contains spaces. The wait for the artifact, the verdict logic and the output are unchanged. This changes the test workload only. The underlying limitation (a sandbox cannot run a batch file that was in its read-write folder before launch) is not changed here; it is likely also why the host-service e2e scenario, which runs a host-created batch file, fails, which was not verified. Tests: run-ocsf-audit.ps1 with etw_audit on, one sandbox, on a GB300 (ARM64, build 28000.3231, wxc-exec 1.0.1) and on x64 (build 28120.3272, wxc-exec 1.0.0), with the two preceding commits: verdict PASS, exit code 0, 7 of 7 event types, workload output present and 8 OCSF events in 3 classes on both, no unattributed warning. Also PASS on x64 with a -ShareDir containing a space. Before this change the script reported FAIL on both with the workload artifact missing. The runs used a copy of the script whose readiness probe connects to the port (Get-NetTCPConnection under-reports listeners on the test hosts) and a gateway log level of info,mxc_etw=trace for diagnostics; the repository's probe is unchanged. Refs #5585 Signed-off-by: ashwind <ashwind@nvidia.com> * fix(mxc): harden ETW attribution and audit-loss accounting Addresses review feedback on #5586. Child PID reuse: a queued ProcessLaunched event was attributed by looking up its child's parent when it was replayed. If that child had exited and Windows had reused the PID for another sandbox's child, the event (and the rest of its burst, through the activity id) was attributed to the wrong sandbox. The parent is now read once, when the event is first received, and kept with the event; a replay uses that snapshot. If the child is already gone at that point nothing can be proven and the event is not attributed. Foreign provider traffic: the Sandboxing provider is system-wide, so events from another gateway or consumer were counted as this gateway's audit gap, including on an idle gateway. Unresolved audited events are now counted as possible loss only if this gateway had a live sandbox while they waited (registered, retired or forgotten); otherwise they are counted separately as unowned and never warned about. The warning no longer claims a confirmed gap. Shutdown: the final warning ran before pending events were accounted for, so an unresolved event younger than the pending TTL was never counted. The consumer now replays once on disconnect, counts what is still unresolved, publishes the count, and only then forces the warnings. Tests: regressions for child PID reuse (and the legitimate late registration), an idle gateway receiving foreign events, a sandbox that came and went (retired and forgotten) while an event waited, and shutdown with a fresh unresolved event and with one that resolves on the final replay. Putting the live PID lookup back on replay fails the PID-reuse test. 108 driver tests pass on x64 and ARM64, clippy is clean on x64, and the real OCSF audit passes 7/7 on x64 and on a GB300 (ARM64) with no attribution warning. Signed-off-by: ashwind <ashwind@nvidia.com> * fix(mxc): bound launch attribution by time and classify by emission time Addresses review feedback on #5586. Child PID reuse before the first receipt: the launched child's parent was read when the event reached the consumer, but an event arrives 1.2 to 1.9 s after it is emitted (measured on x64 and ARM64), so the PID can already have been reused by a child of another sandbox. The event names the child only by PID (no start key, no creation time), so the process now holding the PID must at least have existed when the event was emitted: one created later is refused, and nothing is attributed when either time is unknown. The trace is opened with raw timestamps and each event is placed on the wall clock by pairing the performance counter with the precise system time at receipt, instead of relying on ETW's conversion from the session's start. The launched child is created 5 to 11 ms before its event on both architectures; the bound allows 1 ms of clock noise. Its limits (creation-time resolution, a clock step during delivery) are documented where the constant is defined. Delayed delivery: classification used the time an event was received, so an event from a short-lived sandbox that was forgotten before the event arrived was called foreign traffic and never warned about. It now uses the time the event was emitted, and an unknown emission time counts as possible loss if this gateway ever had a sandbox. forget() stamps the sandbox's liveness only for a sandbox the index knew: the driver forgets it again on delete, which must not look like activity. README: the limitation that broker-emitted ARM64 events cannot be correlated and that audit qualification fails no longer holds; it now describes the supported behaviour, the bound, and how unattributed events are reported. Tests: regressions for PID reuse before the first receipt, the fail-closed cases, the slack boundary, a real child against a real raw QPC reading (so a wrong clock assumption fails), the conversion and its refusals, events received after forget, forgetting an unknown sandbox twice, an unknown emission time, and the raw-timestamp trace mode. Each fails when its fix is reverted (one reversed guard is redundant with the age conversion). 122 driver tests pass on Windows x64 and ARM64 in a clean and a configured environment, with 1 and 32 test threads and from a path with spaces; the real OCSF audit passes 7/7 on x64 and ARM64; fmt, workspace check and clippy pass on Linux. Signed-off-by: ashwind <ashwind@nvidia.com> --------- Signed-off-by: ashwind <ashwind@nvidia.com>
1 parent 2378c84 commit b9efa1e

4 files changed

Lines changed: 1614 additions & 58 deletions

File tree

‎crates/openshell-driver-mxc/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ uuid = { workspace = true }
3737
openshell-mxc-boundary = { path = "../openshell-mxc-boundary" }
3838
openshell-isolation-interface = { path = "../openshell-isolation-interface" }
3939
openshell-sandbox-backend = { path = "../openshell-sandbox-backend" }
40-
windows = { workspace = true }
40+
windows = { workspace = true, features = ["Win32_System_Kernel", "Win32_System_Performance", "Win32_System_SystemInformation"] }
4141

4242
[dev-dependencies]
4343
anyhow = { workspace = true }

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,24 @@ binaries. This requires elevation or Performance Log Users membership. It checks
414414
the shipped config and coverage classifier before requiring all seven event types
415415
in the durable JSONL output; the ordinary E2E scenarios do not check this path.
416416

417-
On the ARM64 test host (Windows build 28120, MXC 1.0.0), Sandboxing ETW records
418-
come from the shared Appinfo broker rather than the driver-owned executor.
419-
The consumer cannot correlate these records using the executor's PID and process
420-
generation, so live audit qualification currently fails even though the workload
421-
completes. The executor diagnostic log redacts its container identity. A trusted
422-
broker-to-launch correlation is needed; treating the shared broker PID as a
423-
sandbox identity would misattribute concurrent sandboxes and is not supported.
417+
On some Windows builds (observed on ARM64, Windows build 28000), Sandboxing ETW records
418+
come from the shared Appinfo broker rather than the driver-owned executor, so they
419+
cannot be matched to a sandbox by the executor's PID and process generation. The
420+
consumer attributes them through the `ProcessLaunched` record instead. That record
421+
names the process the OS started inside the sandbox, and it is attributed to a
422+
sandbox only when that process is a child of a live, registered executor (checked by
423+
the executor's process start key) and was created no later than the record was
424+
emitted. The record carries no start key for the child, so the creation-time bound
425+
is what rules out a PID that was reused before the record reached the consumer
426+
(records arrive about a second after they are emitted); when the bound cannot be
427+
established, the record is not attributed. The record's activity id then attributes
428+
the rest of the create burst. On a host that shows this behaviour, live audit
429+
qualification passes with all seven event types. Treating the shared broker PID as a sandbox identity would
430+
misattribute concurrent sandboxes and is not supported.
431+
432+
Records that cannot be attributed are counted. The provider is system-wide, so some
433+
may belong to another gateway or consumer: a record that waited while this gateway
434+
had a live sandbox counts as possible loss and raises a warning that does not claim
435+
a confirmed gap, and one that arrived while it had none is counted separately and
436+
never warned about. Pending records are replayed and counted when the session stops,
437+
before the final warning.

‎crates/openshell-driver-mxc/examples/run-ocsf-audit.ps1‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,16 @@ gateway_id = 'mxc-ocsf-audit'
357357

358358
$cmdExe = Join-Path $env:SystemRoot "System32\cmd.exe"
359359
if (-not (Test-Path $cmdExe -PathType Leaf)) { throw "cmd.exe not found at '$cmdExe'" }
360-
$helloPathCommand = $helloPath.Replace('\', '/')
361360
New-Item -ItemType Directory -Force $ShareDir | Out-Null
362-
$batch = Join-Path $ShareDir 'audit-workload.cmd'
363-
Set-Content -LiteralPath $batch -Encoding ASCII -Value ('@echo hello from openshell ocsf audit > "{0}"' -f $helloPathCommand)
361+
# Run the workload inline, writing hello.txt relative to its working directory
362+
# (the share), so the command needs no path and works when -ShareDir contains
363+
# spaces. A batch file the host writes into the share before the sandbox starts
364+
# cannot be run by the sandbox (Windows reports a sharing violation), which made
365+
# this script report "audit workload did not produce its artifact" even when
366+
# the audit trail was complete.
364367
$driverConfig = @{
365368
mxc = @{
366-
command = @($cmdExe, '/d', '/c', $batch)
369+
command = @($cmdExe, '/d', '/c', 'echo hello from openshell ocsf audit 1> hello.txt')
367370
cwd = $shareDirPolicy
368371
}
369372
} | ConvertTo-Json -Compress -Depth 4

0 commit comments

Comments
 (0)