Repository navigation
Fonts: Grimoire's own folder on the Kindle is made afresh when the entry at its name is not its own (#201) - #202
Merged
Merged
Conversation
…s own is moved aside, and the folder made afresh (#201) The job that checks fonts opens Grimoire's own folder (/var/local/grimoire on the Kindle) by descriptor and holds it to "a folder of this user's that no one else may write". When the entry at that name does not pass (a link, a file, a pipe, a folder of another user or one others may write), the job now renames it within its parent to <name>.not-own-<seconds>-<pid> with the rename that never replaces an entry (renameat2's no-replace flag, or fsview's reservation where the flag is refused), never following, opening, reading, listing or deleting it, logs its kind, owner and mode once, and makes the folder afresh (mkdirat 0700), which is opened and checked as before. Every font is then checked once more. A process tries this at most once; when the move fails or the fresh folder is not Grimoire's own either, nothing is kept, as before, and the log says why. The folders below are Grimoire's own and are never moved. The UI's opens move nothing. Tests: test_sec_font_verdict's new cases (each kind moved aside as it was, at most once a process, never onto a taken name, an entry back at the name between the move and the make, a parent that takes no write, the app end to end); the base-level legs of the not-own case move to them, and the app's "says once" case now uses a data root's folder that is a file. A unit test of the name, and a root-only test in test_sandbox_linux for a folder of another user (CI's sandbox job). Refs #201 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uoe9ZJNyEZYoc4bsjqbSyQ
…the floors set from them (#201) TESTING.md's fonts section: step 1 now gives what a Scribe answered (/var/local is a file system of its own, ext4, read and write, 996,780 KB with 868,764 KB free and 65,536 inodes with 63,718 free; /var/local itself is mode 2775, of a system user and group), and its rule is what the code needs: a file system that keeps files, owners and modes, with the room the floors ask; Grimoire never relies on /var/local itself, it tests its own folder at every open and moves aside an entry at its name that is not its own. STATE_FREE_FLOOR (4 MB) and STATE_FILES_FLOOR (512 files) are set from those numbers and are no longer placeholders, in the docs and in the code's comment; the glyph limit and the draw size stay placeholders. Step 3 says what a folder made under a setgid /var/local shows, and a new step 12 checks the move aside on a device. KINDLE.md says where the verdicts are kept and that the folder is made afresh when the entry at its name is not Grimoire's own, with the new log lines; DESIGN.md's verdict store says the same rules; the changelog's fonts entry gains one sentence. BACKLOG: the entry on the untested parent goes (Grimoire no longer relies on it), and removing by hand covers what was moved aside. test_sec_invariants: a pin for each new rule sentence, held with the line of userfonts.rs that makes it true (the whole of base_afresh for what is never done to the entry), and gone pins for the old step 1 rule and the placeholder wording. Each was shown to fail once, by changing the code lines and by rewording the sentences. Refs #201 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uoe9ZJNyEZYoc4bsjqbSyQ
…the run's first check (#201) Each font check is a process of its own, so the move aside's once-a-process flag let every check of a run move an entry aside: a writer of the parent that put a folder at the name after every check got one move and one more check of every font each time, without end. A writer that only took the folder away got the same loop already, since every check made a missing folder anew and a check that ended with more fonts left queued the next one. The UI now decides, from its own memory: the first check it queues in a run carries the mark USERFONTS_AFRESH at the head of its argument, and only a check with that mark may make Grimoire's own folder when it is missing or move aside what stands at its name (VerdictDir::open's new `afresh`). A later check of the run needs the folder there and Grimoire's own; otherwise it keeps nothing and ends with status 6 as before, after which the session checks no more fonts until Grimoire starts again, said once. Nothing outside the UI's memory decides it: no file on the storage or in the parent. The folders below Grimoire's own are made as before. A process still tries the move at most once. Tests (test_sec_font_verdict): a run's first look moves aside and checks; with a folder others can write put back, and then with nothing there, later checks of the run end 6, move nothing and make nothing; the next run moves once more. The app against a writer of the parent racing it (taking the folder after every check and putting a writable folder there, or leaving nothing), three fonts: one move a run at most and three checks at most, then a start without that writer moves once and the font draws. Reverted (every check given the mark, or every check making the folder as before) the app case runs 74 checks in 2.5 s. The direct job calls that expect a move pass the mark; the Linux root test does too. DESIGN.md, KINDLE.md and TESTING.md step 12 say once a run, with pins on the UI's line and the base's open (the load_file pin follows its two-argument open). Refs #201 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uoe9ZJNyEZYoc4bsjqbSyQ
…wn, said and tested (#201) The Kindle's /var/local has the setgid bit and a group that may write it, so every folder Grimoire makes there comes out 02700, with that group. own_stat takes it because it asks only the write bits of group and others; its comment now says so, and why: the setgid bit, like the sticky bit, lets no one else write the folder, and the group it brings has no rights in it. Tests. A unit test of own_stat's rule by mode (userfonts.rs): 0700, 0750, 0755, 02700, 02750, 02755, 01700, 01755 and 03700 are Grimoire's own; anything with a write bit for group or others is not, setgid or sticky bit or not; nor is a folder of another user, a link or a file. Refusing the setgid bit, or the sticky bit, in own_stat fails it. The Linux root test (test_sandbox_linux, CI's sandbox job) now uses a parent like the Kindle's: another user's and another group's, mode 02775. The fresh folder must be root's, of that group, mode 02700; a second check given leave to move takes it and moves nothing; and a process of that group, not root, cannot make a file in it. It was compiled here for x86_64 Linux; it runs in CI only. TESTING.md step 3's sentence on the folders under a setgid /var/local is pinned with own_stat's line. Refs #201 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uoe9ZJNyEZYoc4bsjqbSyQ
…inned (#201) DESIGN.md said the entry at the own folder's name is "renamed by descriptor as it stands", which reads as if the entry were held by a descriptor; it is renamed by its name from the parent's descriptor, and the kind, owner and mode logged are those looked at just before the rename, so an entry another writer of the parent puts there in between is the one moved, and is left as it is too. The sentence now says that, and so does base_afresh's comment. "Grimoire never relies on the parent" said more than the code does: the parent holds the own folder's name, the folder opened there is tested at every open, and the parent's owner and mode are never trusted. That is what it says now. test_sec_invariants: the reworded sentences are held with what they stand on (the parent opened and held to nothing, own_dir_at's test, the whole of base_afresh), with gone pins for the old wording; KINDLE.md's "An entry moved aside is left too: Grimoire never opens or removes it." is held with base_afresh, and its two lines for a move that cannot be made and a fresh folder that is not Grimoire's own either with the log lines the code writes. Each was shown to fail once, by rewording the sentences and by changing the code they stand on. Refs #201 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uoe9ZJNyEZYoc4bsjqbSyQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fonts: Grimoire's own folder on the Kindle (
/var/local/grimoire, where what a font's check found is kept) is made afresh when the entry at its name is not Grimoire's own (#201).What it does
own_dir_at,own_dir,own_statinuserfonts.rs). When the entry at that name does not pass, and looked at without following it (fstatatwithAT_SYMLINK_NOFOLLOW) is not such a folder (a link, a file, a pipe, a folder of another user or one that others may write), the job moves it aside within the parent and makes the folder afresh (base_afresh).rename_noreplace):renameat2withRENAME_NOREPLACE, or where the kernel or the file system refuses the flag, the reservation of the new name first. The new name is<name>.not-own-<seconds>-<pid>(grimoire.not-own-1763500000-1234on the Kindle). It is held tofsview_name_checkbefore the move, and it cannot replace anything: an entry already at that name makes the rename fail with EEXIST and nothing moves. The entry is renamed by its name, from the parent's descriptor, as it stands: never followed, opened, read, listed or deleted.mkdirat0700), opened and held toown_direxactly as before. It holds no verdict, so every font is checked once more, as afterrm -r /var/local/grimoire.USERFONTS_AFRESHat the head of its argument, and only a check with that mark may make Grimoire's own folder when it is missing or move aside what stands at its name (VerdictDir::open'safresh). A later check of the run needs the folder there and Grimoire's own; otherwise it keeps nothing and ends with status 6, "what the check finds cannot be kept (it is not Grimoire's own)" or "(it is not there)", and the session checks no more fonts until Grimoire starts again, said once. No file on the storage or in the parent takes part in that decision. A process also tries the move at most once.fonts) are inside Grimoire's own 0700 folder, which no one else can write; one of them that does not pass keeps nothing, as before, and is never moved.own_statasks only the write bits of group and others, so they are Grimoire's own: the setgid bit, like the sticky bit, lets no one else write the folder, and the group has no rights in it. The comment onown_statsays so.fonts: the entry at the name of Grimoire's own folder was not its own (a folder, owner 0, mode 2775): it is moved aside as it was, and the folder is made afresh; every font is checked once more. When it gives up:... is not its own (...) and cannot be moved aside (<why>), orfonts: the folder made afresh is not Grimoire's own either (<why>); nothing more is moved aside.No new user-visible string (log lines only); po/ is untouched.
Changes after review
43f6976a: once a run, as above. Before it, each check could move an entry aside (once a process, and each check is a process), and a check that ended with more fonts left queued the next one, which made a missing folder anew; with a folder put back at the name, or taken away, after every check, the checks went on from one to the next. Now the run's later checks end with status 6 and the session stops checking. The review's helper (a writer of the parent racing the app, three fonts): 2 checks and 1 move with a writable folder put back after every check, 2 checks with the folder taken away each time.74b74700: the setgid parent, said inown_stat's comment and tested (a unit test of the rule by mode; the Linux root test now uses a 02775 parent of another user and group).8343c32b: DESIGN.md says exactly how the entry is renamed and what the log describes, and that Grimoire relies on the parent only to hold the folder's name (it tests the folder it opens at every open and never trusts the parent's owner or mode); KINDLE.md's remaining rule sentences are pinned.The device's answers, and the floors
docs/TESTING.md's fonts section, step 1, gives what a Scribe answered (firmware 5.20.1.0.2, Grimoire 2.1.0): /var/local is a file system of its own, ext4, mounted read and write, 996,780 KB with 868,764 KB free and 65,536 inodes with 63,718 free; /var/local itself is mode 2775, of a system user and group. The step's rule is what the code needs: a file system of its own that keeps its files, owners and modes, with the room the floors ask. Grimoire tests its own folder at every open and moves aside an entry at its name that is not its own, so the owner and mode of /var/local ask nothing of a release.
STATE_FREE_FLOOR(4 MB) andSTATE_FILES_FLOOR(512 files) stand on those numbers (a check keeps a few hundred bytes and one file a font, at most 200 for a data folder) and are no longer called placeholders, in the docs and in the code's comment; the glyph limit and the draw size stay placeholders.Docs
moved asideline; step 3 says what a folder made under a setgid /var/local shows (drwx--S---, its group with no rights); step 12 checks the move aside on the device (Grimoire closed,mv /var/local/grimoire /var/local/grimoire.test && mkdir -m 775 /var/local/grimoire, start, the log line, the fresh folder, every font checked once more, a second start moves nothing), then once a run (the same with Grimoire running and a new font copied in: nothing more is moved aside, the checks stop, the next start moves it).Tests
rust/tests/test_sec_font_verdict.rs(each case through the real job and a real worker, in this process unless said):what_is_not_grimoires_own_is_moved_aside: a folder with group write (0775), one with other write (0757), a link to a folder of this user's outside the parent, a link to nothing, a file, a pipe. Each is moved aside under the new name with the same inode and mode, what it holds unchanged, a link still a link to the same target, the folder it names untouched (names, bytes, times), a pipe never opened; the log line once with its kind, owner and mode and no path; the fresh folder 0700 with the font's verdict in it, and the font loads; a second job, in this process and forked as the app forks it, moves nothing; the other entry in the parent is as it was.a_run_makes_its_own_folder_afresh_once: the run's first look queues a check (forked, as the app forks it) that moves aside and checks the font; with a writable folder put back at the name, and then with nothing there, later checks of the run end with status 6, move nothing, make nothing and mark nothing, and say why; the next run moves once more and the font loads.a_writer_of_the_parent_costs_one_move_a_run: the app with three fonts against a writer of the parent racing it (a thread that takes Grimoire's folder away whenever it is at the name, and puts a writable folder there, or leaves nothing). One move a run at most, three checks at most, the checks stopped once; then a start without that writer moves aside once and the font draws. Here: 2 checks, 1 move; and 2 checks, no move.moved_aside_at_most_once_a_process: a process given leave tries once: after a move, the fresh folder renamed away and a 0777 folder put at the name, the same process moves nothing and keeps nothing (6). A fresh process, with an empty folder at every name it could take in the next 30 seconds, moves nothing (EEXIST) and every entry is as it was. Then it moves, and the font is checked once more.an_entry_back_at_once_is_not_moved_again: a test seam puts a 0777 folder at the name between the move and the make: the job gives up (6), says why, marks nothing, one entry moved aside.a_parent_that_takes_no_write_moves_nothing: the parent 0555 (not run as root): the move fails, the job gives up (6), the parent is as it was; with nothing at the name, "it cannot be made", as before.the_app_moves_aside_what_is_not_its_own: the app started with a 0775 folder at the name: the check it forks moves it aside, checks the font, and the font is in use; the log line once, no path.a_folder_that_is_not_grimoires_own_keeps_nothingkeeps its cases below the first level (and checks nothing is moved aside).the_app_says_once_that_nothing_can_be_keptmakes the data root's folder inside Grimoire's own a file (still "not Grimoire's own", never moved), so it still shows the once-only notice. The direct job calls that expect a move passUSERFONTS_AFRESH, as the first check of a run has it.userfonts.rsunit tests:an_entry_moved_aside_has_a_name_of_grimoires_own(the name's form, the name rules, the longest the Kindle's can be) andown_stat_asks_only_who_may_write(0700, 0750, 0755, 02700, 02750, 02755, 01700, 01755 and 03700 are Grimoire's own; a write bit for group or others is not, with or without the setgid or sticky bit; nor a folder of another user, a link or a file).rust/tests/test_sandbox_linux.rs, root only (CI'ssandboxjob, Ubuntu):a_folder_of_another_user_at_the_own_folders_name_is_moved_aside, in a parent like the Kindle's (another user's and another group's, mode 02775): a folder of uid 65534, mode 0700, at the name is moved aside with the same inode and mode, still that user's, what it holds unchanged; the fresh folder is root's, of the parent's group, mode 02700; a second check takes it and moves nothing; a process of that group, not root, cannot make a file in it. It compiles for x86_64 Linux here (cargo check --target x86_64-unknown-linux-gnu); it runs only in that job.How each was shown to fail (the code changed in a copy, the test run, the file put back):
userfonts.rsa_run_makes_its_own_folder_afresh_once(6 checks);a_writer_of_the_parent_costs_one_move_a_run: 74 checks and 74 moves in 2.5 s, and 74 checks with the folder taken awaya_run_makes_its_own_folder_afresh_once(2 checks); the app case with the folder taken away: 74 checksown_statrefuses the setgid bit, or the sticky bitown_stat_asks_only_who_may_write(02700, 01700), and the pin on step 3base_afreshnever called)moved_aside_at_most_once_a_process(the same process tries again)renameatin place of the no-replace renamemoved_aside_at_most_once_a_process: an empty folder at the new name is replaced, 5 checksa_folder_that_is_not_grimoires_own_keeps_nothing(4) andthe_app_says_once_that_nothing_can_be_kept(7)an_entry_back_at_once_is_not_moved_again, 7 checksfstatatfollowing a linkwhat_is_not_grimoires_own_is_moved_aside, 6 checks(The last six rows were run on the first version of this change.)
rust/tests/test_sec_invariants.rs,the_docs_follow_the_own_folders_move_aside: a pin for each rule sentence of DESIGN.md, KINDLE.md and TESTING.md, held with the line ofuserfonts.rsthat makes it true (the first-level match, the base's open withafresh, the UI's once-a-run line, the folders below, the name, the no-replace rename, thefstatatthat follows no link,own_stat's rule for step 3, the parent opened and held to nothing, the log lines, the two floors), the sentences on what is never done to the entry held with the whole ofbase_afresh, and gone pins for the old wording. Each new pin failed once with its code line changed and once with its sentence reworded.Not tested: a folder of this user's that no one else may write but that did not open (it needs a process out of descriptors).
What was run
On head 8343c32, on macOS (aarch64) with the release's toolchain (Rust 1.97.1, zig 0.16.0):
test_sec_font_verdict(362 checks),test_sec_invariants, theuserfonts.rsunit tests,test_fontcheck,test_fontguard,test_addfont,test_file_previews,test_sec_work_links: passed.tests/scenarios/*font*.qs): ok.make check, the full gate: make's last line isCHECK PASSED(559 scenario runs and the 8 run again 400 ms late, all ok;l10n-check: every language fits (en es ja pl); the unit tests of the host and the sim build; the clean builds give the same bytes twice).cargo check --target x86_64-unknown-linux-gnu --features sim --test test_sandbox_linux).Nothing ran on Linux here, and nothing on a Kindle. CI's
sandboxjob (Ubuntu, as root) ran the root-only test on this head: ok, with the line(a folder, owner 65534, mode 0700): it is moved aside as it was, ....Device check
Not run on a Scribe beyond step 1's answers. docs/TESTING.md, "Hardening round (2026-11), fonts", step 12 checks the move aside and the once-a-run rule on the device.
Closes #201
🤖 Generated with Claude Code
https://claude.ai/code/session_01Uoe9ZJNyEZYoc4bsjqbSyQ