Skip to content

fix(platform): close the NixOS reference check's gaps for dot parts, fstab escapes and comment ends - #250

Open
WitteShadovv wants to merge 16 commits into
nextfrom
fix/nixos-reference-gaps
Open

WitteShadovv wants to merge 16 commits into
nextfrom
fix/nixos-reference-gaps

Conversation

@WitteShadovv

Copy link
Copy Markdown
Owner

This closes the three gaps the reviews of #246 found in suspicious-nails-reference, where a config naming the hidden volume or root passed. Each one now refuses like the plain spelling.

  • A . part right after the leading slash. "/./mnt/data" and the literal /./mnt/data passed while /mnt/data refused. The kernel and Nix read them as /mnt/data. At the root .. is the root too, so /../mnt/data counts as well.
  • fstab octal escapes. NixOS writes fileSystems values into /etc/fstab as Nix reads them and libmount decodes \ooo there, so "/dev/mapper/d\141ta" put the hidden device into the decoy fstab. A line that matches nothing is now matched again with these decoded, also for the root's own name in subvol=, X-mount.subdir= or a bind device. I decode the line as written too, so "d\141ta", which Nix reads as d141ta, refuses. I took that false alarm over a gap.
  • The scanner read context wrong after an odd quote in a block comment, a block comment right after a word (true/* ... */), '' in an identifier or URI (a'', http://example.org/a'') and a # comment ended by a carriage return. A luks.devices block after such a place named no mapping. Comments and those tokens now end where the Nix lexer ends them.

My first scanner fix refused less than next on a few inputs, where next took a quote in a comment for a string and decoded an escape in it. So every line is now read twice, by quotes and brackets alone as next reads it and then as Nix reads it, and a name either reading finds counts. A line next reports keeps its exact reference.

Each case has a unit test that failed on the code of next. One more test pins the double reading and fails when only the Nix reading is kept.

Nothing refuses less than next. I ran both over about 626,000 inputs in three layouts (mapping, btrfs subvolume root, folder root): the module's test strings, the fuzz seeds, variants of those with the new forms, 300,000 grammar texts and the two corpora from the #246 review. No input next refuses passes and no line next reports is dropped, while 27,961 rows refuse only here. A line with another kind always holds a /./ or /../ path.

The fuzz target keeps its properties and gets three seeds. The decoy requirements no longer list the leading . part as a limit, the CHANGELOG bullet that said it still passes now says it counts, and a Fixed entry names the other two.

just check passed on every commit on the build server, with the full check and a 15 minute fuzz search on the head. On this head E2E all passed (run 45588499913), Distro E2E all passed (45588505704), the staged Distro E2E passed (45588510969) and the oracle passed with every image and 0 unexplained (45588540718). Nothing needed a retry.

…e kernel does

suspicious-nails-reference read the . parts and doubled slashes between the
parts of a path, but not a . part right after its leading slash, so
"/./mnt/data" and the path literal /./mnt/data passed where /mnt/data is
refused. The kernel reads both as /mnt/data, and Nix reads the literal so.
At the root a .. part names the root as well, so /../mnt/data is the same
path too.

A path marker now also stands where its leading slash is followed by . or
.. parts, and by slashes after one of them. A run of slashes alone in front
of the path is still left to begins_path, so the text reported for
//mnt/data stays /mnt/data. Seed the fuzz target with such paths.
NixOS writes the device, the mount point and the options of a fileSystems
entry into /etc/fstab as Nix reads them, escaping only blanks, and
libmount decodes a backslash and three octal digits there as the byte they
give. So fileSystems."/x".device = "/dev/mapper/d\\141ta" puts the hidden
volume's device into the decoy's fstab, and fileSystems."/mnt/d\\141ta" a
mount at its mount point, while suspicious-nails-reference passed both. The
same held for the root's own name in a subvol= or X-mount.subdir= option
and in a bind's device.

A line that matches no marker as the file spells it and as Nix reads it is
now matched once more with these escapes decoded in each of those views,
as libmount decodes them. A line the check reported before reports the
same reference, and a match maps back to the bytes of the line that stand
for it. Seed the fuzz target with such names.
… the NixOS scan

The scanner that tells suspicious-nails-reference where a mapping name
names an entry read some lines otherwise than Nix, and missed the entry
after them. Inside a block comment it read a quote or '' as the start of a
string, and the string ran past the comment's */ (/* a 5" disk */). It
took a /* right after a word as part of the word (true/* … */), so the
quote inside opened a string in code. It read '' in an identifier or a
URI as the start of an indented string (let a'' = 1; in a'',
http://example.org/a''). And it read a # comment on to the end of the
line, where Nix ends it at a carriage return too. In each case a
luks.devices block after such a place gave no MapperName.

A block comment now ends at its first */ and a # comment at a carriage
return, whatever the copy of the frames it is read on holds, and what
follows is code. A token ends at a /* unless it is a URI, a ' continues an
identifier but not a path, and a URI holds every byte Nix allows in one.
A word right after the . that selects an attribute starts a token too. Seed
the fuzz target with these places.

Where the two readings part, the old one can find a name the new one does
not: an escape in what it took for a string in a comment. So a second
scanner keeps reading by quotes and brackets alone, and each line is
matched with what that one finds first, then with what the Nix reading
finds. A line the check reported before reports the same reference.
The decoy requirements listed a . part right after a path's leading slash
among what the check does not read, and the CHANGELOG said such a path
still passes. Both now say that it counts, with a .. part there too. The
requirements also say that a line counts with fstab's octal escapes
decoded, and that the check ends a comment where Nix's lexer ends it while
what the reading by quotes alone finds still counts. The CHANGELOG names
the fixes under Fixed.
… code as Nix does

The Nix reading of the NixOS reference scan started a token only at a
word whose byte before it was no token byte. So a word right after +, ++,
//, @ or : with no blank (2 +a'', [ ] ++a'', { } //a'', { b ? 1 }@A'')
was read byte by byte, its '' opened an indented string, and a
luks.devices block after it named no mapping. Nix reads each of these as
an operator and a name. A carriage return in code was no blank either, so
a definition after one (x = 1;\rboot.initrd.luks.devices = …, or a file
whose lines end in a carriage return alone) was not read.

The Nix reading now starts a token at any run of token bytes and reads the
run as Nix's lexer does: each token is the longest of a URI, a path, an
identifier, a number and an operator there. A ' still ends a path, so /a''
is a path and a string. It reads a carriage return outside a string as a
blank. The reading by quotes alone is unchanged. Seed the fuzz target with
these forms.
…OS scan

A path marker was read from each byte of a line and only then checked to
begin a path there. Since a . or .. part after the leading slash counts,
a long run of ./ parts was read once from each of its slashes. Check that
the path begins first: a start inside such a run never begins one.
… count

The decoy requirements and the CHANGELOG now say that '' after an
operator starts no string and that a carriage return in code is a blank,
as Nix reads them, while '' after a path does. The rustdoc of
verify_base_config_clean said a path with a .. component is not matched,
which no longer holds for one right after the leading slash: it names
that case.
The Nix reading took 0.e5 as one float. Nix's float is [1-9][0-9]*.[0-9]*
or 0?.[0-9]+ with an exponent after it, so Nix reads 0.e5'' as the
integer 0, a . and the name e5''. The scan opened an indented string at
the '' instead, and a luks.devices block after it named no mapping:
let y = 0.e5''; in { boot.initrd.luks.devices = { data = …; }; } passed,
where the check refused it before the Nix reading lexed numbers. The same
held for 00.e5'', 01.e5'', 0.E5'', 0.e5-'', 0.e-5'' and 09.e1''.

Read a number as Nix's lexer reads one. Seed the fuzz target with such
numbers.
Checking where a path begins before reading it made a long run of
slashes quadratic: begins_path ran at every slash of the run and read
back over all of it, so a line of 16,000 slashes took about 42 s. Every
slash of a run has the same byte before the run, so read it once for
the run and keep the answer for the slashes after it.
…a token run

The Nix reading takes a carriage return as a blank between the names of
an attribute path and around its =, and reads a URI that starts inside a
run of tokens whole (1a:1'' is the number 1 and the URI a:1''). Pin both
with a mapping in a luks.devices block after them.
The decoy requirements now say that '' after a number Nix reads as an
integer and a . (0.e5'') starts no string, and that '' starts one right
after a path with no interpolation in it, since the Nix reading does not
follow the tail of an interpolated path.
…finds

Since the Nix reading lexes tokens as Nix does, it opens an indented
string at 1.5e3'', which Nix reads as a float and a string. The earlier
Nix reading let a '' continue any word whose last part holds a letter, so
it read 1.5e3'' as a word and saw a fileSystems label, a mapping or an
escaped path after it. Such files are not valid Nix, but the text stays in
/etc/nixos, and in a few hundred of them the check refused nothing now
where the earlier reading refused.

Keep that reading as Reading::Words: comments end as Nix's lexer ends
them, and tokens are read by words as before. Each line is matched with
what the reading by quotes finds, then by words, then as Nix reads it, and
a name any of them finds counts.
The decoy requirements said that what the reading by quotes alone finds
counts as well. Name the reading by words beside it, which lets '' continue
a word that holds a letter.
Reading::Words read tokens as the branch first did, so that the check
refused no input that version refused. That version never landed, and
the bar for the scan is next and Nix itself: nothing next refuses may
pass, and every file Nix parses and sees a hidden reference in must
refuse. The word reading found nothing beyond that and was quadratic in
'. Take it out with its test and the sentence of the decoy requirements
that named it.
…ath tails as Nix does

The Nix reading's lexer read, at every byte of a run of tokens, the rest of
the run again for a path and a URI scheme, so a run of dots, of words with
dots, of +, of numbers such as 0.e5 or a ruler of dashes in a comment took
time that grew with the square of its length: 16,000 dots took seconds.
The crypttab start scan read a run of quotes again from each of them, and
so did next. Keep the end of each run, as the slashes of a path already
are, and read each start run of a crypttab line once. A test pins every
such form to linear time.

Two places still read otherwise than Nix. A token right after a block
comment was taken for the inside of one, since the comment's / is a token
byte, so '' in a name there (/* x */a'') opened a string. And after an
interpolation in a path (./a${x}b) Nix reads the rest as path bytes that a
' ends, where the scan read a name. Start a token after a comment, and read
the rest of such a path as a path. Test both, and the 0.e5 rule where no
other reading finds the mapping.
…imits

The decoy requirements now say that '' right after a block comment starts
no string and that it does after the rest of a path that follows an
interpolation, and that the check reads a line in linear time but for sets
nested thousands deep.

This branch has not been deployed

No deployments
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