Skip to content

fix(mountinfo): read the mount table byte for byte and fail closed where it cannot be read - #252

Merged
WitteShadovv merged 19 commits into
nextfrom
fix/mount-table-bytes
Nov 26, 2026
Merged

WitteShadovv merged 19 commits into
nextfrom
fix/mount-table-bytes

Conversation

@WitteShadovv

@WitteShadovv WitteShadovv commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

The bug is older than the cursor work. One byte that is not valid UTF-8 anywhere in /proc/self/mountinfo failed read_to_string, and most callers then used an empty table. The last step before a switch saw no /run/nextroot and did nothing on both directions.

My choices. Every path from the mount table keeps its bytes once the kernel's octal escapes are undone. Option text and the filesystem type stay text, and a byte there that is not valid UTF-8 becomes an escape such as \377. A device path that is not valid UTF-8 (a source, an XFS logdev= or rtdev=, a bcachefs member) is never looked up with a replaced byte. It counts as a place NAILS could not read, so the decoy storage checks refuse that root and a decoy unit mounted from it is masked. For the way back's wait I name each unit as systemd's unit_name_from_path does and ask PID 1 with systemctl is-active, which still answers where list-units fails on systemd 255. The session policy uses the same namer for the decoy's fstab.

Where the table cannot be read at all:
The transition step refuses the switch, and on the way back it powers off first.
The emergency forces a power off past PID 1's queue, or the reboot asked for, and its JSON side is unknown.
activate, deactivate, discard, recover and the rehearse steps refuse. An offline rehearse scan still runs, as it scans only the images it is given.
The way back's preparation stops before it unmounts or mounts anything, and the detach of /run/nextroot and the runtime directory never takes an unread tree for gone.
The read only guard and the watcher's sweep keep writable only what the plan records, the hidden volume's own device included.
status, the watcher, verify and check say the table could not be read. Offline verify says so where it tells how to mount a decoy device, and gives no mount there. A file of the image or a mapping not open here still gets its read-only losetup or cryptsetup line and a mount. The table plays no part there.
The window refuses a menu entry's start. Opened from a terminal it acts as in a hidden session: Emergency control from the start, at most Verify, Rehearsal and Settings, no Discard, Set Up or Activation Options.
A table that is not there, with no /proc, now counts as unread in verify, which took it for empty. suspicious-nails-reference and the backend record do the same, but in a real run the automount guard and activation read the table first.

Also: /proc/swaps is read as bytes. A btrfs decoy root whose subvolume name is not valid UTF-8 is refused, and so is an overlay layer at such a path. The window now reads a hidden root path with a comma, colon or backslash as the engine does.

Left as it was, and older than the branch: for a decoy fstab mount point or swap device with an escape glibc does not undo, such as \377, systemd up to 258 reads four characters and from 259 on the byte. NAILS names the unit the second way, so on an older decoy a mask can miss. Such escapes are rare, not absent. A later branch masks both names.

Proof. The tmpfs at a /run folder ending in byte 0xff that showed the bug is now a kernel test, passing on both directions. Every place that fails closed on an unread table has a test through a seam for the table, but the early guard's read, whose empty table the guard's own test covers. With each fix undone on the head its test failed. The unit names match PID 1's own on systemd 255 and, in decoy-journal-leak, on the NixOS VM's 261. The fuzz targets read raw bytes, and utab checks every line against the libmount model.

Checks: every commit passed fmt, clippy, the tests and one rotating shuffle seed on the build server, and the tip passed the full just check. The tip also ran the kernel tests with NAILS_REQUIRE_USERNS=1 and the fuzz targets for the mount table, utab, the fstab and the unit names for a minute each. CI on the head, all green: https://github.com/WitteShadovv/nails/actions/runs/45643228786 https://github.com/WitteShadovv/nails/actions/runs/45643234756 https://github.com/WitteShadovv/nails/actions/runs/45643240683 https://github.com/WitteShadovv/nails/actions/runs/45643295122

…thout it

One byte that is not valid UTF-8 anywhere in /proc/self/mountinfo (a mount
point, a root, a source or an option) failed read_to_string, and most
readers then took the table for empty. The last step before a switch saw
no /run/nextroot and returned NothingToDo on both directions: no leftover
guard on the way in, and no scrub, no records put back and no kmsg cursor
on the way back.

The parser now reads bytes. A path keeps every byte the kernel gives once
its octal escapes are undone, and the text fields keep a byte that is not
valid UTF-8 as an octal escape, in the form the kernel uses for a space
there, so the overlay layers, subvol= and every other value decode to the
kernel's bytes and no comparison meets a replaced byte. utab lines, the
mount table copy the entry keeps for the way back, the mount namespace
check's own scan, the NixOS reference check, the selinuxfs fact, verify
and the window read the same way.

Where the table cannot be read at all, each safety path takes its fail
closed end: the transition step refuses the switch and on the way back
powers off first, the emergency forces a power-off (or the reboot asked
for) since it cannot tell its side, activate, deactivate, discard and
recover refuse, the way back's preparation stops before it unmounts or
mounts anything, the next root's detach never takes an unread tree for
gone, and the read-only guard keeps writable only what the plan names.
status, the watcher, verify, check's filesystem list and the window say
that the table could not be read.
The way back's wait named a mount unit from the path read as UTF-8 and
did not shorten a long name, so the unit of a mount point that is not
valid UTF-8, and of one whose name PID 1 cuts with a hash, never showed in
the listing and counted as down at once.

The name is now made as systemd's unit_name_from_path makes it: every byte
of the path escaped, whatever it is, and a name of 256 characters or more
cut and given the SipHash-2-4 of the whole name under systemd's key, as
unit_name_hash_long does. The tests hold the names PID 1 gave on systemd
255 for such mount points.

The wait asks systemctl is-active for those units instead of listing
every mount unit: while any mount point is not valid UTF-8, PID 1 refuses
list-units as a whole (its description cannot go over D-Bus), but answers
the state of each unit by name.
decoy-journal-leak now mounts a tmpfs at folders whose names are not
valid UTF-8 or whose unit names PID 1 shortens with a hash, and requires
systemctl is-active to hold each unit active under the name the way
back's wait asks for, and inactive once it is unmounted. The names are the
ones PID 1 gave on systemd 255, which the nails-teardown tests hold too.
In the hidden session it leaves two such mounts in /run while deactivate
reads the mount table, and requires that the way back leaves nothing of
them.
The CHANGELOG, the operator guide and the kmsg-import row with its
generated rows say that the mount table is read byte for byte, what each
path does where it cannot be read, and that the way back's wait now names
the units of mount points that are not valid UTF-8 or whose unit names
PID 1 shortens with a hash: what still lets such a unit's end follow the
cursor is the wait's bound, no answer from systemctl, and no systemctl.
status reports the place as unknown where the mount table cannot be
read, and its message names the table, not the state file.
The NixOS test driver type-checks the test script, and its machine's
succeed takes several commands and a timeout, so the helper's protocol
of one command did not match and decoy-journal-leak did not build.
A device path in the mount table that is not valid UTF-8 (a source, an
XFS logdev= or rtdev=, a bcachefs member) was looked up with that byte
replaced or kept as its escape's text. It is now a place that could not
be read: the decoy-storage checks refuse the root as one they cannot
judge, and a decoy unit mounted from such a source is masked.

/proc/swaps is read as bytes, so one swap file whose name is not valid
UTF-8 no longer hides every swap partition from rehearse scan. A list
that cannot be read fails the scan, and the way back resets no zram.

The decoy's fstab keeps such a byte as its escape and a mount point
holds the bytes its escapes stand for, and the session policy names its
units as PID 1 names them, a name of 256 characters or more shortened
with the hash. A decoy unit whose name may be such a hash is masked.

The read-only guard and the watcher's sweep keep the hidden volume's
own device writable from the plan, also with an empty table. The
session probe returns an error without the table, and the rehearse
steps refuse on it. The window undoes the overlay's own escapes in the
hidden root's upperdir and shows its Emergency control where the table
cannot be read.

Each site that fails closed on an unread table gets a test through a
seam for the table: leave, the decoy root's mount, the next root's
detach and make private, activate, deactivate, status, check, the
watcher and the mount namespace check. The utab fuzz target checks
every line against the libmount model as bytes.
The fstab_crypttab target read the decoy's fstab with each byte that is
not valid UTF-8 replaced, and named the expected units from the mount
point with such bytes replaced too. The session now reads the decoy's
fstab with such a byte kept as its escape, so a mount point holds the
byte and its unit is named from it: a minute of fuzzing found an fstab
whose expected unit name then differed from the one NAILS masks.

The target reads the fstab as the session does, and the model of
systemd's unit names reads the path as bytes. The input is a new seed.
rehearse scan read the live session for every scan, and refused when
the mount table could not be read. An offline scan reads only the
images it is given, and nothing it decides rests on the session: the
same-session refusal never refuses it, the covered-root check returns
early for it, and its targets are the images. It now runs as outside a
session there. A live scan still refuses.

The service reads the session through a probe a test can replace, and
the new test runs an offline and a live scan with an unread table.
…able

Two sites that fail closed on a mount table they cannot read had no
test that fails without them: the session probe, which every step that
must tell the hidden session from the decoy asks, and the entry's
second read after the /run copy, for the utab lines the way back gives
back. Each now reads the table through a path a test can name, and a
test names one that is not there or cannot be read.
The utab target modelled only the first 64 lines of an input, while its
own doc says every line. The model is linear in the line, so the cap
bought little: every line now goes through it.
An offline verify says how to mount each place of the decoy that holds
nothing under the root, by how its device is mounted here. Where the
mount table here could not be read, it took the device for one not
mounted, and said so. It now says the table could not be read and gives
the mount for a device mounted here and the one for a device that is
not.
Live verify, the NixOS check suspicious-nails-reference and the record
of the hidden volume's device-mapper stack took a /proc/self/mountinfo
that is not there (no /proc) for an empty table, as on a test's tree,
with no message. The kernel always gives a process its table, so each
now takes it for one that cannot be read and takes its fail-closed end:
verify warns that it cannot tell whether /run/nextroot is populated,
the check refuses with the advice for an unread table, and activation
stops before it records no mapping. The tests that ran these readers
on a tree without the file now give it one.
Where the window cannot read the mount table it takes itself for a
hidden session in all: besides its Emergency control it offers at most
a hidden session's tools, never Discard Hidden Changes, Set Up Hidden
Volume or Activation Options. The changelog, the operator guide and the
code docs named only the Emergency control.

The changelog said the policy masks or skips the unit PID 1 has for
every decoy fstab line. A mount point or swap device written with an
escape glibc does not undo is read as four characters by systemd 258
and older, so there the hidden systemd looks for another unit. That
case is older than this release and not covered yet, and the changelog
now says so.
…nread

Where the mount table here cannot be read, the advice gave the second
mount for a device mounted read-write here, made read-only once
mounted. On a btrfs that is mounted read-only, that mount makes the
filesystem read-write and it commits. No one command writes nothing in
every case without knowing how the device is mounted, so the line now
names the unread table and asks for a run where /proc is mounted, and
gives no command.
Two more sites that fail closed on a mount table they cannot read had
no test that fails without them: the discard plan, which refuses, and
the window gate, which takes the decoy's gate. Each now decides on a
view a test can give, and a test gives it an unread table.
An offline rehearse scan scans only the images it is given, and its
targets never use the mount table; it still reads the session for its
next step, so "reads no mount table" said more than it does. A mount
table that is not there changes verify in a run; the NixOS reference
check and the device-mapper record take it as unread too, but their
automount guard and activation read the table first. The offline
verify advice for an unread table gives no mount now. The doc of the
recorded backend names a missing table too.
An offline scan still reads the rehearsal state, and the next step it
names rests on the session. Offline verify gives no mount only for a
device: a file of the image or a closed mapping still gets its losetup
or cryptsetup line. The limit on a subvolume name that is not valid
UTF-8 is the option text NAILS builds and the session plan's JSON, not
mount(2) itself.
The in-diff mutants lane found that no test told the line for a mount
table that could not be read from the one for a state file: the guard
could be always true or always false. The line is now built by a small
function, and a test pins all three lines.

The lane also left two mutants of the locked deactivation handle alive,
may_leave as Ok(()) and leave as an empty report. Its tests run in a
user, PID and mount namespace of their own, so that no leave reaches the
host's PID 1, and the lane's runner does not allow unprivileged user
namespaces, so they skip there. Where namespaces work (the coverage job
with NAILS_REQUIRE_USERNS=1, the build server) they kill both, and the
VM test session-switch-timeout covers the refusal and the way back.
@WitteShadovv
WitteShadovv merged commit 22ce3b6 into next Nov 26, 2026
126 of 127 checks passed
@WitteShadovv
WitteShadovv deleted the fix/mount-table-bytes branch November 26, 2026 02:02
WitteShadovv added a commit that referenced this pull request Nov 26, 2026
…mits

The rebase of this branch onto next after #252 kept only its first seven
commits. Without the later ones the decision for a needed noauto line
again dropped the line's automount, and the fstab_crypttab fuzz job found
srv-crlf.automount neither masked nor skipped (run 45739865655). The
later commits are back on top, unchanged. The crash input is a seed, so
the target checks that shape from its first run.
WitteShadovv added a commit that referenced this pull request Nov 26, 2026
…mits

The rebase of this branch onto next after #252 kept only its first seven
commits. Without the later ones the decision for a needed noauto line
again dropped the line's automount, and the fstab_crypttab fuzz job found
srv-crlf.automount neither masked nor skipped (run 45739865655). The
later commits are back on top, unchanged. The crash input is a seed, so
the target checks that shape from its first run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant