Skip to content

soc: apple: sep: open the xART guard's list per access - #1264

Merged
RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
jgoyvaerts:pr/sep-xart-owned-per-access
Nov 10, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
jgoyvaerts:pr/sep-xart-owned-per-access

Conversation

@jgoyvaerts

Copy link
Copy Markdown
Contributor

The xART guard keeps /var/lib/aurora-sep-xart-owned.bin open read-write from the kernel until power-off. Like the host-state store in #583, that keeps a writer on whatever file system holds /var/lib, so it can't be remounted read-only at shutdown. This opens the list only while it is being used.

What happened

Guard::open() opens the list with open_host and keeps the file in Guard.file. The guard belongs to the xART store, which the SEP device holds until it is unbound, and nothing unbinds it before a reboot. Killing every process at shutdown doesn't close a file the kernel opened.

#583 says the host-state store is the only file that stays open. That holds where the guard is off, but wherever the guard is on (level 1 here: xART guard level 1: 11 session records exist, 0 created by Linux), the list stays open too. Both fixes are needed before the file system unmounts cleanly.

On this machine /var/lib is on the root (ext4), and every boot since the SEP driver arrived replayed the journal (EXT4-fs (nvme0n1p5): recovery complete). A final-shutdown hook recorded the state after systemd-shutdown's unmount loop:

Kernel systemd-shutdown / at the end Next boot
host-state store fixed (same change as #583) Not all file systems unmounted, 1 left. rw, needs_recovery set journal replayed
host-state store and this change All filesystems unmounted. ro, clean no replay

In both captures the only process left was systemd-shutdown itself, which held no file on /.

The change (xart_guard.rs only)

  • New HostListFile implements ListFile and opens OWNED_PATH for each access, then closes it: read-only for size, read_exact, sync and sync_parent, and open_writable_existing for write_all.
  • Guard::open() still calls open_host, but only to create the list if it is missing. That handle is closed at once.
  • Unchanged: the create-and-adopt rule in with_file() (the directory is flushed before a list is adopted), the list format, and the KUnit tests, which use their in-memory MemFile.
  • If the file vanishes mid-boot, the next adoption fails with ENOENT and the write is refused, which is the guard's safe direction.
  • fsync through a new descriptor still flushes the earlier writes and reports a writeback error no descriptor has seen. sep_store_sync_parent only uses the file's path, so a read-only handle works.

This doesn't conflict with #583: different files, and each works on its own.

Tested

  • J616s (MacBook Pro 14" M4 Pro, T6040), Arch Linux ARM, root ext4 holding /var/lib. 7.3.0, with this change and a host-state fix equivalent to soc: apple: sep: open the host-state store only for each operation #583:
    • The reboot above unmounted every file system, and the next boot mounted / clean, with no journal replay.
    • On both boots the enrolment survived (Touch ID: restored 1 enrolled identity/identities; enrolment survived reboot), the unlock preflight passed, and the SEP logged no errors.
    • Before this change, with only the host-state fix, / was still read-write at the end of shutdown, as shown in the table.
  • This branch (integration/aurora 90d2b1ef362): xart_guard.rs, shim.rs and store_shim.c are byte-identical to the tree I tested. apple-sep.o builds with no warnings, also with CONFIG_KUNIT=y and CONFIG_APPLE_SEP_KUNIT_TEST=y.
  • Not run: the KUnit suite.

🤖 Generated with Claude Code

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit (1106742) has no Signed-off-by: line, so it can't be taken as is. Could you add yours (git commit --amend -s) and push again?

On the change itself: opening the list per access looks right. size, read_exact, sync and sync_parent only need a read-only descriptor, write_all uses open_writable_existing so only Guard::open() can create the file, and an fsync on a fresh descriptor still flushes and reports earlier writeback errors. Losing the file mid-boot fails adoption with ENOENT, which refuses the write as intended.

The xART guard opens /var/lib/aurora-sep-xart-owned.bin read-write when
the xART store is set up and keeps it in the guard, which lives as long
as the store: until the device is unbound. Nothing unbinds it before a
reboot, so the kernel holds a writer on the file system that holds
/var/lib until power-off. systemd-shutdown's read-only remount of that
file system then fails with EBUSY and it stays read-write.

The host-state store has the same problem, and aurora-silicon#583 fixes that one.
Both files have to be closed before the file system unmounts cleanly:
on a J616s with the host-state store fixed, the root still was not
remounted read-only at shutdown, and every boot still replayed the
ext4 journal.

Open the list for each access instead: read-only for size, reads and
syncs, existing-only for writes. Only Guard::open() creates it. The
create-and-adopt rule in with_file() is unchanged: the directory is
still flushed before a list is adopted. The list format and the KUnit
tests, which use an in-memory file, are unchanged.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Assisted-by: LLM
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Replaced by #1337: the same diff with my Signed-off-by:, on a fresh integration/aurora.

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