Skip to content

DriveInfo reports ext4/Fixed instead of tmpfs/Ram for stacked Linux mounts #137745

Closed

Description

@krwq

Description

On .NET 11.0.0, after mounting tmpfs on top of an ext4 bind mount, DriveInfo reports DriveFormat = "ext4" and DriveType = Fixed for the mount directory. Native statfs reports tmpfs at that same path. The expected .NET results are DriveFormat = "tmpfs" and DriveType = Ram.

The following results were observed with real mounts, not synthetic mountinfo records:

Setup Path passed to new DriveInfo(...) Actual format / type Expected format / type
A: tmpfs mounted over an ext4 bind mount target ext4 / Fixed tmpfs / Ram
A: same setup target/child tmpfs / Ram tmpfs / Ram
B: an ext4 child mount was also created before mounting tmpfs at its parent target ext4 / Fixed tmpfs / Ram
B: a new child directory created inside the upper tmpfs target/child ext4 / Fixed tmpfs / Ram

This follows up on offline feedback related to #137195, which fixed escaped mount paths reported in #123347. This report concerns a separate filesystem-selection problem; no spaces or escaped paths are needed to reproduce it.

Reproduction Steps

Prerequisites:

  • Linux with Bash, GNU coreutils, and util-linux (unshare, mount, and umount).
  • The .NET 11 SDK and targeting pack.
  • Permission to create a private mount namespace and mounts (CAP_SYS_ADMIN). Root in a restricted container may still lack this permission.
  • A new empty scratch directory on an ext4 filesystem to reproduce the exact output below. Other non-tmpfs/non-ramfs backing filesystems can expose the same selection problem, but the incorrectly reported lower type will differ.

No runtime source build or PR is required. The commands below use the installed .NET runtime.

Save these two files in the scratch directory. The script creates its own project and local build settings, so it can also run below a runtime checkout whose SDK requirements differ.

Program.cs
// 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}");
}
repro.sh

Run the complete script, not the mount commands separately. It creates a private mount namespace, checks that the namespace changed before mounting anything, makes mount propagation private, and unmounts the test mounts before exiting.

#!/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 setup A:

bash ./repro.sh

This bind-mounts ext4 at target, mounts tmpfs at the same path, and creates target/child inside tmpfs.

Run setup B:

HIDDEN_CHILD=1 bash ./repro.sh

This additionally bind-mounts ext4 at the old target/child before mounting tmpfs at target. The parent tmpfs mount hides that old child mount. The script then creates a different target/child directory inside the visible tmpfs.

Both invocations were executed successfully. Builds completed with zero warnings and errors. The test mounts and mount directories were removed after each invocation, and the original namespace's mountinfo was unchanged.

A zero exit code only means the probe ran and cleanup succeeded. The incorrect API values are visible in its output.

Expected behavior

For both setups, stat -f and DriveInfo should agree that both paths reach tmpfs. The relevant output should be:

target: tmpfs
target/child: tmpfs
<repro>/target: tmpfs/Ram
<repro>/target/child: tmpfs/Ram

The first two lines are from native stat -f; the last two are from DriveInfo. <repro> denotes the absolute scratch-directory path. Runtime and namespace diagnostic lines are omitted here and below.

In particular, new DriveInfo(target).DriveType == DriveType.Fixed should be false, not true.

Actual behavior

Setup A:

target: tmpfs
target/child: tmpfs
<repro>/target: ext4/Fixed
<repro>/target/child: tmpfs/Ram

The mount directory is reported as ext4/Fixed, but its child is correctly reported as tmpfs/Ram, even though both paths reach the same tmpfs filesystem.

Setup B:

target: tmpfs
target/child: tmpfs
<repro>/target: ext4/Fixed
<repro>/target/child: ext4/Fixed

Both API results are wrong. The ext4 child mount still appears in mountinfo, but it is hidden by the parent tmpfs mount and is not the filesystem reached through target/child.

Regression?

Unknown. Reproduced on .NET 11.0.0; earlier releases were not run through this reproduction.

Known Workarounds

No workaround using the existing DriveInfo API was verified for both setups. Native statfs returned the correct visible filesystem type in these runs.

Configuration

  • Runtime: .NET 11.0.0, commit 297acf930f.
  • SDK: 11.0.100.
  • OS: Ubuntu 24.04.5 LTS.
  • Kernel: Linux 6.12.115-adc.2.
  • Architecture: x64.
  • Backing filesystem: ext4; upper filesystem: tmpfs.
  • Public API assembly: /usr/share/dotnet/shared/Microsoft.NETCore.App/11.0.0/System.IO.FileSystem.DriveInfo.dll.
  • Reproduced in a separate private mount namespace. No runtime patch was applied for these public API results.

Other information

The Linux lookup currently stops at the first exact-path mountinfo match. This can select the old ext4 mount even though another filesystem is mounted on top of it. For child paths, choosing the longest matching mount path can select a child of a now-hidden mount.

The parent-ID rules in proc_pid_mountinfo(5) describe these relationships. Record order and the largest numeric mount ID are not reliable substitutes for determining which mount is visible.

This affects application decisions as well as display text: code filtering for DriveType.Fixed takes the wrong branch for a tmpfs mount. The observed failure is incorrect metadata; file access still reaches the correct kernel-selected filesystem. No data loss or security exploit was established.

Note

This issue draft was prepared with GitHub Copilot.

Activity

  1. added
    untriaged
    on Nov 17, 2026
  2. self-assigned this
    on Nov 17, 2026
  3. dotnet-policy-service commented on Nov 17, 2026

    @dotnet-policy-service
    Contributor

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

  4. removed
    untriaged
    on Nov 20, 2026
  5. added a commit that references this issue on Nov 20, 2026
    cfe5c10
  6. added this to the 12.0.0 milestone on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions