Repository navigation
Set DOTNET_EnableWriteXorExecute=0 for OpenDebugAD7 when the file size limit is below 2 TiB - #14886
Ming (MaxonT) wants to merge 1 commit into
Conversation
…e limit is below 2 TiB Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
There was a problem hiding this comment.
🔵 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/limitsand 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) { |
There was a problem hiding this comment.
✨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?
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). Withulimit -fbelow 2 TiB that returns EFBIG and the process gets SIGXFSZ, soOpenDebugAD7dies at startup.This adds a small helper that reads
/proc/self/limitson Linux. If the softMax file sizeis below 2 TiB andDOTNET_EnableWriteXorExecuteis not already set, the adapter is started withDOTNET_EnableWriteXorExecute=0through theenvoption ofDebugAdapterExecutable(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
test/unit/debugAdapterEnvironment.test.ts(4 tests) covers the threshold (2 TiB minus 1 byte triggers, exactly 2 TiB andunlimiteddo not), the platform check, missing or unparsable input, and a user-set value. It passed when compiled withtscand run with mocha outside the repo'syarn testflow. Flipping the comparison in the helper makes 2 of the 4 fail.tsc; only unrelated missing-dependency errors showed up because I did not runyarn install.Not verified: I did not run the extension or OpenDebugAD7, and I have no Linux machine with
ulimit -fset, so the crash fix itself is untested end to end. I did not run the fullyarn testsuite 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.