Skip to content

Preventing IsoSession relay Ctrl Handler from accessing closed stop-event handle - #1504

Merged
Dom Giandinoto (daamenik) merged 5 commits into
mainfrom
user/dgiandinoto/fix-ctrl-handler-race
Oct 16, 2026
Merged

Dom Giandinoto (daamenik) merged 5 commits into
mainfrom
user/dgiandinoto/fix-ctrl-handler-race

Conversation

@daamenik

@daamenik Dom Giandinoto (daamenik) commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

📖 Description

When running a process through the IsoSession backend's interactive console, MXC creates a Ctrl-handler to handle Ctrl-C and cmd.exe Close via Win32's SetConsoleCtrlHandler(). That ctrl-handler contains the integer payload of a stop-event that MXC's stdin relay to the IsoSession backend listens to. In the rare event in which the stop-event's handle is closed (when it's dropped at the end of create_process) before the ctrl-handler signals it, the handler could be signaling a closed handle, which is not good.

This PR adds a lock for where the stop-event handle is modified to prevent the use-after-free.

🔍 Validation

Added test_ctrl_handler_target_survives_guard_teardown and ensured its passage.

✅ Checklist

📋 Issue Type

  • Bug fix
  • Feature
  • Task

GitHub Actions runs the PR validation build automatically. The ADO pipeline
(MXC-PR-Build) is the Azure version of the PR pipeline, kept in parity with the GitHub
Actions build; it runs on merge to main, and Microsoft reviewers with write access can trigger it
on a PR with /azp run. See pull request builds.

If the dependency-feed-check check fails on a new dependency, the crate must be added to
the feed before the PR can pass. See pull request builds
for the steps.

Microsoft Reviewers: Open in CodeFlow

Copilot AI balanced review requested due to automatic review settings October 14, 2026 23:46
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@daamenik Dom Giandinoto (daamenik) changed the title Preventing IsoSession relay Ctrl Handler from accessing reset stop-event handle Preventing IsoSession relay Ctrl Handler from accessing closed stop-event handle Oct 14, 2026

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.

🟡 Changes recommended

Shared-event reuse allows delayed callbacks and surviving relay threads to interfere with subsequent executions.

2 open findings
What changed in this PR

This PR prevents IsolationSession console Ctrl handlers from signaling a closed stop-event handle.

Changes:

  • Reuses a process-lifetime stop event for interactive executions.
  • Preserves per-execution event ownership for non-interactive runs.
  • Adds a regression test for signaling after guard teardown.
File Description
src/​mxc-sdk/​src/​backends/​isolation_session/​common/​manager.rs Selects stop-event ownership based on interactive mode.
src/​mxc-sdk/​src/​backends/​isolation_session/​common/​console_mode.rs Adds persistent event initialization, reset, and teardown coverage.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/mxc-sdk/src/backends/isolation_session/common/console_mode.rs Outdated
Comment thread src/mxc-sdk/src/backends/isolation_session/common/manager.rs Outdated
Copilot AI balanced review requested due to automatic review settings October 15, 2026 20:27

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.

🟡 Changes recommended

The regression tests bypass the concurrent callback/teardown interaction and would not detect removal of the locking fix.

1 open finding
2 resolved since last review

🧠 Review effort: Balanced

Comment thread src/mxc-sdk/src/backends/isolation_session/common/console_mode.rs Outdated
Copilot AI balanced review requested due to automatic review settings October 15, 2026 23:51

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.

🔵 Needs a closer look

Windows callback synchronization needs native validation and final human review despite no identified defects.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 16, 2026 17:05

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.

🔵 Needs a closer look

Windows console-dispatch lock ordering needs human verification beyond the direct-callback tests.

0 open findings

🧠 Review effort: Balanced

@daamenik
Dom Giandinoto (daamenik) marked this pull request as ready for review October 16, 2026 17:30
@daamenik
Dom Giandinoto (daamenik) requested a review from a team as a code owner October 16, 2026 17:30
@daamenik
Dom Giandinoto (daamenik) merged commit 54545d8 into main Oct 16, 2026
31 checks passed
@daamenik
Dom Giandinoto (daamenik) deleted the user/dgiandinoto/fix-ctrl-handler-race branch October 16, 2026 18:53
@daamenik
Dom Giandinoto (daamenik) restored the user/dgiandinoto/fix-ctrl-handler-race branch October 16, 2026 19:09
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.

3 participants