Skip to content

Permissive Learning Mode 1/6 audit skeleton - #584

Merged
Lily Barkley (lilybarkley-msft) merged 34 commits into
mainfrom
user/lilybarkley/plm-pr1-audit-skeleton
Jul 8, 2026
Merged

Lily Barkley (lilybarkley-msft) merged 34 commits into
mainfrom
user/lilybarkley/plm-pr1-audit-skeleton

Conversation

@lilybarkley-msft

@lilybarkley-msft Lily Barkley (lilybarkley-msft) commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

📖 Description

PR 1 of 6 — stacked vertical split of the PermissiveLearningMode work for readability. Merged together this PR plus PRs 2–6 produce exactly the same tree as the source branch; the split is per-area, not per-self-contained-feature.

This PR introduces the cross-cutting plumbing needed for permissive learning mode (PLM):

  • wxc-exec --audit plumbing: new audit/log-capture flag and the surrounding wiring in wxc-exec that invokes plm.exe before/after the workload.
  • plm crate skeleton: a Windows-only binary + library at src/core/plm/ with:
    • start — wpr -cancel + wpr -start <plm.wprp>!AccessFailureProfile -filemode
    • stop — trace-lifecycle scaffolding (parse + merge land in PR2+)
    • log — interactive Enter-to-start/Enter-to-stop trace lifecycle skeleton
    • Embedded WPR profile (plm.wprp) auto-materialized next to the exe on first use
    • Cross-process singleton coordination so plm log and wxc-exec --audit don't double-start traces
    • wpr.exe PATH-spoof-safe resolver
  • Build-infra additions (CI templates, workspace Cargo.toml wiring).

Subsequent PRs layer the parser, config merge, capability extraction, UI policy, and test artifacts on top.

🔗 References

  • Stack:
    • PR1 (this) → base main
    • PR2 filesystem extraction → base PR1
    • PR3 config generation → base PR2
    • PR4 capability extraction → base PR3
    • PR5 UI policy → base PR4
    • PR6 testing artifacts → base PR5

🔍 Validation

  • cargo build -p plm --target x86_64-pc-windows-msvc — clean
  • cargo fmt --all -- --check — clean
  • cargo clippy -p plm --target x86_64-pc-windows-msvc --all-targets -- -D warnings — clean
  • cargo test -p plm --target x86_64-pc-windows-msvc — 25 passed
  • Full stack (PRs 1–6) verified: final tip's tree is bit-identical to the pre-split source branch.

✅ Checklist

📋 Issue Type

  • Bug fix
  • Feature
  • Task

GitHub Actions runs the PR validation build automatically. The ADO pipeline
(MXC-PR-Build) is the official build pipeline that signs the binaries; it
runs on merge to main and nightly, and Microsoft reviewers can trigger it
on a PR with /azp run. See docs/pull-requests.md.

Microsoft Reviewers: Open in CodeFlow

Copilot AI review requested due to automatic review settings June 27, 2026 01:38
@lilybarkley-msft
Lily Barkley (lilybarkley-msft) requested a review from a team as a code owner June 27, 2026 01:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces the initial (“skeleton”) plumbing for Permissive Learning Mode (PLM) audit tracing on Windows: a new plm tool (WPR start/stop + coordination helpers) and a wxc-exec --audit flag that injects permissiveLearningMode and brackets the workload with trace start/stop plus best-effort cleanup to avoid leaking the host’s NT Kernel Logger session.

Changes:

  • Add wxc-exec --audit (Windows-only) that injects permissiveLearningMode, spawns plm.exe start/stop, and adds Ctrl-C / panic / process::exit cleanup for WPR sessions and a host-wide singleton mutex.
  • Add new core/plm crate (Windows-only binary + shared library helpers) implementing WPR lifecycle, safe absolute wpr.exe resolution, embedded WPRP profile staging, and coordination primitives.
  • Update build scripts and CI (GitHub Actions + ADO) to build/test plm and run a Windows PLM integration harness; adjust workspace membership/default-members accordingly.

Reviewed changes

Copilot reviewed 22 out of 24 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/core/wxc/src/main.rs Adds --audit, plm spawning, WPR cancel cleanup, and singleton coordination.
src/core/wxc/Cargo.toml Adds plm dependency for shared coordination constants/helpers.
src/core/wxc_common/src/models.rs Adds ExecutionRequest.audit to allow release override behavior.
src/core/wxc_common/src/config_parser.rs Adds audit-related warnings and initializes audit: false.
src/core/plm/src/wpr_path.rs Adds safe absolute resolution of wpr.exe (System32 via API) + tests.
src/core/plm/src/stop.rs Adds plm stop skeleton: wpr -stop, log dir creation, testable seams.
src/core/plm/src/start.rs Adds plm start skeleton: start trace, cancel-on-conflict retry, profile sanity tests.
src/core/plm/src/profile_gen.rs Adds embedded WPRP + atomic “write if missing” materializer with tests.
src/core/plm/src/main.rs Adds Windows-only plm.exe CLI + ctrl handler + singleton handling.
src/core/plm/src/log.rs Adds interactive plm log skeleton: prompt/start/prompt/stop into temp ETL.
src/core/plm/src/lib.rs Exposes the PLM library modules with Windows-only gating where needed.
src/core/plm/src/coordination.rs Shared singleton env-var name + ctrl-handler bounded-wait helper + tests.
src/core/plm/readme.md Documents PLM skeleton behavior, layout, CLI, and limitations.
src/core/plm/Cargo.toml Introduces plm crate deps and Windows-target-gated windows crate usage.
src/core/plm/build.rs Embeds Windows VersionInfo for plm.exe.
src/Cargo.toml Adds core/plm to workspace and defines default-members excluding PLM.
src/Cargo.lock Adds plm and new transitive dependencies.
src/backends/appcontainer/common/src/appcontainer_runner.rs Allows permissiveLearningMode in release when request.audit is true.
sdk/tests/integration/package-lock.json Updates local SDK version and a few dev dependency lock entries.
README.md Adds end-user docs for --audit and PLM tool usage.
build.bat Builds/stages plm.exe, adds --with-bfs, and refreshes local SDK file: dep.
.github/workflows/Build.Windows.Job.yml Builds/tests plm and runs PLM integration tests + artifact upload on failure.
.github/workflows/Build.Linux.Job.yml Builds/tests plm library on Linux to enforce cfg-gating hygiene.
.azure-pipelines/templates/Rust.Build.Job.yml Builds/tests plm in ADO Windows jobs to keep it green.
Files not reviewed (1)
  • sdk/tests/integration/package-lock.json: Generated file

Comment thread README.md Resolved
Comment thread src/core/wxc/src/main.rs Resolved
Comment thread src/core/wxc/src/main.rs Resolved
Comment thread src/core/plm/src/stop.rs Resolved
Comment thread src/core/wxc/src/main.rs Resolved
Comment thread src/Cargo.toml Resolved
Comment thread src/host/plm/src/main.rs Resolved
Comment thread src/Cargo.toml Resolved
Comment thread .github/workflows/Build.Linux.Job.yml Resolved
Comment thread .github/workflows/Build.Windows.Job.yml Resolved
Comment thread src/core/plm/build.rs Resolved
Comment thread src/core/plm/Cargo.toml Resolved
Comment thread src/core/wxc/src/main.rs Resolved
Comment thread src/core/wxc/src/main.rs Resolved
Comment thread src/core/wxc/src/main.rs Resolved
Comment thread src/core/wxc/src/main.rs Resolved
Comment thread src/core/wxc/src/main.rs Resolved
Comment thread src/core/wxc/src/main.rs Resolved
Comment thread src/core/plm/src/main.rs Resolved
Comment thread src/core/wxc/src/main.rs Outdated
/// invoke `wpr.exe` by absolute path
/// (`%SystemRoot%\System32\wpr.exe`) rather than as a bare name so
/// `CreateProcessW`'s implicit CWD-first search order can't be abused
/// to substitute a planted binary. PLM runs as administrator, so a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLM runs as administrator

This can't be true, right? For that to work, wxc-exec would also have to run as admin, no? Or are users going to see a UAC prompt when plm.exe is spawned?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it is. It's something that Brian is going to be addressing for next release. WPR has to run as admin in order to gather the logs we need

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will wxc-exec have to run as admin? Or will wxc-exec run as non-admin but when plm.exe is started the user will get a UAC prompt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it needs to be ran as admin, but I like prompt for elevation suggestion and will add it in

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavior is now: prompt for elevation and spawns an elevated prompt that runs for that evocation

@MGudgin Gudge (MGudgin) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. label Jul 1, 2026
Comment thread .github/workflows/Build.Linux.Job.yml Resolved
Comment thread .github/workflows/Build.Windows.Job.yml Resolved
Comment on lines +29 to +34
/// The 2s budget is chosen so the combined budget of the wxc-exec
/// handler (`2 * CTRL_HANDLER_DRAIN_TIMEOUT`) stays under the
/// ~5s OS-imposed kill budget for `CTRL_CLOSE_EVENT` /
/// `CTRL_LOGOFF_EVENT` / `CTRL_SHUTDOWN_EVENT`, with ~500ms of
/// slack for the actual `wpr -cancel` spawn. Pinned by
/// `tests::ctrl_handler_drain_timeout_respects_os_budget`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: these times might be machine specific so they could differ depending on the machine.

Comment thread src/core/plm/src/lib.rs Resolved
Comment thread src/core/plm/Cargo.toml Resolved
Comment thread README.md Resolved
Comment thread build.bat Resolved
Comment thread src/core/wxc/src/main.rs Resolved
Comment thread src/core/wxc/src/main.rs Resolved
@microsoft-github-policy-service microsoft-github-policy-service Bot added Needs-Attention Requires attention or a decision from the MXC maintainers. and removed Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. labels Jul 2, 2026
Comment thread src/Cargo.toml Resolved
Comment thread src/core/wxc/src/audit.rs Resolved
Comment thread src/core/plm/src/start.rs Resolved
Comment thread src/core/plm/src/stop.rs Resolved
Comment thread src/core/plm/src/stop.rs Resolved
The step references run_plm_test.ps1 which does not exist on this branch (arrives in the testing PR). A dedicated PLM integration test job belongs on the branch that ships the script.
Removes the runtime feature that reordered every serde_json Map — which was the sole cause of the dev schema on this branch differing from main. The feature was consumed only by a dead type alias in plm/src/config.rs. Regenerated dev schema now matches main byte-for-byte.
Substitute neutral placeholder paths in the plm readme (C:\Tessera\mxc -> C:\src\mxc).
…doc-comment ctrl-handler globals

- start.rs / stop.rs: switch wpr.exe spawns from .status() to .output()
  so successful runs stay silent; replay captured stdout+stderr on
  non-zero exit via shared start::replay_wpr_output. Fixes the
  wxc-exec --audit stdio pollution called out in comments
  r3514558858 / r3514562221 / r3514564478.
- wxc/src/audit.rs: capture plm.exe stdio via .output() so the
  audit-mode background trace never leaks plm chatter into the
  wrapped workload's console. On failure (and in --verbose) the
  captured streams are replayed via a shared replay_child_output
  helper. Fixes r3502009755 / r3502010101 / r3502010465 / r3514551150.
- coordination.rs: switch singleton acquire from
  CreateMutexW(bInitialOwner=true) + ERROR_ALREADY_EXISTS to
  CreateMutexW + WaitForSingleObject(0) so a previous owner that
  crashed (WAIT_ABANDONED) no longer blocks the singleton forever
  and forces a reboot. Addresses r3503721112.
- main.rs: expand PLM_TRACE_ACTIVE doc-comment to explain why it's
  a process-wide static (Windows ctrl-handler callback context has
  no captured self — must reach state via globals). Expand
  plm_ctrl_handler doc to explain why polling is used instead of a
  wait-object (wpr's kernel-session engagement isn't OS-signalled;
  bounded 40-poll worst case stays well under the ~5s ctrl-handler
  kill budget). Addresses r3503762141 / r3503729778.
- stop.rs: drop redundant _pid<PID> suffix from log-dir stamp;
  sub-second (%H%M%S%.3f) is already collision-safe. Addresses
  r3503525035.

Co-authored-by: Copilot <[email protected]>
The atomic itself has to stay a process-wide static because the
Windows console-control handler (plm_ctrl_handler) is an OS-owned
extern "system" callback with no captured self/environment — it
can only reach state via process globals. But all non-signal-context
mutation now goes through &AcquiredSingleton methods:

- mark_trace_active(&self)  — was free fn mark_plm_trace_active
- clear_trace_active(&self) — was free fn clear_plm_trace_active
- cancel_active_trace(&self) — was free fn cancel_active_plm_trace

The compile-time invariant is that trace-active can only be flipped
while we hold the host-wide Global\\Mxc_Plm_Audit singleton mutex —
you can't call these methods without first producing an
AcquiredSingleton. The single remaining free-fn escape hatch,
cancel_active_plm_trace_from_signal(), is documented as callable
only from the ctrl handler (where no &self exists).

Also: AcquiredSingleton::drop now cancels any leftover trace before
releasing the mutex, so an error mid-flow can't leak the kernel
session past exit.

The Cmd::Log flow uses the singleton bypass path (when wxc-exec
--audit already holds the mutex outer-process) — that branch falls
back to touching PLM_TRACE_ACTIVE directly because no local
AcquiredSingleton exists in the bypass case.

Addresses PR584 review comment r3503762141 more thoroughly than the
prior doc-comment-only fix.

Co-authored-by: Copilot <[email protected]>
wpr.exe is catalog-signed, not embedded-signed, so WinVerifyTrust with WINTRUST_ACTION_GENERIC_VERIFY_V2 returns TRUST_E_NOSIGNATURE (0x800B0100) on stock Windows installs. Correctly verifying a catalog-signed binary requires a CryptCATAdmin fallback dance.

Since we resolve the path via GetSystemDirectoryW (not env-spoofable) and %SystemDirectory% write access requires TrustedInstaller, path resolution already is the trust boundary. Reduce verify_wpr_signed() to a sanity file-existence check that surfaces a clear message when WPT isn't installed.

Co-authored-by: Copilot <[email protected]>
`wpr -stop` streams a `100% [>>>>>>>]` progress bar to stdout as it merges the ETL, which pollutes any wrapping tool's console. `stop::WprExeStopper` already captures via `.output()` and replays via `replay_wpr_output` only on failure; apply the same pattern to `log::stop_wpr_trace`.

Co-authored-by: Copilot <[email protected]>
wpr.exe renders its `100% [>>>>>>]` merge progress via `WriteConsoleW`, which writes to the console handle directly and bypasses any stdio pipe redirection (`.stdout(Stdio::piped())` / `.output()`). So even though `log.rs` / `stop.rs` / `start.rs` all already capture wpr's stdout+stderr via `.output()`, the progress bar was still leaking onto the wrapping tool's terminal.

Add CREATE_NO_WINDOW (0x08000000) as a creation flag on the Command returned by wpr_command(), so every wpr.exe child is spawned without an attached console and its WriteConsoleW calls silently no-op. Normal stdout/stderr traffic still flows through the pipes and is replayed on failure via replay_wpr_output.

Co-authored-by: Copilot <[email protected]>
Addresses PR#584 reviewer feedback (bbonaby comments r3503498362, r3503511023, r3503528016, r3503563795, r3503578675, r3503583878, r3507611305). Rewrites the pr1 subcommand summary, `Cmd::Stop` doc, `resolve_bin_path` doc, the `Trace captured at` print, the trailing `verbose logging` message, and the pass-through-options comment so they describe what the code does now rather than deferring to `later PRs`.

The extract-caps subcommand doc entry is removed because Cmd::ExtractCaps isn't wired in this PR (it lands in the split-out PR#587).

Co-authored-by: Copilot <[email protected]>
Detects a non-elevated token at startup (before COM init) and, when
--audit was requested, re-launches the same argv with ShellExecuteExW
+ `runas` so the user sees the standard UAC consent dialog. The
child's exit code is propagated so the outer invoker sees the normal
return contract. UAC decline (ERROR_CANCELLED = 1223) surfaces a
clear `--audit requires elevation` message.

Addresses PR#584 review thread 3501401682.

Co-authored-by: Copilot <[email protected]>
Per PR#584 review (MGudgin): PLM's wpr invocations require
Administrator, but the wxc-exec invariant is that it never runs
elevated. Moving the plm crate into src/host/ (alongside wxc-host-prep)
sets up a follow-up commit that adds a small wxc-host-wpr helper
with a requireAdministrator manifest, keeping the elevated surface
scoped to the wpr command line.

No behavior change in this commit \u2014 path move + Cargo path updates
only.

Co-authored-by: Copilot <[email protected]>
This reverts commit 2feb58e1b2b5bc5aed23975b2ab6b09924ecf4a2.
…lf-relaunch

Restores the invariant that wxc-exec never runs elevated by moving the
elevation requirement onto plm.exe itself, following the wxc-host-prep
pattern.

* Embed a requireAdministrator application manifest on plm.exe
  (release builds only, via embed-manifest crate in build.rs).
* wxc-exec --audit spawns plm.exe via ShellExecuteExW with the "runas"
  verb (new plm_launch module). The elevated child cannot inherit our
  unelevated stdio pipes, so we pass per-invocation capture file paths
  through MXC_PLM_STDOUT_FILE / MXC_PLM_STDERR_FILE env vars; plm.exe
  redirects its stdio to those files on startup via SetStdHandle and
  we replay the captured bytes after the child exits.
* Disable the empty main.rs test binary for the plm crate so
  cargo test -p plm --release does not attempt to launch the
  manifested bin from an unelevated dev shell.

Co-authored-by: Copilot <[email protected]>
ShellExecuteExW + runas does not propagate env vars or stdio handles
across the elevation boundary, so the parent-holds-singleton signal
and the stdio capture paths now ride on hidden CLI flags on plm's Cli
(--wxc-singleton-held-by-parent, --wxc-capture-dir) instead of env
vars. redirect_stdio_from_argv scans argv manually before Cli::parse so
clap parse errors still surface in the capture files.

Co-authored-by: Copilot <[email protected]>
The capture-file handshake previously used a deterministic temp dir
(%TEMP%\mxc-plm-<pid>) that any same-user medium-IL attacker could
pre-squat, and the elevated child opened stdout.log/stderr.log with
plain OpenOptions::create(true) which silently follows reparse points.
A racing attacker could plant those filenames as symlinks pointing at
an admin-only target and have the elevated (admin-token) plm.exe
append attacker-influenceable diagnostic bytes to it — an EoP.

Two defenses layered:

1. plm_launch.rs: use tempfile::Builder with a 16-byte random suffix
   so the dir path isn't guessable, and treat pre-existing dir as
   fatal (no silent reuse).

2. plm/main.rs redirect_one: switch OpenOptions::create(true) to
   create_new(true) so CreateFileW returns ERROR_FILE_EXISTS if
   anything (regular file, symlink, junction) already occupies the
   path — the elevated child either creates the file itself fresh
   or gives up on capture; it will never follow an attacker-planted
   reparse point.

Co-authored-by: Copilot <[email protected]>
Comment described the elevated child as using 'create(true).append(true) +
reparse-point rejection', but the security-fix sibling commit actually
switched to create_new(true) precisely because create(true) has no
reparse-point rejection and silently follows symlinks. A maintainer
trusting the old comment could revert to create(true) and reintroduce
the EoP. Also fix two references to tempdir_in (the code calls tempdir).

Co-authored-by: Copilot <[email protected]>
…sites

Add module-doc paragraphs at plm_launch.rs and audit.rs making the
design invariant explicit at the two files where wxc-exec coordinates
PLM elevation: wxc-exec itself is unelevated, and the WPR/ETW work
that requires admin is delegated to plm.exe (requireAdministrator
manifest) via ShellExecuteExW + runas. Mirrors the existing rationale
in src/host/plm/build.rs. Also update the stale 'via env' phrase in
plm_launch.rs docs to reflect the CLI-flag handshake introduced in
3d3bee8.

Co-authored-by: Copilot <[email protected]>
…atures

* plm_launch.rs: swap WaitForSingleObject INFINITE for a 30 s bound
  (new PLM_ELEVATED_WAIT_MS const) and add a WAIT_TIMEOUT branch that
  TerminateProcess'es the orphan child before CloseHandle so it can't
  finish wpr -start behind our back and leak the kernel logger
  session. Documented that PLM is intended for a single end-to-end
  flow / unit test at a time, so 30 s is sufficient for the supported
  usage.
* audit.rs: fix stale comments that implied wxc-exec ran elevated;
  cancel_active_audit_trace and AUDIT_SINGLETON_HANDLE docs now
  correctly attribute elevation to plm.exe and name the
  --wxc-singleton-held-by-parent bypass.
* Cargo.toml: drop Win32_Security_WinTrust and Win32_Security_Cryptography
  from the workspace windows crate features; no code uses them (only
  stale comments in plm's wpr_path.rs / main.rs which explicitly say
  we do NOT call WinVerifyTrust).

Co-authored-by: Copilot <[email protected]>
@lilybarkley-msft
Lily Barkley (lilybarkley-msft) force-pushed the user/lilybarkley/plm-pr1-audit-skeleton branch from cdd12e8 to 673a3bc Compare July 7, 2026 01:50
The umbrella build stages plm.exe into sdk/bin/<arch> alongside
wxc-exec.exe when the plm crate is part of the workspace build.
The SDK 'no unexpected binaries' package test fails because
plm.exe wasn't in any allowed list.

Add 'plm.exe' to OPTIONAL_BINARIES (mirroring the wslcsdk.dll
pattern) so builds with and without plm.exe both pass the
integration test, without forcing every build to produce it.

Co-authored-by: Copilot <[email protected]>
Resolve README.md conflict by keeping both the Audit Mode section and the Telemetry section.

Co-authored-by: Copilot <[email protected]>
@lilybarkley-msft
Lily Barkley (lilybarkley-msft) merged commit aca8461 into main Jul 8, 2026
32 of 33 checks passed
@lilybarkley-msft
Lily Barkley (lilybarkley-msft) deleted the user/lilybarkley/plm-pr1-audit-skeleton branch July 8, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants