Skip to content

Decode escaped Linux mountinfo paths - #137195

Merged
krwq merged 1 commit into
mainfrom
krwq-linux-mount-path-decoding
Nov 12, 2026
Merged

krwq merged 1 commit into
mainfrom
krwq-linux-mount-path-decoding

Conversation

@krwq

@krwq krwq commented Nov 9, 2026

Copy link
Copy Markdown
Member

Note

This pull request was generated with AI (GitHub Copilot).

Fixes #123347.

Summary

Decode escaped Root and MountPoint paths when parsing Linux /proc/self/mountinfo. This fixes DriveInfo.GetDrives() and Environment.GetLogicalDrives() returning paths such as /run/media/user/DISC\0403 instead of /run/media/user/DISC 3. The shared parser also supplies filesystem-type lookup and cgroup path construction.

The Linux getmntent(3) documentation describes the mount-table escaping convention:

... octal escapes are used to represent the characters space (\040), tab (\011), newline (\012), and backslash (\\) ...

When converting from escaped representation, the sequence \134 is also converted to a backslash.

Use the existing ValueStringBuilder pattern to decode these escapes in one pass. Unescaped paths retain spans into the input without allocating. Decode only the original input, so \134040 becomes literal \040, not a space. Leave filesystem-type and super-options fields unchanged.

Extend the parser tests for both path fields, combined and literal escapes, unknown/truncated sequences, Unicode, stack/pool buffer boundaries, and the unchanged zero-copy path. No new public API or platform support is added.

Validation

Run on Windows with the local .NET 12 build:

Command Result
.\build.cmd -rc Release -s clr+libs Passed, 0 warnings/errors. Run before the final debug-only entry assertion; the targeted commands below passed again after that assertion was added.
.\.dotnet\dotnet.exe build src\libraries\Common\tests\Common.Tests.csproj /t:Test /p:RuntimeConfiguration=Release Passed: 1,757 tests, 0 failures/skips.
.\.dotnet\dotnet.exe build src\libraries\System.Runtime\tests\System.Runtime.InteropServices.RuntimeInformation.Tests\System.Runtime.InteropServices.RuntimeInformation.Tests.csproj /t:Test /p:RuntimeConfiguration=Release Passed: 15 tests, 0 failures/skips.
.\.dotnet\dotnet.exe build src\libraries\System.IO.FileSystem.DriveInfo\src\System.IO.FileSystem.DriveInfo.csproj /p:TargetOS=linux /p:RuntimeConfiguration=Release /p:BuildProjectReferences=false Passed: all three managed targets, including net12.0-unix.

The expanded parser theory was also run against the original implementation: 18 of 24 cases failed as expected, with no runner errors. All 24 cases, six buffer-boundary cases, and the original-span check pass with the fix.

A source-linked BenchmarkDotNet check on the built .NET 12 runtime measured 0 B for ordinary paths, 72 B for one space-escaped path, and 96 B when both paths contained combined escapes. Large paths use pooled storage; a cold pool can allocate a buffer.

The Linux bind-mount smoke test was not run: this Windows host has no usable WSL installation.

Resolves #123347

AI-generated with GitHub Copilot.

Decode root and mount-point escapes in the shared Linux parser.
Preserve ordinary spans and cover escapes and buffer boundaries.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

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.

🟢 Approval recommended

The mount-path decoding change has no active review issues.

No open issues 🎉

What changed in this PR

Fixes escaped Linux mount paths in the shared /proc/self/mountinfo parser, addressing incorrect drive names and root directories reported in #123347.

Changes:

  • Decodes space, tab, newline, and backslash escapes in Root and MountPoint without decoding literal escapes twice.
  • Preserves zero-copy spans for unescaped paths and leaves filesystem-type and super-options fields unchanged.
  • Adds regression coverage and includes ValueStringBuilder in the affected projects.
File Description
src/​libraries/​System.Runtime/​tests/​System.Runtime.InteropServices.RuntimeInformation.Tests/​System.Runtime.InteropServices.RuntimeInformation.Tests.csproj Includes ValueStringBuilder for the shared parser.
src/​libraries/​System.IO.FileSystem.DriveInfo/​src/​System.IO.FileSystem.DriveInfo.csproj Includes ValueStringBuilder for drive enumeration.
src/​libraries/​Common/​tests/​Tests/​Interop/​procfsTests.cs Covers escapes, malformed sequences, Unicode, buffer boundaries, and input-span preservation.
src/​libraries/​Common/​src/​Interop/​Linux/​procfs/​Interop.ProcMountInfo.TryParseMountInfoLine.cs Adds single-pass decoding for both mount path fields.

Review effort: Balanced

