Skip to content

df: statfs fallback swallows over-mounted device error, prints wrong row #15799

Closed

Description

@sylvestre
============================================================================
ANT-2026-QQAJBFZG  [NOT SECURITY: ordinary bug]
df: statfs fallback swallows over-mounted device error, prints wrong row
Location: src/uu/df/src/platform/unix.rs:79  in filesystem_for_path()
Commit:   7bc1eb6d1d6fa2e1dc2c9d2277cf576c05f61e47
============================================================================

Not a security issue. This is a real, reproducible bug that is NOT a security issue: by your project's own policy nobody gains anything from it that they did not already have. It is not part of the vulnerability report, is in none of its counts, needs no embargo and no advisory, and can be filed and fixed in the open like any bug.

df DEVICE prints the wrong row and exits 0 when the device's mount point has another file system mounted on top of it. Instead of GNU's df: cannot access '/dev/loop0': over-mounted by another device (exit 1), uutils prints the row of the file system that holds the device node, typically tmpfs 0% /dev. A script reading Use% for a nearly full volume can therefore get a plausible 0% instead of an error. This is a regression first released in 0.11.0; 0.10.0 reports the over-mount as GNU df does.

The cause is the or_else(|_| from_path_direct_with_mounts(mounts, path)) in filesystem_for_path() (src/uu/df/src/platform/unix.rs:79), added by a75f32a ("df: add a fallback path for statfs with a mount table"). That fallback was meant for a mount table with no entry covering the path, but it runs on every error from Filesystem::from_path(), including FsError::OverMounted. The fallback has no notion of a device operand. It calls statfs() on the device node itself and returns the mount with the same fsid, which is /dev.

The same line also hides a second error. If the device's mount point cannot be statfs'd (for example, root cannot traverse a FUSE mount above it), GNU prints Permission denied and exits 1, while uutils again prints the /dev row and exits 0. Only device operands are affected; df MOUNTPOINT and plain df are not. Since GNU df already prints this same /dev row for a device that is not mounted at all, the practical effect is that an over-mounted or inaccessible device looks unmounted instead of being reported.

The attached reproducer shows this on a loop-mounted FAT volume, with GNU df as the reference. The attached patch restricts the fallback to the "no mount found" case.

Details

This is an ordinary bug, not a security issue: whoever over-mounts the volume gains no file access
and no privilege, and only turns a df error into a wrong /dev row, which is the row GNU df already
prints for any device that is not mounted. They can also already decide what df shows for the mount
point itself.

df DEVICE finds the mount of DEVICE, notices that another file system is mounted on top of it,
returns FsError::OverMounted, and the caller discards that error and retries with a statfs fallback
that answers a different question. The result is the row of the file system that holds the device
node (/dev) and exit status 0. The root cause is that filesystem_for_path() retries every
error of the mount table lookup, not only "no entry covers the operand"; the over-mounted device is
the clearest way to reach it, and a mount point that cannot be statfs'd (described further down)
is a second one.

With /dev/loop0 (a 4 MiB FAT volume, 76% used) mounted on a directory and any other file system
mounted on the same directory afterwards:

$ df --output=source,pcent,target /dev/loop0                # GNU coreutils 9.7, exit 1
df: cannot access '/dev/loop0': over-mounted by another device

$ coreutils df --output=source,pcent,target /dev/loop0      # exit 0
Filesystem     Use% Mounted on
tmpfs            0% /dev

The defect is the |_| at src/uu/df/src/platform/unix.rs:79, which treats every error of the mount
table lookup as "nothing found":

    if use_fallback {
        from_path_direct(path)
    } else {
        Filesystem::from_path(mounts, path).or_else(|_| from_path_direct_with_mounts(mounts, path))
    }

The example follows this path:

  1. get_named_filesystems() calls platform::filesystem_for_path() for the operand
    (src/uu/df/src/df.rs:401), which calls Filesystem::from_path(). mount_info_from_path()
    (src/uu/df/src/filesystem.rs:88-98) returns the first mount whose canonicalized source equals
    the operand: the FAT mount.

  2. filesystem_from_mount() asks is_over_mounted(); the last entry of the mount table for that
    directory has another source, so:

    // src/uu/df/src/platform/unix.rs:58
        if is_over_mounted(mounts, mount) {
            Err(FsError::OverMounted)
        } else {
            Filesystem::new(mount.clone(), file).ok_or(FsError::MountMissing)
        }
  3. Back at line 79, or_else(|_| …) drops OverMounted and calls from_path_direct_with_mounts()
    (platform/unix.rs:100-126). That function has no notion of a device operand. It runs statfs()
    on the operand itself (line 111), i.e. on the device node, which lives on the tmpfs mounted on
    /dev, and returns the last mount with the same f_fsid (lines 115-121): /dev.

  4. get_named_filesystems() receives Ok, so the arm that prints the diagnostic and sets exit
    status 1 (df.rs:422-427, df-error-cannot-access-over-mounted) does not run.

