Skip to content

Set DOTNET_EnableWriteXorExecute=0 for OpenDebugAD7 when the file size limit is below 2 TiB - #14886

Open
Ming (MaxonT) wants to merge 1 commit into
microsoft:mainfrom
MaxonT:contrib/13768-auto
Open

Ming (MaxonT) wants to merge 1 commit into
microsoft:mainfrom
MaxonT:contrib/13768-auto

Conversation

@MaxonT

Copy link
Copy Markdown

The strace in the issue made the cause easy to find. I could not run this on Linux, so the end-to-end behavior is untested.

Fixes #13768.

The strace in the issue shows the .NET runtime creating a memfd called "doublemapper" (its W^X mapping) and calling ftruncate(fd, 2 TiB). With ulimit -f below 2 TiB that returns EFBIG and the process gets SIGXFSZ, so OpenDebugAD7 dies at startup.

This adds a small helper that reads /proc/self/limits on Linux. If the soft Max file size is below 2 TiB and DOTNET_EnableWriteXorExecute is not already set, the adapter is started with DOTNET_EnableWriteXorExecute=0 through the env option of DebugAdapterExecutable (VS Code merges it with the parent environment). In every other case nothing changes: other platforms, unlimited or large limits, an unreadable /proc, and a value the user already set. I scoped it to low limits so the W^X hardening stays on for everyone else.

Testing

  • New test/unit/debugAdapterEnvironment.test.ts (4 tests) covers the threshold (2 TiB minus 1 byte triggers, exactly 2 TiB and unlimited do not), the platform check, missing or unparsable input, and a user-set value. It passed when compiled with tsc and run with mocha outside the repo's yarn test flow. Flipping the comparison in the helper makes 2 of the 4 fail.
  • Type-checked the changed files with tsc; only unrelated missing-dependency errors showed up because I did not run yarn install.

Not verified: I did not run the extension or OpenDebugAD7, and I have no Linux machine with ulimit -f set, so the crash fix itself is untested end to end. I did not run the full yarn test suite or the lint. I did not add a CHANGELOG line because the top section (1.36.0) looks already released; happy to add one wherever you prefer.

…e limit is below 2 TiB

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>

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

The W^X-hardening workaround lacks end-to-end Linux validation of bundled OpenDebugAD7 startup under low RLIMIT_FSIZE and preservation of unlimited-limit behavior and explicit overrides.

No open issues 🎉

What changed in this PR

This PR addresses #13768 by disabling .NET W^X double mapping for OpenDebugAD7 on Linux when the soft file-size limit is below 2 TiB, preventing the reported startup crash.

Changes:

  • Adds a helper to detect low file-size limits while preserving user-set environment values.
  • Reads /proc/self/limits and applies the environment override when launching the debug adapter.
  • Adds unit tests for threshold boundaries, platform checks, missing input, and user overrides. End-to-end Linux behavior remains unverified.
File Description
Extension/​test/​unit/​debugAdapterEnvironment.test.ts Tests limit detection and environment override conditions.
Extension/​src/​Debugger/​debugAdapterEnvironment.ts Determines when to disable .NET W^X double mapping.
Extension/​src/​Debugger/​debugAdapterDescriptorFactory.ts Reads Linux limits and passes overrides to OpenDebugAD7.

Review effort: Balanced

* An existing DOTNET_EnableWriteXorExecute value set by the user is never overridden.
*/
export function getDebugAdapterEnvironment(platform: string, processEnv: NodeJS.ProcessEnv, procLimits: string | undefined): { [key: string]: string } | undefined {
if (platform !== 'linux' || processEnv.DOTNET_EnableWriteXorExecute !== undefined || procLimits === undefined) {

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.

✨Copilot (devbox7-wsl/agent61): [Moderate] .NET also accepts COMPlus_EnableWriteXorExecute, and checks DOTNET_ before COMPlus_. With a low file-size limit and COMPlus_EnableWriteXorExecute=1 but no DOTNET_ value, this adds DOTNET_EnableWriteXorExecute=0, silently disabling W^X despite the user's explicit setting. Could this preserve the COMPlus_ value too and cover that case in a test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pull Request

Development

Successfully merging this pull request may close these issues.

Debugger fails under Linux if file size limits are in effect

3 participants