Package: fakeroot
Version: 2.1.4-1
Severity: normal

faked caches ownership and mode data keyed by (st_dev, st_ino), and entries
are only invalidated by the wrapped operations.  A process that LD_PRELOAD
cannot affect (a statically linked binary, a set-id binary, or one that
confers file capabilities) can therefore unlink a file and create a new one
that lands on the same inode without faked noticing.  If the new file has
the same file type, process_stat() finds the cached entry, the type check
added in fda94bb passes, and the caller is served the previous file's fake
uid/gid and mode -- with no diagnostic, and no way to tell from the stat
data that anything is wrong.

Reproduction below was verified with 2.1.4.  ext4 reuses the inode when a
file is unlinked and a new one is created in the same directory, which is
also what makes t.no_ld_preload_typeswitch exercise the fda94bb path.

    $ mkdir /tmp/repro && cd /tmp/repro
    $ fakeroot sh -c 'umask 022
        : > x && chown 0:0 x
        stat -c "before: inode %i mode %a" x
        ls -ln x
        /bin/busybox rm x
        /bin/busybox touch x
        stat -c "after:  inode %i mode %a" x
        ls -ln x'
    before: inode 48643224 mode 644
    -rw-r--r-- 1 0 0 0 Jan 1 00:00 x
    after:  inode 48643224 mode 644
    -rw-r--r-- 1 0 0 0 Jan 1 00:00 x

The second ls reports root:root for a file that busybox created a moment
earlier and that is owned by the invoking user on disk; nothing warns, and
nothing distinguishes it from a file that was legitimately fake-chowned.
Using LD_PRELOAD= instead of /bin/busybox gives the same result -- that is
the variant a test suite which deliberately drops the preload hits.

Before fda94bb, inode reuse often showed its face in the other direction as
well: the cached type contradicted the disk, the wrong type was served, and
tools failed with ENOTDIR or EISDIR.  fda94bb repairs that half silently,
which is the right thing to do with wrong data, but it also removes the
canary: a session that hits the silent half now has no visible symptom
anywhere.  (We first hit the loud half in CI in October: deterministic
ENOTDIR/EISDIR on paths that are provably regular files, only on GitHub's
ubuntu-26.04 runners and not on an identical local install, i.e. dependent
on inode allocation.  The silent half was never noticed at all.)

Impact: an artifact can be built with ownership or mode taken from a file
that no longer exists -- an image or a package shipping files owned by the
wrong uid, or a build reading a file with a mode other than the one on
disk, with the build log showing nothing.

This is not a request to revert fda94bb.  I am reporting it because 2.1.x
closes the case that produced visible failures and thereby leaves the
remaining case as the only one with no symptom.  What, if anything, should
be done is your call.  Two things we have working downstream, in case a
reduced version is interesting:

 - The exec side is detectable before handoff: a PT_INTERP program header
   means the loader will honour LD_PRELOAD (set-id and file-capability
   binaries being the exceptions, cf. #544471), so libfakeroot can name the
   binary and optionally refuse the exec, letting CI fail at the boundary
   instead of three build steps later.  We keep that opt-in
   (FAKEROOT_EXEC_POLICY=fail) and it is what would have made our original
   failure say what actually happened.

 - The serve side can compare faked's cached permission bits with the fresh
   real stat and warn when they disagree (a static chmod, for example).
   Warn-only, because a legitimate in-place modifier can change the bits;
   it cannot catch the same-mode reuse above, for the reason in the first
   paragraph.

Happy to send either as a patch, or as a description only -- we are not
assuming you want the extra wrapped functions upstream.

Reply via email to