Skip to content

initramfs, device-cheetah, device-raven, device-lynx (versions at merge): guard the boot LUNs as the main LUN (#252) - #484

Open
derekross wants to merge 4 commits into
mainfrom
guard-boot-luns
Open

derekross wants to merge 4 commits into
mainfrom
guard-boot-luns

Conversation

@derekross

@derekross derekross commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Implements the maintainer's ruling on #252: guard the boot LUNs the way the main LUN is already guarded, so #483's window can be devinfo alone.

Never booted. Needs Derek's Pixel 7 Pro run before merge (runbook: device/cheetah/STORAGE-GUARD-PLAN.md §2, including R5, which runs the marker's new write path for real). Blocks #483, which rebases onto it afterwards. After the merge, every device's boot files need restaging.

Why

The kernel counts a partition read-only when its own flag or its disk's flag is set (bdev_read_only()). The guard removed /dev/sda and left sda's flag clear, but set the boot LUNs' (sdb, sdc, sdd) disk flags and kept their whole-disk nodes. So writing devinfo meant clearing sdd's flag, and while it was clear, /dev/sdd reached pinfo, blenv and mfg_data too.

What changes

  • initramfs/init. Every LUN's whole-disk node is removed, and no disk's own flag is ever set. A node that won't go is retried and warned about. Every partition gets its own flag, except the UFS_RW allowlist, which still opens sda partitions only. The hand-over check also keeps the phone in the initramfs while any whole-disk node is still there.

    • After the first pass, nothing is writable that wasn't before.
    • Inside the initramfs, a boot-LUN partition can now be writable from its birth until the next pass, about 0.2 s. The kernel creates the disk's node before it scans the partitions, and each partition starts with its own flag clear. sda's partitions have always had this window, and nothing in the initramfs writes a boot-LUN partition.
  • omamobile-boot-success (device-cheetah, raven and lynx): a cheetah change. The old marker ran blockdev --setrw /dev/sdd first, so under the new guard it fails whenever slot B needs marking. The new marker reads the disk flag:

    • clear (the new guard): it clears devinfo's own flag alone, checks it, writes, and sets the flag again;
    • set (an older initramfs): it runs the old disk-then-partition sequence, so a rollback to an older image set still marks B.

    It also carries the line # guard: partition flags (#252), which push and flash look for.

  • bin/omamobile push and flash: the order on development phones. push and flash build the init from the checkout, but the marker comes from the installed package. For a device whose package ships the marker:

    • push reads /usr/bin/omamobile-boot-success over SSH. It refuses images with the new guard when the guard line is missing, or the file itself is.
    • flash can't read the phone, so it refuses images with the new guard unless OMAMOBILE_MARKER_CHECKED=1 is set. I chose a refusal over a warning because a warning scrolls by, and a wrong marker shows only three boots later, as a fallback to slot A. The error message gives the one-line check to run on the phone.
    • Images whose initramfs reads as the old guard skip the check. A missing or unreadable initramfs doesn't.
  • Docs.

    • CONTRIBUTING §3.2 and AGENTS §1 describe the new guard.
    • 10-omamobile-storage.rules: the wrong "udev would recreate /dev/sda" comment is fixed in all seven copies (devtmpfs makes a node only in device_add). The rule itself is unchanged.
    • device/husky/UFS-PLAN.md: its future checks no longer expect sdb-sdd to read ro.

Unchanged, checked: push and omamobile-boot-update write only sda partitions found by PARTNAME. nv-backup, phone-provision, omamobile-fp and phone-smoke read partitions by PARTNAME and never open a whole-disk node.

Merging this

Tested (no phone, no build)

  • tests/storage-guard. Its fake sysfs ro files follow the own-or-disk rule, and the blockdev stub refuses a missing node. It covers:

    • the disk nodes gone and the disk flags clear;
    • the boot-LUN partitions' own flags set;
    • the allowlist limited to sda;
    • devinfo's own flag opening devinfo alone;
    • a node that comes back, a node that won't go, and a late LUN.
  • tests/images-layout (the image-building part skipped): push and flash with the guard line present, the line missing, the marker file missing, and the override; an initramfs with the old guard, the new guard, and an unreadable one. Fastboot is never called before the refusal.

  • Other tests: tests/initramfs-steps, tests/modules-push, tests/boot-method, sh -n initramfs/init, tools/pr-check origin/main.

  • packages/omamobile-device-cheetah/test/boot-success, run on all three markers. It covers:

    • the new guard and the old guard;
    • a flag that won't clear and a failed write;
    • a devinfo that isn't on a LUN, and a phone with no devinfo;
    • the guard line.

    It fails against main's marker.

  • Mutations:

    • guard: 10 of 10 caught;
    • marker: 5 of 6 caught; the survivor is a no-op, since the node is gone;
    • push/flash check: 7 of 8 caught. The survivor drops grep's || true; it still refuses, with a different message.
  • Not run locally: tests/packages and the package test/all files, which compile C. CI runs them.

Open questions

  • Widening the udev rule's mode 0000 to the boot LUNs is not needed: a removed node can't come back without a new device_add. If it is ever widened, it should match the UFS host rather than sd[a-z], because USB drives also enumerate as sd*.
  • phone-smoke could flag "a LUN with its node present and its disk flag clear", which is unguarded under both the old and the new guard. That is a follow-up.
  • device/flame/initramfs/init (Qualcomm) has its own guard and is untouched.

🤖 Generated with Claude Code

derekross and others added 2 commits November 7, 2026 11:00
…252)

The kernel counts a partition read-only when its own flag or its disk's
is set (bdev_read_only). The guard removed /dev/sda and left sda's flag
clear, but set the boot LUNs' (sdb, sdc, sdd) disk flags and kept their
whole-disk nodes, so writing any one boot-LUN partition (devinfo) meant
clearing the disk flag, and while it was clear /dev/sdd reached every
partition on the LUN. #483 found it; the maintainer's ruling on #252:
guard the boot LUNs the way the main LUN is guarded.

Every LUN is now guarded the same way: its whole-disk node removed (a node
that won't go is retried, warned about and reported), its own flag never
set, each partition's own flag set except the allowlist, which still opens
partitions of sda only. The hand-over check also refuses Arch while any
whole-disk node is there. Nothing becomes writable that wasn't, and a tool
can open one partition by clearing that partition's own flag alone.

omamobile-boot-success (device-cheetah 0.1.45, raven 0.1.33, lynx 0.2.3)
ran blockdev --setrw on /dev/sdd first; under the new guard that node is
gone and the marker fails whenever slot B needs marking. It now clears
devinfo's own flag alone when the disk flag is clear, and keeps the old
disk-then-partition sequence when an older initramfs set the disk flag,
so a fastboot rollback to an older image set still marks slot B.

push, omamobile-boot-update, nv-backup, phone-provision, omamobile-fp and
phone-smoke use partitions found by PARTNAME and never a whole-disk node.

Tested without a phone or a build: tests/storage-guard (fake sysfs whose
ro files follow the own-or-disk rule: every disk node gone and its flag
clear, each boot-LUN partition's own flag set, the allowlist unchanged and
sda-only, devinfo's own flag opening devinfo alone with no disk flag, a
returning or stuck node and a late LUN), tests/initramfs-steps, sh -n,
and the new packages/omamobile-device-cheetah/test/boot-success (new and
old guard, a flag that won't clear, a failed write, a non-LUN devinfo; it
fails on the old marker), also run on raven's and lynx's markers. Ten
mutations of the guard and five of the marker were each caught. Never
booted: device/cheetah/STORAGE-GUARD-PLAN.md is the runbook for the 7 Pro.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…round 1 (#484)

The review of #484 found the order unsafe on development phones: push and
flash build the init from the checkout, but omamobile-boot-success comes
from the installed device package, and an old marker under the new guard
never marks slot B, so the next flash would end in a fallback to slot A.

- The new marker carries "# guard: partition flags (#252)". For a device
  whose package ships the marker (cheetah, raven, lynx), push reads the
  phone's marker over SSH and refuses images with the new guard unless
  the line is there (a missing marker too); flash can't read the phone,
  so it refuses those images unless OMAMOBILE_MARKER_CHECKED=1. A warning
  would scroll by, and the failure shows only three boots later. Images
  whose initramfs reads as the old guard skip the check; a missing or
  unreadable initramfs doesn't. tests/images-layout covers each case;
  eight mutations, seven caught (the survivor drops grep's "|| true",
  which still refuses, with another message).
- STORAGE-GUARD-PLAN: R5 runs the marker's new write path on the 7 Pro
  (a flash that unmarks B, a devinfo copy before and after, rollback to
  the old-init set whose old-guard path marks B); R4 arms a detached
  relock; "after the first pass" with the new-partition window explained;
  the merge order, the owners' notice and the version collisions.
- test/boot-success: the guard line, and a phone without devinfo.
- 10-omamobile-storage.rules: the comment said udev would recreate
  /dev/sda; devtmpfs makes a node only in device_add. Comment only, the
  rule is unchanged, so felix, husky, panther and tegu aren't bumped.
- husky UFS-PLAN: its future checks no longer expect sdb-sdd to read ro.

Tested without a phone or a build: tests/storage-guard,
tests/initramfs-steps, tests/images-layout (image part skipped),
tests/modules-push, tests/boot-method, test/boot-success on all three
markers, sh -n, tools/pr-check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@W4HO-ham

Copy link
Copy Markdown
Contributor

An offer, since this is the step the 9a's modem and GNSS cells wait on (through #483) and you have a long queue: I can do the rebase and hand it to you as a branch to review, if that saves you time. It stays yours to decide and to boot on the 7 Pro.

I tried the merge with today's main (6649b76) to see what it takes. The branch is 197 commits behind and conflicts in five files:

  • the three version files (main has moved each; yours to set at merge anyway);
  • initramfs/init and tests/storage-guard, which is the real one. Main has since gained two things in the same functions: UFS_RW_LUNS (initramfs: guard UFS_RW partitions on a second LUN (UFS_RW_LUNS) #530: a LUN the descriptor names is guarded as sda is, and the allowlist may name partitions on it) and the NFS-root mode (every disk and partition read-only by flag, nodes kept). They need a decision rather than a text merge: this branch's rule is that the allowlist opens nothing off the main LUN, and that no disk flag is ever set.

How I would put them together, unless you see it differently: every LUN's whole-disk node removed and its flag left clear, as here; the allowlist honoured on sda and on the descriptor's UFS_RW_LUNS only; NFS-root mode kept as main has it (disk flags set, since nothing is written there at all), with ufs_unguarded reporting a present node in the normal mode and a clear disk flag in NFS mode; and the tests of both sides kept, with the fake disks gaining sde. The device packages added since (akita, dodge, tegu) would need the udev rule's change as well.

Say the word and I'll push it to my fork with the test run, or leave it with you if you'd rather do it yourself.

@W4HO-ham

Copy link
Copy Markdown
Contributor

A correction to my last line about the device packages: the ones on main that carry 10-omamobile-storage.rules and that this branch doesn't touch yet are akita and oriole. tegu is already in the branch, and dodge has no such rule.

…and the NFS root

Main gained two things in the guard since this branch: a LUN list beside sda (UFS_RW_LUNS, #530) and the NFS-root mode. Both are kept, on this branch's rule that every LUN loses its whole-disk node and keeps its disk flag clear.

initramfs/init: every LUN is guarded alike; the allowlist is honoured on sda and on a listed LUN only; with an NFS root sda keeps main's disk-level read-only flag and the other LUNs are guarded by their partitions' own flags. tests/storage-guard keeps both sides' cases on the own-flag model (the late LUN is now sdf, since sde is the listed LUN's fixture). akita and oriole get the storage rule's new comment. Versions: device-cheetah 0.1.55, device-lynx 0.2.5, device-raven 0.1.37.
@W4HO-ham

Copy link
Copy Markdown
Contributor

I had a quiet evening while a long sleep run went on the 9a, so I did the merge with main rather than only offering it. It's on my fork as guard-boot-luns-on-main: your two commits untouched, one merge commit on top (main at 6649b76). Take it, take pieces of it, or ignore it; nothing here has run on a phone, only the tests.

What I decided where the two sides met, so you can overrule any of it:

  • initramfs/init. Every LUN is guarded as this branch rules: node removed, disk flag clear, each partition's own flag set. Main's UFS_RW_LUNS (initramfs: guard UFS_RW partitions on a second LUN (UFS_RW_LUNS) #530) keeps its meaning in the one place it still matters: the allowlist is honoured on sda and on a listed LUN, nowhere else. An unlisted LUN no longer gets a disk flag, its partitions get their own.
  • NFS root. I kept main's behaviour for sda exactly (node kept, blockdev --setro on the disk, the hand-over check reports sda if it reads writable), so nothing merged is weakened; the other LUNs are guarded the Marking slot B successful: the plan after #125's hold, and for the Pixel 8 Pro #252 way under NFS too, so devinfo can still be opened alone there. If you'd rather NFS root be plain "closed allowlist, every LUN alike", it's a deletion of two small blocks.
  • tests/storage-guard. Both sides' cases run on this branch's own-flag model. The fixture now always has main's sde (boot_a, boot_b, dtbo_b, vbmeta_b), so your late-LUN case uses sdf. Main's "unlisted LUN is read-only at the disk level" became "no partition on it is writable, boot_b too"; the NFS case checks sda's disk flag and the other LUNs' partition flags.
  • Versions: device-cheetah 0.1.55, device-lynx 0.2.5, device-raven 0.1.37 (main's plus one).
  • akita and oriole get the storage rule's new comment, as the other device packages did here; no version bump for a comment, as with felix, husky and panther.
  • Two doc lines followed the code: the UFS_RW_LUNS row in RELEASES.md and the guard's paragraph in CONTRIBUTING.md (the listed LUN, the NFS root).

Run here: tests/storage-guard and tests/all pass, tools/pr-check passes. tests/packages passes except omamobile-omarchy's QML parse check, which fails the same way on plain main on my laptop (its qmlformat), so I take it to be my machine, not the merge.

On W4HO-ham's merge of 2026-11-14 (UFS_RW_LUNS and the NFS root). Main has
since made the allowlist follow the slot the phone runs from
(ACTIVE-SLOT-PLAN §4); the guard's pass merged without conflict, since the
slot mapping happens where the list is loaded. tests/storage-guard keeps
this branch's fake disks (every LUN, own flags) and gains main's slot
argument and its slot-A cases. device-cheetah's version is main's: it is
set after an image from this branch has booted on the 7 Pro.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@derekross

derekross commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner Author

Brought up to date with main (34328ecf).

  • Base: @W4HO-ham's merge of 11-14 (8a934ef6), taken as it is, with its three choices: every LUN is guarded as this branch rules (node removed, disk flag clear, each partition's own flag set); the allowlist is honoured on sda and on a LUN in UFS_RW_LUNS, nowhere else; an NFS root keeps main's behaviour for sda. Thank you for doing it.
  • On top: today's main, which since then made the allowlist follow the slot the phone runs from (ACTIVE-SLOT-PLAN §4). The guard's pass merged without a conflict, because the slot mapping happens where the list is loaded. tests/storage-guard keeps this branch's fake disks and gains main's slot argument and slot-A cases: 56 checks pass, with every boot-LUN partition read-only on a slot-A boot too.
  • Versions: device-cheetah stays at main's 0.1.60 until an image from this branch has booted on the 7 Pro; device-raven is 0.1.37.

Still open before a merge: the 7 Pro boot; the akita and oriole packages, whose 10-omamobile-storage.rules this branch doesn't touch yet; and a review of the merged guard from the first line. The guard test ran under plain sh only: busybox isn't installed here and CI doesn't set GUARD_SH, so the busybox run (GUARD_SH="busybox sh" tests/storage-guard) is also still owed.

@W4HO-ham

Copy link
Copy Markdown
Contributor

The busybox run, on 34328ec: GUARD_SH="busybox sh" tests/storage-guard passes all 56 checks with BusyBox v1.37.0 (taken from nixpkgs for the run), as does plain sh on the same commit.

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.

2 participants