@krwq
krwq requested a review from jozkee November 12, 2026 07:51

@adamsitnik adamsitnik 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.

Holistic Review

Motivation: The linked issue reproduces incorrect Linux drive paths when mount points contain spaces, and the same parser feeds DriveInfo/GetLogicalDrives plus filesystem and cgroup lookups. Correctly decoding the kernel's mountinfo escaping addresses the shared root cause.

Approach: Decoding only Root and MountPoint preserves the other fields and avoids allocations for unescaped paths. The implementation preserves unknown and escaped-literal sequences, and the tests cover those cases as well as Unicode and the stack/pool boundary.

Summary: ✅ LGTM. I found no correctness or compatibility issues in the changed paths. The parser-level tests exercise the key behavior and the downstream consumers all use the shared parser.


Detailed Findings

✅ Shared parser behavior and coverage

The shared parser's decoded spans are consumed by mount enumeration, filesystem-type lookup, and cgroup mount resolution, so the change fixes the affected consumers at the common source. The added cases cover all four documented escapes, combined and literal escapes, malformed/unknown sequences, long paths, and retention of input-backed spans for ordinary paths.

Note

This review was created by GitHub Copilot.

@adamsitnik adamsitnik 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.

LGTM, thank you for fixing it @krwq !

@krwq
krwq merged commit e0bc8a0 into main Nov 12, 2026
90 checks passed
@krwq
krwq deleted the krwq-linux-mount-path-decoding branch November 12, 2026 09:52
@krwq

krwq commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@krwq

krwq commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

@krwq

krwq commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Opening bacport PRs to consider per @adamsitnik's offline suggestion

@github-actions

Copy link
Copy Markdown
Contributor

@krwq backporting to release/10.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick e0bc8a0abf07459a1b5b993896e6478c65166106

Auto-merging src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj
Auto-merging src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
CONFLICT (content): Merge conflict in src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
error: could not apply e0bc8a0abf0... Decode escaped Linux mountinfo paths (#137195)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Decode escaped Linux mountinfo paths
Using index info to reconstruct a base tree...
M	src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj
M	src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj
Auto-merging src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
CONFLICT (content): Merge conflict in src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Decode escaped Linux mountinfo paths
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 13, 2026
krwq added a commit that referenced this pull request Nov 17, 2026
> [!NOTE]
> This pull request was generated with AI (GitHub Copilot).

Backport of #137195 to release/10.0

/cc @krwq

Fixes Issue #123347 <!-- Issue Number -->

main PR #137195 <!-- Link to PR if any that fixed this in the main
branch. -->

# Description

<!-- Give a brief summary of the issue and how the pull request is
fixing it. -->

Decode escaped `Root` and `MountPoint` paths when parsing Linux
`/proc/self/mountinfo`. Keep ordinary paths as spans into the input,
decode the four supported escapes in one pass, and preserve unknown or
truncated sequences. A literal `\134040` becomes `\040`, not a space.

The decoding logic and regression tests are unchanged from #137195
(`e0bc8a0abf07459a1b5b993896e6478c65166106`). The only manual conflict
resolution keeps the existing `Interop.UnixFileSystemTypes.cs` compile
item in `System.Runtime.InteropServices.RuntimeInformation.Tests.csproj`
and adds `ValueStringBuilder.cs`. The .NET 10 target frameworks and
project layout are unchanged.

Changed files, under `src\libraries\`:

-
`Common\src\Interop\Linux\procfs\Interop.ProcMountInfo.TryParseMountInfoLine.cs`
- `Common\tests\Tests\Interop\procfsTests.cs`
-
`System.IO.FileSystem.DriveInfo\src\System.IO.FileSystem.DriveInfo.csproj`
-
`System.Runtime\tests\System.Runtime.InteropServices.RuntimeInformation.Tests\System.Runtime.InteropServices.RuntimeInformation.Tests.csproj`

# Customer Impact

<!-- What is the impact to customers of not taking this fix? -->

- [x] Customer reported
- [ ] Found internally

#123347 reports a .NET 10 regression on Linux. For a mounted volume
whose label contains spaces, `DriveInfo.GetDrives()` returns a name such
as `/run/media/user/DISC\0403` instead of `/run/media/user/DISC 3`.
`RootDirectory` is incorrect, and `DriveType` can be `NoRootDirectory`
instead of `CDRom`. `Environment.GetLogicalDrives()` is also affected.

Without this fix, applications cannot reliably use those returned paths.
The shared parser also supplies filesystem-type lookup and cgroup paths.
The change handles the Linux mount-table escapes for spaces, tabs,
newlines, and backslashes.

# Regression

<!-- Is this fixing a problem that was introduced in the most recent
release, ie., fixing a regression? -->

- [x] Yes
- [ ] No

Introduced in .NET 10 by #116102, which switched Linux mount-point
enumeration and filesystem-type lookup to `/proc/self/mountinfo`. The
customer reports that the same code worked on .NET 8 and .NET 9.

# Testing

<!-- What kind of testing has been done with the fix. -->

All results below are from this .NET 10 worktree, based on
`56d5bb652aced6bb4fed74ab43fbdd4c39b6b7ed`, using the pinned SDK
`10.0.114` and locally built .NET `10.0.16` binaries. Windows uses
Release CoreCLR and Debug libraries/tests; browser uses Debug Mono.
Builds for different targets were run serially.

The fixed code passed 1,701 Common tests, 13 existing cgroup mount/path
cases, 15 RuntimeInformation tests, and 24 DriveInfo tests on Windows.
The Linux-managed DriveInfo build passed all three target frameworks.
Browser Common passed 1,124 tests; browser RuntimeInformation passed 9
tests with 3 existing remote-executor skips. All 31 mountinfo parser
cases passed on both Windows and browser, including the six
buffer-boundary cases and the original-input-span check.

**Pre-existing browser limitation:** both browser commands returned 0
and wrote successful test results, but the Debug WASM runner then logged
a `runtimeKeepalivePop` shutdown assertion and "Application exited
without sending a wasm exit message." This was also reproduced with the
exact original release/10.0 CoreLib parser and original Common test
source: 1,098 tests passed, with the same shutdown diagnostics and exit
code 0. This backport does not change the WASM runtime or runner.

No live Linux mount smoke test or WASI runtime test was run on this
Windows host. No shared mount state was changed.

<details>
<summary>Exact local build and test commands and results</summary>

Commands ran from a temporary short path to this worktree to avoid
Windows path-length limits. `%CD%` below replaces that worktree root.

| Command | Result |
| --- | --- |
| `.\build.cmd -rc Release -s clr+libs` | Passed before changes
(20:56.11) and after the port (10:31.55); 0 MSBuild warnings/errors. |
| `.\build.cmd mono+libs -os browser` | Passed before changes
(28:27.48); 0 MSBuild warnings/errors. |
| `.\build.cmd mono.corelib+mono.wasmruntime+libs.pretest -os browser` |
Passed after the port and again after restoring the fixed product from
the baseline comparison (final run 2:07.71); 0 MSBuild warnings/errors.
|
| `.\.dotnet\dotnet.exe build
src\libraries\Common\tests\Common.Tests.csproj /t:Test
/p:RuntimeConfiguration=Release` | Passed: 1,701 tests, 0
failures/skips/runner errors. |
| `.\.dotnet\dotnet.exe build
src\libraries\System.Runtime\tests\System.Runtime.InteropServices.RuntimeInformation.Tests\System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
/t:Test /p:RuntimeConfiguration=Release` | Passed: 15 tests, 0
failures/skips/runner errors. |
| `.\.dotnet\dotnet.exe build
src\libraries\System.IO.FileSystem.DriveInfo\tests\System.IO.FileSystem.DriveInfo.Tests.csproj
/t:Test /p:RuntimeConfiguration=Release` | Passed: 24 tests, 0
failures/skips/runner errors. |
| `.\.dotnet\dotnet.exe build
src\libraries\System.IO.FileSystem.DriveInfo\src\System.IO.FileSystem.DriveInfo.csproj
/p:TargetOS=linux /p:RuntimeConfiguration=Release
/p:BuildProjectReferences=false` | Passed: `net10.0`, `net10.0-unix`,
and `net10.0-windows`; 0 warnings/errors. |
| `.\.dotnet\dotnet.exe tool restore --tool-manifest
%CD%\.config\dotnet-tools.json` | Passed; restored the repository's
pinned test tools. |
| `.\.dotnet\dotnet.exe build
src\libraries\Common\tests\Common.Tests.csproj /t:Test
/p:TargetOS=browser /p:TargetArchitecture=wasm /p:RuntimeFlavor=Mono
/p:InstallV8ForTests=true
/p:WasmXHarnessArgsCli=--js-engine-path=%CD%\artifacts\bin\v8-13.9.205\d8.exe`
| 1,124 tests passed, 0 failures/skips/runner XML errors; command exit
0. Pre-existing shutdown limitation described above. |
| `.\.dotnet\dotnet.exe build
src\libraries\System.Runtime\tests\System.Runtime.InteropServices.RuntimeInformation.Tests\System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
/t:Test /p:TargetOS=browser /p:TargetArchitecture=wasm
/p:RuntimeFlavor=Mono /p:InstallV8ForTests=true
/p:WasmXHarnessArgsCli=--js-engine-path=%CD%\artifacts\bin\v8-13.9.205\d8.exe`
| 9 passed, 3 existing remote-executor skips, 0 failures/runner XML
errors; command exit 0. Same pre-existing shutdown limitation. |

For browser execution, `XHARNESS_CLI_PATH` selected the restored
`microsoft.dotnet.xharness.cli\11.0.0-prerelease.26556.1\tools\net10.0\any\Microsoft.DotNet.XHarness.CLI.dll`
under the NuGet global-packages cache. The existing repository target
provisioned V8 `13.9.205`. The three RuntimeInformation skips require
`RemoteExecutor.IsSupported`; no tests were disabled or changed to skip.

Supplemental controls used ignored scratch MSBuild compile-item
overrides, not changes to the committed projects. Final product and
normal test projects were rebuilt without those overrides.

```cmd
.\.dotnet\dotnet.exe build src\libraries\Common\tests\Common.Tests.csproj /t:Test /p:RuntimeConfiguration=Release /p:CustomAfterMicrosoftCommonTargets=%CD%\artifacts\tmp\backport-validation.targets /p:BackportOriginalParser=%CD%\artifacts\tmp\backport-original-parser.cs /p:XUnitMethodName=Common.Tests.procfsTests.ParseMountInfoLine_Success
```

Expected failure with the original parser: 18 of 24 cases failed, with 0
skips or runner errors. The source snapshot matched original blob
`dc89ddb285e78a4566120cec0b3aa5132c9d1bfe`. All cases pass with the fix.

```cmd
.\.dotnet\dotnet.exe build src\libraries\System.Runtime\tests\System.Runtime.InteropServices.RuntimeInformation.Tests\System.Runtime.InteropServices.RuntimeInformation.Tests.csproj /t:Test /p:RuntimeConfiguration=Release /p:CustomAfterMicrosoftCommonTargets=%CD%\artifacts\tmp\backport-validation.targets /p:BackportIncludeCgroupTests=true /p:XUnitOptions="-method Common.Tests.cgroupsTests.ParseValidateMountInfo -method Common.Tests.cgroupsTests.ValidateFindCGroupPath"
```

Passed: all 13 existing cgroup mountinfo/path cases, source-linked into
the RuntimeInformation test harness on Windows; 0 failures/skips/runner
errors. The normal RuntimeInformation project was then rebuilt and its
15 tests passed without the supplemental inclusion.

The bounded browser baseline comparison used these commands with exact
original parser and test-source snapshots:

```cmd
.\build.cmd mono.corelib+mono.wasmruntime+libs.pretest -os browser /p:CustomAfterMicrosoftCommonTargets=%CD%\artifacts\tmp\backport-validation.targets /p:BackportOriginalProduct=true /p:BackportOriginalParser=%CD%\artifacts\tmp\backport-original-parser.cs
.\.dotnet\dotnet.exe build src\libraries\Common\tests\Common.Tests.csproj /t:Test /p:TargetOS=browser /p:TargetArchitecture=wasm /p:RuntimeFlavor=Mono /p:InstallV8ForTests=true /p:WasmXHarnessArgsCli=--js-engine-path=%CD%\artifacts\bin\v8-13.9.205\d8.exe /p:CustomAfterMicrosoftCommonTargets=%CD%\artifacts\tmp\backport-validation.targets /p:BackportOriginalProduct=true /p:BackportOriginalParser=%CD%\artifacts\tmp\backport-original-parser.cs /p:BackportOriginalProcfsTests=%CD%\artifacts\tmp\backport-original-procfsTests.cs
```

Both commands returned 0. Original Common tests: 1,098 passed, 0
failures/skips/runner XML errors, with the same shutdown assertion. The
original procfs test snapshot matched blob
`707a9f7954491aa4ad8a36858d11ab6da9f05d57`. The fixed browser product
was restored and both final browser suites were rerun afterward.

</details>

# Risk

<!-- Please assess the risk of taking this fix. Provide details backing
up your assessment. -->

Low. This is the already-merged managed fix, with no decoding changes
for the backport, no new public APIs, and no native-code changes. Only
the two path fields are decoded, and only when they contain a backslash.
Ordinary paths retain their input-backed spans. Filesystem-type and
super-options fields are unchanged; unknown/truncated sequences and
literal escaped backslashes are covered by regression tests.

The sole manual project-file resolution retains the .NET 10-specific
compile item rather than replacing it. Builds and tests cover the
parser, its cgroup callers, both affected project files, Linux-managed
compilation, and browser compilation/execution. The pre-existing WASM
shutdown limitation is called out above rather than changed in this
backport.

**IMPORTANT**: If this backport is for a servicing release, please
verify that:

- For .NET 8 and .NET 9: The PR target branch is `release/X.0-staging`,
not `release/X.0`.
- For .NET 10+: The PR target branch is `release/X.0` (no `-staging`
suffix).

# Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet
package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older
versions.

> AI-generated with GitHub Copilot.

Co-authored-by: Copilot App <[email protected]>
krwq added a commit that referenced this pull request Nov 17, 2026
> [!NOTE]
> This pull request description was updated with AI (GitHub Copilot).

Backport of #137195 to release/11.0

/cc @krwq

Fixes Issue #123347 <!-- Issue Number -->

main PR #137195 <!-- Link to PR if any that fixed this in the main
branch. -->

# Description

<!-- Give a brief summary of the issue and how the pull request is
fixing it. -->

Decode escaped `Root` and `MountPoint` paths when parsing Linux
`/proc/self/mountinfo`. Keep ordinary paths as spans into the input,
decode the four supported escapes in one pass, and preserve unknown or
truncated sequences. A literal `\134040` becomes `\040`, not a space.
Filesystem-type and super-options fields remain unchanged.

This is the automatic .NET 11 backport of #137195
(`e0bc8a0abf07459a1b5b993896e6478c65166106`). The decoder and
regression-test files are byte-for-byte identical to the merged main
fix. Unlike the .NET 10 backport in #137420, this backport did not
require a manual project-file conflict resolution. The project changes
add the shared `ValueStringBuilder.cs` compile item to DriveInfo and
RuntimeInformation.Tests.

Changed files, under `src\libraries\`:

-
`Common\src\Interop\Linux\procfs\Interop.ProcMountInfo.TryParseMountInfoLine.cs`
- `Common\tests\Tests\Interop\procfsTests.cs`
-
`System.IO.FileSystem.DriveInfo\src\System.IO.FileSystem.DriveInfo.csproj`
-
`System.Runtime\tests\System.Runtime.InteropServices.RuntimeInformation.Tests\System.Runtime.InteropServices.RuntimeInformation.Tests.csproj`

# Customer Impact

<!-- What is the impact to customers of not taking this fix? -->

- [x] Customer reported
- [ ] Found internally

#123347 reports incorrect Linux drive information for mounted volumes
whose labels contain spaces. `DriveInfo.GetDrives()` returns a name such
as `/run/media/user/DISC\0403` instead of `/run/media/user/DISC 3`.
`RootDirectory` is incorrect, and `DriveType` can be `NoRootDirectory`
instead of `CDRom`. A [second customer
report](#123347 (comment))
confirms that `Environment.GetLogicalDrives()` is also affected.

Without this fix, applications cannot reliably use those returned paths.
The shared parser also supplies filesystem-type lookup and cgroup paths.
The change handles the Linux mount-table escapes for spaces, tabs,
newlines, and backslashes.

# Regression

<!-- Is this fixing a problem that was introduced in the most recent
release, ie., fixing a regression? -->

- [x] Yes
- [ ] No

Introduced in .NET 10 by #116102, which switched Linux mount-point
enumeration and filesystem-type lookup to `/proc/self/mountinfo`, and
carried forward into .NET 11. The customer reports that the same code
worked on .NET 8 and .NET 9.

# Testing

<!-- What kind of testing has been done with the fix. -->

The added tests cover both pathname fields, all four supported escapes,
combined and literal escapes, unknown/truncated sequences, Unicode,
stack/pool buffer boundaries, and preservation of input-backed spans for
ordinary paths. There are 31 mountinfo parser cases: the expanded
24-case theory, six buffer-boundary cases, and the original-input-span
check. The previous parser coverage did not exercise the escaped
pathname cases.

**Validation scope:** No separate local .NET 11 build or test run was
performed for this description update. The results below are supporting
evidence from the manual **.NET 10** backport in #137420, not .NET 11
test results. Validation of the original main fix is recorded in
#137195. The .NET 11 decoder and regression-test file blobs were
compared with main and match exactly.

On the .NET 10 worktree, the original parser reproduced 18 expected
failures among the 24 theory cases, with no skips or runner errors. The
fixed code passed all 31 parser cases on Windows and browser. Windows
also passed 1,701 Common tests, 13 existing cgroup mount/path cases, 15
RuntimeInformation tests, and 24 DriveInfo tests. The Linux-managed
DriveInfo build passed all three target frameworks. Browser Common
passed 1,124 tests; browser RuntimeInformation passed 9 tests with 3
existing remote-executor skips.

**Pre-existing .NET 10 browser limitation:** the browser commands
returned 0 and wrote successful test results, but the Debug WASM runner
then logged a `runtimeKeepalivePop` shutdown assertion and "Application
exited without sending a wasm exit message." This was also reproduced
with the exact original release/10.0 CoreLib parser and original Common
test source: 1,098 tests passed, with the same shutdown diagnostics and
exit code 0. No WASM runtime or runner changes are included in this fix.
This observation is not a claim about a .NET 11 browser run.

No live Linux mount smoke test or WASI runtime test was run locally. No
shared mount state was changed.

<details>
<summary>Supporting .NET 10 build/test commands and results</summary>

These are the existing results from #137420, using SDK `10.0.114` and
locally built .NET `10.0.16` binaries. Windows uses Release CoreCLR and
Debug libraries/tests; browser uses Debug Mono. Cross-target builds were
run serially. `%CD%` represents that .NET 10 worktree root; these
commands were not rerun against release/11.0 for this description
update.

| Command | Result on the .NET 10 backport |
| --- | --- |
| `.\build.cmd -rc Release -s clr+libs` | Passed before changes and
after the port; 0 MSBuild warnings/errors. |
| `.\build.cmd mono+libs -os browser` | Passed before changes; 0 MSBuild
warnings/errors. |
| `.\build.cmd mono.corelib+mono.wasmruntime+libs.pretest -os browser` |
Passed after the port and again after restoring the fixed product from
the baseline comparison; 0 MSBuild warnings/errors. |
| `.\.dotnet\dotnet.exe build
src\libraries\Common\tests\Common.Tests.csproj /t:Test
/p:RuntimeConfiguration=Release` | Passed: 1,701 tests, 0
failures/skips/runner errors. |
| `.\.dotnet\dotnet.exe build
src\libraries\System.Runtime\tests\System.Runtime.InteropServices.RuntimeInformation.Tests\System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
/t:Test /p:RuntimeConfiguration=Release` | Passed: 15 tests, 0
failures/skips/runner errors. |
| `.\.dotnet\dotnet.exe build
src\libraries\System.IO.FileSystem.DriveInfo\tests\System.IO.FileSystem.DriveInfo.Tests.csproj
/t:Test /p:RuntimeConfiguration=Release` | Passed: 24 tests, 0
failures/skips/runner errors. |
| `.\.dotnet\dotnet.exe build
src\libraries\System.IO.FileSystem.DriveInfo\src\System.IO.FileSystem.DriveInfo.csproj
/p:TargetOS=linux /p:RuntimeConfiguration=Release
/p:BuildProjectReferences=false` | Passed: `net10.0`, `net10.0-unix`,
and `net10.0-windows`; 0 warnings/errors. |
| `.\.dotnet\dotnet.exe build
src\libraries\Common\tests\Common.Tests.csproj /t:Test
/p:TargetOS=browser /p:TargetArchitecture=wasm /p:RuntimeFlavor=Mono
/p:InstallV8ForTests=true
/p:WasmXHarnessArgsCli=--js-engine-path=%CD%\artifacts\bin\v8-13.9.205\d8.exe`
| 1,124 passed, 0 failures/skips/runner XML errors; command exit 0.
Pre-existing shutdown limitation described above. |
| `.\.dotnet\dotnet.exe build
src\libraries\System.Runtime\tests\System.Runtime.InteropServices.RuntimeInformation.Tests\System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
/t:Test /p:TargetOS=browser /p:TargetArchitecture=wasm
/p:RuntimeFlavor=Mono /p:InstallV8ForTests=true
/p:WasmXHarnessArgsCli=--js-engine-path=%CD%\artifacts\bin\v8-13.9.205\d8.exe`
| 9 passed, 3 existing remote-executor skips, 0 failures/runner XML
errors; command exit 0. Same pre-existing shutdown limitation. |

Browser execution used the restored, pinned XHarness `net10.0`
entrypoint through `XHARNESS_CLI_PATH` and repository-provisioned V8
`13.9.205`. The three RuntimeInformation skips require
`RemoteExecutor.IsSupported`; no tests were changed to skip.

The 13 cgroup cases were source-linked into the RuntimeInformation
harness using ignored scratch compile-item overrides. The negative
control and browser baseline comparison also used exact original source
snapshots through scratch overrides. Final product and normal test
projects were rebuilt without those overrides. Full setup, exact
supplemental control commands, baseline comparison, and results are
recorded in #137420.

</details>

# Risk

<!-- Please assess the risk of taking this fix. Provide details backing
up your assessment. -->

Low. This is the already-merged managed fix, with no decoder changes for
the .NET 11 backport, no new public APIs, and no native-code changes.
Only the two pathname fields are decoded, and only when they contain a
backslash. Ordinary paths retain their input-backed spans.
Filesystem-type and super-options fields remain unchanged;
unknown/truncated sequences and literal escaped backslashes are covered
by regression tests.

The two project changes only include the existing shared builder source.
There is no .NET 10-specific conflict resolution in this PR. Supporting
validation covers the shared decoder, cgroup callers, affected project
files, Linux-managed compilation, and browser compilation/execution on
.NET 10; it is not presented as separate .NET 11 execution evidence.

**IMPORTANT**: If this backport is for a servicing release, please
verify that:

- For .NET 8 and .NET 9: The PR target branch is `release/X.0-staging`,
not `release/X.0`.
- For .NET 10+: The PR target branch is `release/X.0` (no `-staging`
suffix).

# Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet
package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older
versions.

> AI-generated with GitHub Copilot.

Co-authored-by: Krzysztof Wicher <[email protected]>
Co-authored-by: Copilot App <[email protected]>
krwq added a commit that referenced this pull request Nov 20, 2026
<!-- -->

Follow-up to [#137195](#137195),
which fixed escaped mount paths reported in
[#123347](#123347). This
addresses offline feedback about stacked-mount selection, separately
from escaped-path decoding.

## Problem

Linux allows another filesystem to be mounted at a directory that is
already a mount point. File access uses the new mount, but
`/proc/self/mountinfo` still lists the earlier one. The current lookup
stops at the first exact-path match, so `DriveInfo` can report the
hidden filesystem instead of the one the path actually reaches.

Choosing the longest matching path is not sufficient either: mounting a
new filesystem at a parent directory also hides mounts below the old
parent.

Both cases were reproduced with real mounts on Ubuntu 24.04.5, Linux
6.12.115-adc.2 x64, using installed .NET 11.0.0:

| Setup | Queried path | Actual `DriveFormat` / `DriveType` | Expected |
|---|---|---|---|
| ext4 bind mount, then tmpfs at the same target | `target` | `ext4` /
`Fixed` | `tmpfs` / `Ram` |
| Same setup | `target/child` | `tmpfs` / `Ram` | `tmpfs` / `Ram` |
| An additional ext4 child mount created before the parent tmpfs mount |
New `target/child` inside tmpfs | `ext4` / `Fixed` | `tmpfs` / `Ram` |

Native `statfs` reported tmpfs for every queried path. The proposed
selector also returned tmpfs for every path when run against the same
live mount table.

## Why fix this

This affects behavior, not just the filesystem name displayed to a user.
For example, code filtering on `DriveType.Fixed` accepts the tmpfs mount
even though it should be classified as `Ram`. The directory and its
child can also disagree despite accessing the same filesystem.

The issue was identified through offline feedback and confirmed with a
controlled Linux reproduction, rather than an exact matching customer
report. This is a correctness fix for the metadata returned by the API;
it does not change mounts, file access, or kernel permissions.

## Change

Follow mount IDs and parent IDs to select the filesystem that is
actually reachable. This handles both same-directory stacks and child
mounts hidden by a newer parent mount, without assuming record order or
selecting the largest mount ID.

Mount identifiers remain spans in the shared parser and are converted
only for matching paths. Mount enumeration, escaped-path decoding, and
native interop are unchanged. No newer kernel feature is required.

## Validation

### Results so far

- Installed .NET 11.0.0: both live mount setups above reproduced the
incorrect public API results. All test mounts were private and removed
afterward; the original namespace's mount table was unchanged.
- Proposed selector: compiled into a standalone harness and returned the
native filesystem type for all queried paths in both live setups.
- Windows tests: **1,833 Common.Tests**, **24 DriveInfo tests**, and
**15 RuntimeInformation tests passed**. Coverage includes 64 selection
cases with reordered records and 12 identifier-preservation cases.
- Linux-targeted managed builds of DriveInfo and Process, including
shared CoreLib, cross-compiled on Windows: **passed**, with no warnings
or errors.

The live comparison exercised the proposed helper, **not a rebuilt
patched public `DriveInfo` assembly**. That end-to-end patched API run
remains outstanding. .NET 10, autofs, and optical media were not
exercised.

### Reproduce the public API bug

No PR, CI, or runtime build is needed. The following recipe was run
successfully with the installed .NET 11 SDK/runtime.

Use a new empty directory on a non-tmpfs/non-ramfs filesystem. This
requires Linux, Bash, GNU coreutils, util-linux, the .NET 11
SDK/targeting pack, and permission to create a private mount namespace
and mounts (`CAP_SYS_ADMIN`). Root inside a restricted container may
still lack that permission. The script refuses to mount anything in the
original namespace.

<details>
<summary>Self-contained reproduction</summary>

Save this as `Program.cs`:

```csharp
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using System.Runtime.InteropServices;

Console.WriteLine($"Runtime: {RuntimeInformation.FrameworkDescription}");
Console.WriteLine($"Namespace: {new FileInfo("/proc/self/ns/mnt").LinkTarget}");
foreach (string path in args)
{
    DriveInfo drive = new(path);
    Console.WriteLine($"{drive.Name}: {drive.DriveFormat}/{drive.DriveType}");
}
```

Save this as `repro.sh`. The local SDK and build configuration files
keep the standalone project independent of the runtime repository's
build settings.

```bash
#!/usr/bin/env bash
set -euo pipefail
case "$(stat -f -c %T .)" in
    tmpfs|ramfs) echo 'Unsupported: use a non-tmpfs/non-ramfs backing directory.' >&2; exit 1 ;;
esac

printf '{"sdk":{"version":"11.0.100","rollForward":"latestFeature"}}\n' > global.json
printf '<Project />\n' | tee Directory.Build.props > Directory.Build.targets
printf '<configuration><packageSources><clear /></packageSources></configuration>\n' > NuGet.Config
printf '<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net11.0</TargetFramework></PropertyGroup></Project>\n' > StackedMountRepro.csproj
export DOTNET_CLI_TELEMETRY_OPTOUT=1 DOTNET_NOLOGO=1 DOTNET_CLI_HOME="$PWD/.dotnet-home"
dotnet build StackedMountRepro.csproj -c Release

unshare --mount --propagation private bash -s -- "$(readlink /proc/self/ns/mnt)" "${HIDDEN_CHILD:-0}" <<'MOUNTS'
set -euo pipefail
test "$(readlink /proc/self/ns/mnt)" != "$1" || { echo 'Refusing original mount namespace.' >&2; exit 99; }
mount --make-rprivate /
mkdir -- lower target hidden-lower
mkdir -- lower/child
mounts=()
cleanup() {
    result=$?
    trap - EXIT
    for ((i=${#mounts[@]}-1; i>=0; i--)); do
        umount -- "${mounts[i]}" || result=1
    done
    rmdir -- target lower/child lower hidden-lower || result=1
    exit "$result"
}
trap cleanup EXIT

mount --bind "$PWD/lower" "$PWD/target"
mounts+=("$PWD/target")
if [[ "$2" == 1 ]]; then
    mount --bind "$PWD/hidden-lower" "$PWD/target/child"
    mounts+=("$PWD/target/child")
fi
mount -t tmpfs -o size=4m,nosuid,nodev tmpfs "$PWD/target"
mounts+=("$PWD/target")
mkdir -- target/child
stat -f -c '%n: %T' target target/child
dotnet "$PWD/bin/Release/net11.0/StackedMountRepro.dll" "$PWD/target" "$PWD/target/child"
MOUNTS
```

Run the entire script for each setup:

```bash
bash ./repro.sh
HIDDEN_CHILD=1 bash ./repro.sh
```

On the tested ext4 host, the first run printed `ext4/Fixed` for the
target and `tmpfs/Ram` for the child. The second printed `ext4/Fixed`
for both. In both runs, `stat -f` reported tmpfs for both paths.

The correct public API result is **`tmpfs/Ram` for both paths in both
setups**. The incorrectly selected lower type depends on the backing
filesystem. A zero script exit code means the setup and cleanup
succeeded; compare the printed API results with `stat -f` to detect the
bug.

</details>

### Validate the patch

From the repository root on Linux, build the normal component baseline
and run the regression suites:

```bash
./build.sh clr+libs -rc Release
./dotnet.sh build src/libraries/Common/tests/Common.Tests.csproj /t:Test /p:RuntimeConfiguration=Release
./dotnet.sh build src/libraries/System.IO.FileSystem.DriveInfo/tests/System.IO.FileSystem.DriveInfo.Tests.csproj /t:Test /p:RuntimeConfiguration=Release
./dotnet.sh build src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj /t:Test /p:RuntimeConfiguration=Release
```

For the remaining end-to-end check, run the same probe inside the same
private mount setup using the patched repository testhost instead of the
installed runtime. Confirm that it loads the rebuilt DriveInfo assembly
and returns `tmpfs/Ram` for both paths in both setups.

## Tradeoff

Exact-path lookups now scan the whole mount table to account for other
mounts at the same directory or above it, rather than stopping at the
first match. The selector retains only matching path prefixes and adds
no native calls. This is a correctness change, not a performance
optimization.

Fixes #137745

> [!NOTE]
> This pull request was opened with GitHub Copilot.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.IO.DriveInfo returns invalid data for mounted optical drive volume in Linux if the volume label contains space

4 participants