The check comes from 02e49a4 ("df: error on over-mounted device"). The or_else was added by
a75f32a ("df: add a fallback path for statfs with a mount table", 2026-04-29), whose message
describes one case: a mount table with no entry for the path. Since then the OverMounted result of
from_path() no longer reaches the user. The regression is first in release 0.11.0; 0.10.0 reports
the over-mount and exits 1, as GNU df does.

The same line hides a second error. When the mount is found and not over-mounted but statfs() on
its mount point fails, Filesystem::new() returns None and line 61 turns it into
FsError::MountMissing, the value that also stands for "no entry covers the path"; the fallback runs
again. Observed with /dev/loop0 mounted on …/home/nobody/data and a FUSE mount owned by nobody
on …/home/nobody, which root cannot traverse: GNU df prints df: …/home/nobody/data: Permission denied and exits 1, uutils prints tmpfs 0% /dev and exits 0.

Only operands matched through the mount source are affected. For a path operand the prefix lookup
(filesystem.rs:102-105) already picks the last mount of a directory, so OverMounted never arises.

Impact

df DEVICE succeeds with the row of the file system that holds the device node, where GNU df and
uutils 0.10.0 print a diagnostic and exit 1. On a typical system that row is /dev, an almost empty
tmpfs or devtmpfs showing 0%. Anyone who runs df with a device operand hits this when something
else is mounted on the device's mount point, or when that mount point cannot be statfs'd (the
Permission denied case above). The over-mount can be an administrator's own or a FUSE mount that a
user made on a directory they can write to. A script that reads Use% from df DEVICE then gets a
plausible 0% instead of an error, even for a volume that is nearly full, unless it also checks the
Filesystem column.

Both situations are uncommon, and path operands (df MOUNTPOINT, plain df) are not affected. GNU
df 9.7 itself prints the same tmpfs 0% /dev row, exit 0, for any device that is not mounted (e.g.
/dev/null, an unused /dev/loop7). The practical effect is therefore that an over-mounted or
inaccessible mount looks like an unmounted device instead of being reported as an error: the
GNU-compatible "over-mounted by another device" diagnostic is lost.

Reproducing

repro must run as root in a privileged container, because it needs a loop device, vfat and /dev/fuse. It uses the prebuilt /src/target/debug/coreutils and GNU /usr/bin/df as the reference. All of its mounts are made in a private mount namespace, so they disappear when the script exits.

Files:

  • repro (setup, root's df runs and the verdict):
    • It creates an empty 4 MiB FAT volume and loop-mounts it on …/media/nobody/STICK with uid=65534,gid=65534, the way udisks mounts a user's stick. The volume's root directory therefore belongs to nobody.
    • It writes 3 MiB into the volume.
    • It runs df --output=source,pcent,target DEVICE as the control. If that row is not the device at its mount point, the script aborts as a setup failure.
    • It then has nobody over-mount the volume and runs the same df command twice: first GNU df for reference, then uutils df.
  • repro.d/make_fat_image.py (setup) writes the empty FAT12 image. The image has no mkfs, so the boot sector and FATs are built field by field.
  • repro.d/fusermount3_standin.py (the over-mounting user, nobody) stands in for nobody running fusermount3 DIR. The image doesn't ship libfuse's setuid helper, so this file does what the helper does:
    • It checks write access to the directory with nobody's ids (effective uid/gid 65534, no supplementary groups). If nobody cannot write there, it refuses.
    • As root, it calls mount(2) with type fuse, nosuid,nodev and user_id=65534,group_id=65534, without allow_other.
    • It starts no FUSE server. The defect only needs the mount table entry. Any second mount on the directory gives the same df output; mount -t tmpfs none DIR does too.

Expected output (the loop device number and temporary path vary):

CONTROL  uutils df /dev/loop0, volume visible:      exit 0: /dev/loop0 76% /tmp/tmpXXXXXXXX/media/nobody/STICK
EXPECTED GNU df /dev/loop0, volume over-mounted:    exit 1: df: cannot access '/dev/loop0': over-mounted by another device
OBSERVED uutils df /dev/loop0, volume over-mounted: exit 0: tmpfs 0% /dev
BUG

The last line is BUG when uutils df exits 0 after the over-mount and its row names a source other than the device. In this run that row is the file system holding the device node, /dev. A df that reports the over-mount, or reports the device itself, makes the script print OK.

Suggested fix

The attached patch uses the fallback only when the lookup finds no mount, and lets an error about the
mount that was found stand. It moves the decision out of filesystem_for_path()
(platform/unix.rs:79), which now returns the result of Filesystem::from_path() as is, into
Filesystem::from_path() (filesystem.rs:142-146). That is the one place that can tell
mount_info_from_path()'s MountMissing ("no element of mounts covers path", the case
a75f32a added the fallback for) from an error about the mount it found:

--- a/src/uu/df/src/platform/unix.rs
+++ b/src/uu/df/src/platform/unix.rs
@@ -76,7 +76,7 @@
     if use_fallback {
         from_path_direct(path)
     } else {
-        Filesystem::from_path(mounts, path).or_else(|_| from_path_direct_with_mounts(mounts, path))
+        Filesystem::from_path(mounts, path)
     }
 }
 
--- a/src/uu/df/src/filesystem.rs
+++ b/src/uu/df/src/filesystem.rs
@@ -142,9 +142,13 @@
         let file = path.as_ref().as_os_str().to_owned();
         let canonicalize = true;
 
-        let result = mount_info_from_path(mounts, path, canonicalize);
-        result
-            .and_then(|mount_info| platform::filesystem_from_mount(mounts, mount_info, Some(file)))
+        match mount_info_from_path(mounts, &path, canonicalize) {
+            // An error about the mount that was found is the answer for `path`.
+            Ok(mount_info) => platform::filesystem_from_mount(mounts, mount_info, Some(file)),
+            // No element of `mounts` covers `path`.
+            Err(FsError::MountMissing) => platform::from_path_direct_with_mounts(mounts, path),
+            Err(e) => Err(e),
+        }
     }
 }
 

The patch also makes from_path_direct_with_mounts() pub(crate) so filesystem.rs can call it,
and updates the doc comments of both functions. Matching on FsError::MountMissing at line 79
instead would not be enough, because of the second case above. Two new unit tests in
platform/unix.rs call filesystem_for_path() with a mount table in which /dev/null is the source
of an over-mounted entry, and one in which its mount point does not exist; both fail on the
unpatched code.

With the patch applied to a clean checkout, the reproducer prints OK: df DEVICE on the
over-mounted volume prints df: cannot access '/dev/loop0': over-mounted by another device and exits

  1. df /dev/null still reports /dev, df / in a chroot whose root has no mount table entry (the
    case a75f32a was written for) still prints the same row as GNU df, and the uu_df unit tests and
    test_df:: pass. The behaviour change is that df DEVICE now fails with a diagnostic for an
    over-mounted device or an inaccessible mount point instead of succeeding with another file system's
    row. Two differences from GNU remain outside the patch:
  • the second case prints df: no file systems processed (exit 1) where GNU prints
    MOUNT_POINT: Permission denied; that would additionally need fs_usage()
    (platform/unix.rs:27) to keep the statfs error instead of turning it into None;
  • for a device mounted twice whose first mount is over-mounted and second is not, GNU reports the
    second mount, while the patched lookup, which only considers the first match, reports
    "over-mounted".

Running the reproducer

bugs-not-security/ANT-2026-QQAJBFZG/repro, next to this file, with its companion files in bugs-not-security/ANT-2026-QQAJBFZG/repro.d/ (fusermount3_standin.py, make_fat_image.py) — the script reads them from /tmp/repro.d/. It was written by an automated agent and our check ran it as root in a privileged container: run it INSIDE A THROWAWAY VM, with the image oss-scan-7bc1eb6d1d6f built by bash build/build-image.sh, from the archive's top directory:

docker run --rm --network=none --privileged -u 0 -w /src -v "$PWD/bugs-not-security/ANT-2026-QQAJBFZG/repro:/tmp/repro:ro" -v "$PWD/bugs-not-security/ANT-2026-QQAJBFZG/repro.d:/tmp/repro.d:ro" oss-scan-7bc1eb6d1d6f /tmp/repro

It prints its evidence; the last line is BUG if the issue triggered, OK otherwise.

Related: #3970

Activity

  1. added a commit that references this issue on Nov 3, 2026
    abf33a9
  2. added a commit that references this issue on Nov 4, 2026
    f9e62d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions