Repository navigation
Conversation
DjDeveloperr
left a comment
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist audit at head 014b29bedf33a7250c4470adb8e3a3479f2e4ac6.
The core VFS replacement design in drivers/soc/apple/store_shim.c is thoughtfully engineered (full-write loop, vfs_fsync(temp, 0) before start_renaming_dentry()/vfs_rename(), d_is_reg() target guard, vfs_fsync(dir, 0) gating CONFIRM_SAVE, start_removing_dentry() cleanup that won't unlink a reused name, mnt_want_write() kept outside kernel_write(), and verified Linux 7.3 symbol exports for CONFIG_APPLE_SEP=m). However, there are blocking §1/§5/§6 gaps plus concrete store_shim.c edge cases to address before this can enter MERGETRAIN-LINUX4:
§1. No model gating & chicken-and-egg — BLOCKED (upgrade-order flag day)
- Model gating: PASS — no chip/SoC/board/firmware-version gates introduced.
- Chicken-and-egg / SELinux upgrade-order hazard (Blocker): The PR requires
aurora-sep-selinux1-14 (module 1.4.0) to be installed before booting a kernel with this change. On any Fedora Aurora host still runningaurora-sep-selinux1-13 (module 1.3.0) when the kernel updates first:type_transitiondoes not cover.apple-sep-catacomb-{master,owner,user}.bin.new, so newly created temporaries inheritvar_lib_tinstead ofaurora_sep_state_t.kernel_tlacksrename_file_perms/delete_file_permsonaurora_sep_state_t:filein 1.3.0.- Because SELinux enforces
inode_unlink/inode_rename(unexported hooks) rather thansecurity_path_unlink(which is a no-op under SELinux),sep_store_replaceable()/sep_store_publishable()cannot detect an outdated 1.3.0 policy during preflight. That meansdelete_identity()(0x57) orbio_prepare_enrol()(SELECT_CONTEXT) can pass preflight, mutate enclave state, and then failSAVE_CATACOMBwith-EACCES— or on first creation publish avar_lib_tcatacomb thatfprintd_t/kmod_t/init_tcannot read under Enforcing.
- Per §1's chicken-and-egg rule, ship
aurora-sep-selinux1-14 first (or split the policy update so it lands and ships ahead of the kernel consumer) before merging the kernel atomic-replacement switch.
§2. Production-ready, no hacks — CHANGES REQUESTED
- No new kernel cmdline/module parameters or race sleeps.
- Concrete bugs / edge cases in
store_shim.c&catacomb.rs:- Stale-cleanup race returns
-ENOENTinstead of retrying (drivers/soc/apple/store_shim.c,store_replace()/store_remove_stale()): Whenfile_open_root(..., O_CREAT | O_EXCL)returns-EEXISTand the stale.<name>.newdisappears beforestart_removing()takes the parent lock,store_remove_stale()returns-ENOENT, which breaks out of the 2-attempt loop and failsstore_replace()with-ENOENTinstead of treating-ENOENTas already-removed and retrying exclusive creation. fput(temp)bypassesfilp_close()/->flush(drivers/soc/apple/store_shim.c,store_replace()):tempis released withfput(temp)after rename rather thanfilp_close(temp, NULL), skippingf_op->flushand any close-time flush error (inconsistent withsep_store_close()and relevant on non-local/9P/FUSE filesystems).- Caller
current_umask()stripped on every replacement (drivers/soc/apple/store_shim.c,store_replace()):file_open_root(&dir->f_path, temporary, ..., 0600)stripscurrent->fs->umaskviamode_strip_umask()/posix_acl_create()when/var/libhas no default POSIX ACL. Previouslyopen_trunc()preserved an existing catacomb's0600mode across writes; now every replacement creates a new inode in caller context (bio_prepare_enrol,delete_identity/persist_deletion), so a caller with a restrictive umask masking owner bits produces a non-0600catacomb. Consider ensuring the created inode has explicit0600(or creating under a neutral umask /notify_change) if0600is an invariant. - Minor — unnecessary full-file read + CRC in
catacomb::publishable()(drivers/soc/apple/catacomb.rs):publishable()callsis_absent(kind), which runscatacomb::read()(allocating aKVecup to 1 MiB, reading the full file, and computing CRC16) on every preflight whenever an optional catacomb already exists, just to decide whether to callopen_writable_existing(). - Minor — unlocked
IS_APPEND/IS_DEADDIRread instore_check_publish()(drivers/soc/apple/store_shim.c): On-ENOENTfromstart_removing()(which has already droppeddir->i_rwsem),IS_APPEND(file_inode(dir))andIS_DEADDIR(file_inode(dir))are inspected unlocked.
- Stale-cleanup race returns
§3. Safety — CONDITIONAL ON §1 & §5
- No hardcoded hardware limits/tables; host-side VFS safety checks (
d_is_reg(),d_mountpoint(),store_dir_capable(),fsuidgid_has_mapping(),may_delete_dentry(),CONFIRM_SAVEstrictly after bothvfs_fsynccalls, non-regular.newpreserved) are sound. - However, SEP catacomb durability and SELinux Enforcing behavior cannot be considered production-safe until §1 upgrade ordering and §5 live hardware + Enforcing validation are proven.
§4. Clean-room and attribution — PASS
- All 3 commits (
1baf9f068f3a,f3923c3db19a,014b29bedf33) carry human author/committer (Matt <mmdisbro@gmail.com>) and humanSigned-off-by:only, with zero AI trailers in commits. - AI assistance is disclosed at the end of the PR body. No Apple code, strings, disassembly, or firmware values in the diff.
§5. Evidence — BLOCKED (no exact-head hardware / SELinux Enforcing proof)
- As candidly noted in the PR body, full
CONFIG_APPLE_SEP=mmodule linkage, KUnit execution, SELinux Enforcing operation, and exact-head SEP hardware behavior remain untested, and the earlier J313 report (omacom/linux-aurora#250) does not qualify this reworked series. - Before this can leave draft / be approved for merge, please provide exact-head evidence on an Apple Silicon Mac with SEP/Touch ID:
- Full arm64 kernel +
CONFIG_APPLE_SEP=mmodule build/link andkunit.pyapple_sep*pass. - Real Mac SEP catacomb boot + enrol/verify/delete + reboot and S2R cold-restore confirming inode replacement, clean restore across reboot/S2R, and no leaked
.apple-sep-catacomb-*.bin.newfiles. - Stale-temp recovery check (pre-existing regular
.newcleaned up and replaced; non-regular.newrefused without touching destination or mutating enclave). - SELinux Enforcing regression run with
aurora-sep-selinux1-14 installed:ls -Z /var/lib/apple-sep-catacomb-*.binshowingaurora_sep_state_tpost-replacement, 0 SELinux AVCs, 0 failed systemd units, 0 new kernel errors.
- Full arm64 kernel +
- Until hardware + CI evidence is ready, consider marking the PR as Draft per the pre-PR checklist.
§6. Naming & CI — BLOCKED (CI not yet run)
- Naming: PASS — no prohibited/stale naming in the diff.
- CI: Fork PR with no executed checks yet (
statusCheckRollupempty;SEP source checksandHost testsare bothaction_requiredawaiting maintainer workflow approval). Needs greenSEP source checks(includingrust-build,kunit, and the new atomic host suite) andHost testson the final head.
Assisted-by: LLM (Gemini 4 Neon)
RyanTheTide
left a comment
There was a problem hiding this comment.
Review at 014b29b. The replacement path fences the write and checks directory fsync before sending CONFIRM_SAVE. Deployment still needs to carry the matching SELinux policy before this becomes the default. Please add an enforcing upgrade row with the old release's state files followed by an enrollment and reboot on the new policy, and an unwind row for a parent fsync refusal. The host matrix and policy compile cover their mocked paths. They cannot establish working labels or recovery after a power loss on the shipped filesystem.
A kernel that publishes a catacomb by atomic replacement writes the complete file under a fixed temporary name, ".<name>.new", in /var/lib, and renames it over the catacomb. SELinux labels a file when it is created and rename keeps that label, so the temporary must be created with the state type, not var_lib_t. Give the three temporary names aurora_sep_state_t with type_transition rules and file contexts, and let the kernel set attributes on (to reset a temporary's mode to 0600 after a restrictive caller umask), rename and unlink state files. Bump the module to 1.4.0 and the package to 1-14. This policy has to be installed before a kernel with atomic catacomb replacement, so it lands and ships on its own first. It only adds labels and permissions; current kernels are unaffected. Signed-off-by: Matt <mmdisbro@gmail.com>
catacomb::write() truncates the saved catacomb and rewrites it in place. An error or crash between the truncate and the final sync leaves a short or empty file where the last valid generation was, and the enclave cannot restore it at the next start. Write the complete file under a fixed temporary name, ".<name>.new", fsync it, close it, rename it over the catacomb under the directory lock, and fsync the parent before reporting success. Closing before rename runs ->flush, so a close-time flush error leaves the previous generation in place. A failed parent fsync is reported as an error even though the replacement is already visible, so SAVE_CATACOMB is not confirmed. Non-regular destinations are refused. The parent is resolved from userspace init's root, as open_as_kernel() does; kernel threads start in nullfs. Both the writer (before creating a temporary file) and admission require the parent directory to support directory fsync and rename. O_CREAT applies the calling task's umask to the temporary. When that umask cleared bits from 0600, set the mode back with notify_change() before writing, so the published file is 0600 regardless of the caller. A failure there unlinks the temporary and keeps the previous catacomb. The ".<name>.new" names are reserved for the driver, and a driver lock serializes its replacements. After a collision, the driver removes a regular file at its reserved temporary name and retries exclusive creation once; a leftover that is already gone counts as removed. A non-regular entry is left in place. Rename, temporary creation, or parent fsync can fail on a destination that still opens for writing (for example a file bind mount, an idmapped mount whose mapping excludes the kernel creator IDs, a filesystem lacking directory fsync or rename, an append-only parent directory, or a non-regular entry occupying the reserved temporary name). Add sep_store_replaceable() and sep_store_publishable() to inspect parent directory fsync/rename callbacks, the parent mount, creator ID mapping via fsuidgid_has_mapping(), parent directory permissions, any existing destination via may_delete_dentry() and d_mountpoint(), and any entry at the reserved temporary name (including parent unlink support) without modifying the directory. For an absent destination, the parent's permission and append-only and dead flags are read under its shared inode lock. Rejecting d_mountpoint() catches mounts on the dentry through any alias in this namespace and conservatively refuses mounts present only in another mount namespace; bind-mounting the parent directory itself remains allowed. catacomb::writable() now requires sep_store_replaceable() alongside opening for write; catacomb::publishable() requires sep_store_publishable() and a file that either opens for writing or is provably missing, without reading or checksumming it; enrollment preflight checks publishability for not-yet-existing catacombs; and owner preparation checks MASTER and OWNER publishability before creating the owner placeholder or sending SYSTEM SELECT_CONTEXT, retaining the post-save validation. Later races, I/O errors, or create/unlink/rename filesystem and LSM denials remain possible. Requires aurora-sep-selinux 1.4.0 (aurora-sep 1-14) from the previous commit, which labels the temporary names and lets the kernel set the mode of, rename and unlink state files. The new file takes its owner, ACLs and label from creation, not from the file it replaces. Signed-off-by: Matt <mmdisbro@gmail.com>
Compile the production store_shim.c replacement, mode, publishability and parent-sync functions, the Rust StoreFile wrapper, catacomb::write(), catacomb::writable(), catacomb::publishable(), catacomb::prepare_missing_owner(), SepData::save_catacomb(), SepData::preflight_enrol(), SepData::delete_identity() and SepData::bio_prepare_enrol() against a synthetic per-file VFS and SEP transport. With Rust 1.85.0, 38 Rust cases and 89 C boundary cases (ASan and UBSan) pass. They cover short writes; open, security, chmod, close, rename and fsync failures; the filesystem root; leftover temporary files, including non-regular ones, denied or failing removal, and one that disappears before removal; lock ownership from creation through cleanup; the temporary closed through filp_close() before rename and unlinked through its pinned dentry with no leaked references; mode 0600 published under umasks 0022, 0277 and 0777, with notify_change() only when the umask cleared bits; per-slot replaceability and publishability refusals (bind mounts, symlinks, directories, unmapped creator IDs, parents lacking directory fsync/rename/unlink callbacks, append-only/dead/unwritable parents, read-only mounts, and non-regular or unremovable reserved temporary entries), with the parent's flags read only under its lock; publishability decided without reading an existing catacomb; sep_store_sync_parent() refusals and unwinding; zero delete commands on each modeled static refusal; enrollment preflight distinguishing absent from unwritable optional catacombs; owner preparation refusing before creating a placeholder or selecting a context, and unwinding on a failed parent fsync; and, for the master catacomb, that CONFIRM_SAVE follows a durable replacement and the lockout record is refreshed only after it. The suite also compiles catacomb::write() reverted to truncate-in-place and requires the previous-generation preservation case to fail; 15 cases fail. Signed-off-by: Matt <mmdisbro@gmail.com>
Run the catacomb replacement suite and the SELinux module test in the SEP source checks. Both run under the job's pinned Rust 1.85.0 toolchain. The suite reads rust/kernel/error.rs, so add it to the job's sparse checkout. Signed-off-by: Matt <mmdisbro@gmail.com>
014b29b to
2b6bceb
Compare
catacomb::write()truncates the saved catacomb and rewrites it in place. An error or crash between the truncate and the final sync leaves a short or empty file where the last valid generation was, and the enclave cannot restore it at the next start. Write the complete file under a temporary name, sync and close it, then rename it over the catacomb and sync the parent directory. The driver sendsCONFIRM_SAVEonly after both sync calls succeed. Durability depends on the filesystem and storage honoring those calls.Port of omacom/linux-aurora#250, reworked after review. The original remains open. Three enrollments on combined J313 build
39e8f218d716produced user/master inode changes and empty post-enrollment temporary-file listings. The report did not record rename cookies or listing exit codes. That run used the omacom base, random temporary names, the old filesystem root and no replaceability check, so it does not qualify this series. Hardware reportUpgrade order (§1)
aurora-sep-selinux1-14 (module 1.4.0) must reach hosts before booting a kernel with atomic replacement, because under 1.3.0 temporary files inheritvar_lib_tandkernel_tlacks module-scopedsetattr/rename/unlinkrules onaurora_sep_state_t. Commit 1 (41a02cefc) is split out with zero driver dependencies and opened as standalone precursor PR #2978 soaurora-sep-selinux1-14 can land and ship ahead of this PR. Once #2978 merges, this PR rebases cleanly to commits 2–4.Changes
aurora-sep: selinux: allow catacomb publication by atomic replacement(41a02cefc, standalone precursor aurora-sep: selinux: allow catacomb publication by atomic replacement #2978)aurora_sep.te/.fc: module 1.4.0,aurora_sep_state_tfor the three.apple-sep-catacomb-{master,owner,user}.bin.newnames, andsetattr_file_perms rename_file_perms delete_file_permsforkernel_tonaurora_sep_state_t:file.aurora-sep.spec: bump to1-14with upgrade-order changelog note.test_sep_selinux_state.py: verifies the temporary contexts, transitions, and allow rule without depending onstore_shim.c.soc: apple: sep: publish catacomb files by atomic replacement(47346f3dc)store_shim.c,sep_store_replace(): resolves parent from userspace init's root under kernel credentials, checks parentfsync(-EINVAL) andrename(-EPERM) viastore_dir_capable(), serializes withstore_replace_lock, creates.<name>.newexclusively, retries once after removing a stale regular file (treating-ENOENTfromstart_removing()as already gone), normalizes mode to0600vianotify_change()only when callercurrent_umask()or a default ACL cleared or altered bits, writes all bytes, runsvfs_fsync(temp, 0), pinstemp_dentry = dget(temp->f_path.dentry), and closestempwithfilp_close(temp, NULL)before rename so any close-time->flusherror aborts before publication and leaves the previous generation intact. Non-regular destinations are refused. A failed post-rename parentfsyncreturns an error although the replacement is already visible, soCONFIRM_SAVEis not sent.sep_store_replaceable()andsep_store_publishable()checkstore_dir_capable(),mnt_want_write(),fsuidgid_has_mapping(), destination replaceability understart_removing()(or parentMAY_WRITE|MAY_EXEC,!IS_APPEND,!IS_DEADDIRunderinode_lock_shared(file_inode(dir))when an absent destination is allowed), and any reserved.<name>.newentry without mutating the directory.catacomb.rs:catacomb::writable()requiresshim::replaceable()andopen_writable_existing().catacomb::publishable()checksshim::publishable()plusopen_writable_existing().is_ok() || open_readonly() == Err(ENOENT), avoiding a full-file read,KVecallocation, and CRC16 on existing optional catacombs.prepare_missing_owner()checksshim::publishable()beforeopen_host().test_sep_selinux_state.py: addstest_temporary_names_match_the_drivercross-checking".%s.new", base + 1instore_shim.c.aurora-sep: add host fault tests for catacomb replacement(cc4b5bca3)store_shim.c(store_write_all,store_remove_temp,store_remove_stale,store_dir_capable,store_ensure_mode,store_replace,store_check_reserved,store_check_publish,sep_store_sync_parent), RustStoreFile,catacomb.rs, andSepData::{save_catacomb,preflight_enrol,delete_identity,bio_prepare_enrol}against a synthetic per-file VFS and SEP transport.ci: sep: run the catacomb replacement tests(2b6bcebc8)persistence-tests.py --suite atomicandtest_sep_selinux_state.pyinsep-source.yml, addingrust/kernel/error.rsto the sparse checkout.No storage format, enclave protocol, reader or xART policy changes.
Metadata: creation requests mode
0600under kernel credentials and normalizes back to0600vianotify_change()if the caller's umask stripped bits. Ownership, ACLs and SELinux label follow creation-time rules. Replacement discards the previous inode's metadata.Local host validation (
2b6bcebc8, Rust 1.85.0)sep-source.yml):filp_closeflush failure skippingCONFIRM_SAVE, zero-readcatacomb::publishable()on existing/absent/unwritable/unreadable files, andbio_prepare_enrol()unwinding cleanly beforeSELECT_CONTEXTwhenprepare_missing_owner()fails parentfsync..newvanishing (-ENOENTrace -> retry succeeds),filp_close()before rename (FLRDordering and flush-error preservation), umasks0022/0277/0777+notify_change()failure unwind, lockedIS_APPEND/IS_DEADDIRchecks, andsep_store_sync_parent()parent-fsyncrefusal and unwind (-EINVAL,-EIO,-EACCES,-ENOMEM).catacomb::write()to truncate-in-place fails 15/38 Rust cases.sep-source.yml(including all 4-Oruns) pass in sparse checkouts at Commit 1 (41a02cefc, 14/14 SELinux + 4/4 packaging, zerodrivers/diff), Commit 2 (47346f3dc, 15/15 SELinux), and HEAD (2b6bcebc8).sep-abi_Static_assertcheck passes;store_shim.ocompiles with 0 warnings underW=1against this tree's Linux 7.3 headers (using a throwaway defconfig build outside the repo) with all undefined symbols verified exported (dput,filp_close,notify_change,security_path_rename,security_path_unlink);checkpatch.plreports 0 errors across all 4 commits (0/0/1/0 warnings, only the MAINTAINERS reminder on Commit 3);git diff --checkis clean;git merge-tree --write-tree 2b6bcebc8 471593d0fis clean (9ed76d00d).Exact-head hardware, SELinux Enforcing, and CI matrix
The host suite and policy checks cover mocked paths only. They do not establish live SELinux labels,
CONFIG_APPLE_SEP=mmodule linkage, KUnit, or power-loss recovery on the shipped filesystem.2b6bcebc8aurora-sep-selinux1-14 (#2978) ahead of this kernel changeSEP source checks(source,rust-build, arm64 QEMUkunitapple_sep*,dwc3-atc-compile) andHost testson final headaurora-sep-selinux1-13 state files on disk, installaurora-sep-selinux1-14 (module 1.4.0), boot kernel at final head under SELinux Enforcing, enrol + reboot; verifyls -Z /var/lib/apple-sep-catacomb-*.binisaurora_sep_state_t, clean cold-restore, 0 AVCs, 0 failed units, 0 new kernel errors.apple-sep-catacomb-*.bin.newfiles.newcleaned up and replaced; non-regular.newrefused without touching destination or mutating enclavefsyncrefusal unwind (RyanTheTide)CONFIRM_SAVE, 0 leaked refs/locks/temp files) on parentfsyncrefusalstore_replace,store_check_publish,sep_store_sync_parent,delete_identity,bio_prepare_enrol,save_catacomb); live filesystem row PENDINGFollow-ups
Still truncate-in-place: the keybag slots, and the host failed-attempt record written by
write_lockout_record(). That record is distinct from the enclave lockout blob thatsave_lockout()stores after a master save. The xART guard intentionally empties its one-time allowance.Assisted-by: OpenAI Codex (original change and cross-family review), Claude Code and Gemini (rework, port, and verification)