Repository navigation
Fix dotnet host resolution under proot (ARM64/Termux) - #16462
Azat Mukhametshin (azat-msft) merged 3 commits into
Conversation
ProcessHelper.GetCurrentProcessFileName used Process.MainModule.FileName to
identify the running executable. Under proot the value can be the injected
proot loader instead of the running dotnet host, so DotnetTestHostManager and
DotnetHostHelper stop recognizing the current process as dotnet, fall back to
searching DOTNET_ROOT* and the well known installation folders, and finally
fail with:
Could not find 'dotnet' host for the '<arch>' architecture.
.NET builds MainModule from /proc/<pid>/maps. proot translates
readlink("/proc/self/exe") to the guest path, but it cannot rewrite the
contents of /proc/<pid>/maps, which keep the host path. When the two differ,
ProcessManager.GetModules cannot match the executable and leaves the lowest
mapped module first. On ARM64 proot maps its loader below the executable
(LOADER_ADDRESS 0x2000000000 < EXEC_PIC_ADDRESS 0x3000000000, see proot
src/arch.h), so that first module is the loader. On x64 the order is reversed,
which is why this only reproduces on ARM64.
Prefer Environment.ProcessPath on .NET. It does not depend on the /proc maps
ordering and proot reports it correctly. The change is guarded by #if NET so
.NET Framework keeps the existing MainModule behavior, and it falls back to
MainModule when ProcessPath is null.
Verified with real proot 5.4.1 by reproducing both required conditions on x64
(guest/host path mismatch plus a loader relocated below the executable):
baseline aborts with the error above, the fixed build runs the tests. No
behavior change outside proot.
Fixes microsoft#16446
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The new unit test currently assumes Environment.ProcessPath is always non-null on .NET, despite the production code explicitly supporting a fallback path.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR addresses dotnet host resolution failures when running dotnet test inside proot (notably on ARM64/Termux) by making ProcessHelper.GetCurrentProcessFileName() prefer Environment.ProcessPath on .NET, avoiding incorrect Process.MainModule.FileName values when proot injects a loader.
Changes:
- Update
ProcessHelper.GetCurrentProcessFileName()to returnEnvironment.ProcessPathon .NET (with a fallback toMainModulewhen unavailable). - Add a unit test validating
GetCurrentProcessFileName()behavior across TFMs.
File summaries
| File | Description |
|---|---|
| src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs | Prefer Environment.ProcessPath to correctly identify the running executable under proot/sandboxed environments. |
| test/vstest.console.UnitTests/ProcessHelperTests.cs | Add a regression test for GetCurrentProcessFileName() and update class documentation. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Environment.ProcessPath is nullable, and GetCurrentProcessFileName falls back to MainModule when it is null. The test asserted against ProcessPath directly, so it would have failed in a host where ProcessPath is null even though the production fallback behaved correctly. Compute the expected value the same way the production code does instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, matches the documented root cause in proot, and is covered by a new cross-TFM unit test mirroring the production fallback behavior.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
| // rather than the running executable under sandboxes such as proot. See issue #16446. | ||
| // ProcessPath is nullable, so mirror the fallback the production code performs instead of | ||
| // assuming it is always set. | ||
| string? expectedFileName = Environment.ProcessPath ?? mainModuleFileName; |
There was a problem hiding this comment.
This test does not exercise the regression on normal CI hosts. Environment.ProcessPath and Process.MainModule.FileName normally resolve to the same executable, so the pre-change implementation—which always returned MainModule.FileName—also satisfies this assertion. Because the expected value mirrors the production fallback, the test only distinguishes the implementations when it already runs under an environment reproducing the proot discrepancy.
Please add a controllable seam and test distinct values explicitly (prefer ProcessPath when available, and fall back to MainModule when it is null), or add an automated proot scenario; otherwise this regression can return without the test failing.
There was a problem hiding this comment.
I changed the GetCurrentProcessFileName() function to have internal parameterized overload, so it can be tested in unit tests.
Creating a separate arm64 leg that would test the behavior in different infrastructure under proot looks like too big of a change for this PR.
Keep the public method parameterless and expose internal test-only path readers to cover preference and fallback behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e228b330-4684-40b2-9abe-ace56bd4f221
There was a problem hiding this comment.
🟢 Approval recommended
The change is small, targeted to the reported root cause, preserves fallback behavior, and includes focused unit tests covering the new logic.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
12888c8
into
microsoft:main
Updated [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 18.11.1 to 18.12.0. <details> <summary>Release notes</summary> _Sourced from [Microsoft.NET.Test.Sdk's releases](https://github.com/microsoft/vstest/releases)._ ## 18.12.0 ## Security fix This release includes the fix for CVE-2026-105544, an elevation of privilege vulnerability in the VSTest artifact post-processor. The post-processor could consume a forged `executionComplete.json` written by another local user, and then run attacker-controlled output handling. Affected: `Microsoft.TestPlatform.CLI` 18.11.0 and earlier. Every version from 18.11.1 on is fixed, including 18.12.0. `Microsoft.TestPlatform.CLI` is the VSTest build that we ship into the .NET SDK. The recommended way to get this fix is to update your .NET SDK to the latest patched version, see the advisory for the SDK versions. The fix is also released in the `Microsoft.TestPlatform.CLI` package, for completeness. That package is rarely used directly. It is not a dependency of `Microsoft.NET.Test.Sdk` or `Microsoft.TestPlatform`, so those packages do not bring it in. Details: https://github.com/microsoft/vstest/issues/16654 and https://github.com/dotnet/announcements/issues/517 Using custom Docker images or Nano Server? See https://github.com/microsoft/vstest/issues/16652 ## What's Changed * Fix TestCaseStart/Stop events dropped for data-driven tests with shared TestCase.Id by @nohwnd in https://github.com/microsoft/vstest/pull/16033 * Stop the discovery manager factory from shadowing discoveryCriteria by @nohwnd in https://github.com/microsoft/vstest/pull/16391 * Gate the HTTP link checker on a fingerprint of the broken links by @nohwnd in https://github.com/microsoft/vstest/pull/16413 * Quote boolean conditions in shipped Microsoft.TestPlatform.targets by @nohwnd in https://github.com/microsoft/vstest/pull/16404 * Obsolete API hygiene: the compatibility-safe changes by @azat-msft in https://github.com/microsoft/vstest/pull/16420 * Add xxHash128 test ids, available but not default by @azat-msft in https://github.com/microsoft/vstest/pull/16378 * Isolate attachment manager test temporary files by @mmitche in https://github.com/microsoft/vstest/pull/16463 * Test ids report logger by @azat-msft in https://github.com/microsoft/vstest/pull/16443 * Isolate code coverage files in published output by @azat-msft in https://github.com/microsoft/vstest/pull/16483 * Preserve OutputType for Android test projects by @jonathanpeppers in https://github.com/microsoft/vstest/pull/16496 * Fix dotnet host resolution under proot (ARM64/Termux) by @azat-msft in https://github.com/microsoft/vstest/pull/16462 * Mark the xxHash128 test id API as experimental by @azat-msft in https://github.com/microsoft/vstest/pull/16465 * Ship Microsoft.Diagnostics.NETCore.Client in Microsoft.TestPlatform and Portable packages by @nohwnd in https://github.com/microsoft/vstest/pull/16633 * Fix localized resource paths in CLI source-build/non-Windows packages by @nohwnd in https://github.com/microsoft/vstest/pull/16644 **Full Changelog**: https://github.com/microsoft/vstest/compare/v18.11.0...v18.12.0 Commits viewable in [compare view](https://github.com/microsoft/vstest/compare/v18.11.1...v18.12.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Fixes #16446
Under proot,
Process.MainModule.FileNamecan return proot'sloaderpath instead of the runningdotnetexecutable. VSTest then fails to recognizedotnetand reports that it cannot find a host for the requested architecture.Use
Environment.ProcessPathon .NET to get the executable path. Keep the existing lookup for .NET Framework and as a fallback whenProcessPathis null.