Repository navigation
Commit b9efa1e
authored
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
357 | 357 | | |
358 | 358 | | |
359 | 359 | | |
360 | | - | |
361 | 360 | | |
362 | | - | |
363 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
364 | 367 | | |
365 | 368 | | |
366 | | - | |
| 369 | + | |
367 | 370 | | |
368 | 371 | | |
369 | 372 | | |
| |||
0 commit comments