Skip to content

Fix the findings of a whole-tree audit: media input checks, storage flushes, DMA isolation, KSM on user4k, SEP and tooling - #2755

Open
Alyx-ML wants to merge 30 commits into
aurora-silicon:integration/aurorafrom
Alyx-ML:aurora/shipshape-audit-fixes
Open

Alyx-ML wants to merge 30 commits into
aurora-silicon:integration/aurorafrom
Alyx-ML:aurora/shipshape-audit-fixes

Conversation

@Alyx-ML

@Alyx-ML Alyx-ML commented Nov 22, 2026

Copy link
Copy Markdown

Branch: aurora/shipshape-audit-fixes, on integration/aurora at 606d37e. 30 commits, one per fix, each with its own message.

Summary

untrusted input → memory safety
├── media: apple: avd
│   ├── HEVC   refuse tile sizes / slice addresses / CTB sizes that do not fit the picture   (heap write)
│   ├── VP9    bound tile rows and columns; refuse headers and tile sizes past the frame
│   ├── AV1    check each tile entry's row and column before indexing the frame's arrays
│   └── H.264  refuse an SPS larger than the OUTPUT format, as HEVC does
├── accel/ane          size shifts in u64; refuse a buffer larger than the IOVA range
├── HID: spi-hid-apple bound reassembled reports to the 2 KiB buffer; no descriptor for mngt (NULL)
├── drm/asahi          finite cmdbuf cap (16 MiB); __GFP_NOWARN on user-sized allocations
└── soc: apple: sep    bio_shim: free the char device by refcount, not after a mutex unlock

data durability
├── nvme: apple   flush_interval defaults to 0: a flush is not acknowledged before it reaches the drive
│                 remove(): run a deferred flush before namespace removal, then disable the work
└── nvme: apple   T6040: NVME_QUIRK_BROKEN_FUA, as T8132/T8140/T8142/T6050

DMA isolation for PCIe-C / USB4 tunnels
├── PCI                  a device below a DT "external-facing" port is untrusted and removable
├── iommu/apple-dart     any untrusted PCI device gets a DMA domain (covers T6050 "pcie-tunnel-N")
├── iommu/apple-dart     a paging attach that fails part way puts the old domain back
├── thunderbolt: apple   iommu_dma_protection only when every tunnel host is translated and external-facing
└── PCI: apple           a re-enabled function keeps its RID-to-SID slot

user4k
├── mm/ksm         PR_SET_MEMORY_MERGE, exec inheritance and the scan skip non-native address spaces
└── Documentation  say what still differs from upstream while user4k is off

SEP, keys, power, tools
├── sep userbag    FDE keys designated under USER_BAG_BASE + uid, not the identity bag; KUnit case
├── sep uAPI       SEP_BIO_REARM docs: the kernel does not use the password
├── sep hwrng      quality 900, not 1024
├── KEYS: trusted  "import" only for a source that opts in (applesep); refuse options SEP cannot apply
├── mfd: macsmc    power-off and restart still send MBSE after a protocol fault; KUnit case
├── macsmc-power   work set up before the notifier; remove() unregisters, then waits
├── aurora-touchid keep the distro polkit stack; --remove deletes only a file it wrote
├── installer      ask for "yes" on /dev/tty before the SEP writes; --yes where there is no terminal
└── ci             new apple-build-kunit.yml: build the Apple drivers (LLVM, Rust 1.96) and 16 KUnit suites

Left out because other PRs already cover them: the GPU timestamp mapping limit (#2531) and the dcp_trace.c removal (#2368). Per-user Touch ID lockout is left to #2050 and #2051; only the rearm documentation is fixed here.

Evidence

No kernel object was built: the authoring host is macOS (GNU make 3.81, no generated headers). The CI workflow in this PR is the first full build and KUnit run. Each fix was checked with a host harness that compiles the changed functions from the tree, mostly under AddressSanitizer and UBSan.

  • HEVC tiles. Before: two tile columns, the first 201 CTBs wide, on a 30-CTB picture write past tile_ids[] (ASan: heap-buffer-overflow in compute_tile_ids). After: refused with -EINVAL. 11 edge cases pass, and 200 000 random layouts compute only in-bounds, permutation-correct scan tables.
  • AV1. tools/asahi/avd-av1-tail-tests.py: 1804 production controls pass.
  • NVMe flush. Before: 99 of 100 flushes completed before reaching the drive in the harness. After: 0 (an opted-in interval behaves as before).
  • spi-hid. Before: a 20 000-byte report overruns the heap. After: dropped; good reports up to 2048 bytes still delivered.
  • splice. 16 896 cases: old and new give the same results; 4224 calls no longer allocate.
  • KSM. 13 checks pass; the same harness fails 7 on the old code.
  • DART attach undo. 11 cases pass; the old code fails 7.
  • RID-to-SID. Before: one slot leaked per re-enable, failing at the 17th (or -EBUSY on SID-indexed ports). After: the slot is reused.
  • FDE designation. Before: uid 1000's FDE key went to the identity bag. After: -(USER_BAG_BASE + uid) for every uid; KUnit fde_uses_the_user_bag.
  • Trusted-key options. 12/12 pass.
  • Touch ID PAM. 13/13 pass; the old script fails 6.
  • Installer. test_sep_writes_always_on.py: 22/22 before, 24/24 after (two new consent tests).
  • checkpatch --strict: no errors or warnings in kernel code. rustfmt shows no new differences.

Not run: the KUnit cases added here (fde_uses_the_user_bag, trusted_source_import, macsmc), and anything on hardware.

Merge Danger

Door: two-way. Each commit stands alone and reverts cleanly. The FDE fix is the one exception: FDE records created before it are under the identity bag and must be created again. The FDE ioctls are a design draft, not a stable ABI.

Blast Radius: wide.

  • Tunnelled PCIe devices now get strict DMA domains and swiotlb bouncing for small unaligned transfers (16 KiB DART pages). Dock throughput should be measured.
  • NVMe flushes now always reach the drive on pre-M4 machines. Expect lower throughput on flush-heavy workloads; flush_interval=1000 restores the old behaviour.
  • When J614s: PCIe-C on the Thunderbolt ports (Studio Display USB, audio, camera) #2069 adds T6040 tunnel nodes, their root ports need external-facing, or the router reports no DMA protection.
  • Media streams whose headers do not fit their own picture now fail with -EINVAL instead of being decoded.
  • The installer asks for a typed "yes". Scripts with no terminal must pass --yes.
  • The SEP trusted-key backend now refuses blobauth=, keyauth= and similar options instead of ignoring them.
  • The 16 MiB max_cmdbuf_size default has not been exercised on G17, G18, M3 or M5.

Still need hardware to confirm, and not changed here: PMP effort after a PMP crash, ANE H16 page recycling and H14 command checks, DART SID-mask sharing and CIO reopen, AMX state in stop paths, and a bcm4377 hang.

🤖 Generated with Claude Code

Alyx-ML and others added 30 commits November 22, 2026 01:10
… the picture

The V4L2 core bounds the HEVC tile counts by the uAPI arrays, but not
the tile sizes, the slice addresses or the CTB size against the picture.
With explicit tile sizes, compute_tiles_non_uniform() sets the last
column to the picture width minus the sum of the others. If userspace
sends sizes larger than the picture, that u16 wraps, the tile boundaries
run past the picture, and compute_tile_ids() writes tile_ids[] far past
the allocation sized for the picture. stream_slices() also indexes the
per-CTB table with slice_segment_addr without a check, a CTB size other
than 16, 32 or 64 gives a shift the code was not written for, and a zero
picture width divides by zero in submit_slice_segment().

Check the CTB size (CtbLog2SizeY 4 to 6), a non-zero picture, that the
tile counts fit the picture, that explicit sizes leave at least one CTB
to the last tile, and that every slice address is inside the picture,
before any table is computed. Fail the frame with -EINVAL otherwise. Bound
the tile position stream_slices() derives from the segment count by the
boundary tables, and allocate the per-CTB tables with kcalloc().

Tested with a host harness that compiles the tile functions from this
file under AddressSanitizer: the audit case (two columns, the first 201
CTBs wide on a 30-CTB picture) writes past tile_ids[] without the check
and is refused with it; legal edge layouts are accepted; 200000 random
layouts compute only in-bounds, permutation-correct scan tables. Not
built as a kernel module or run on hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
The V4L2 core does not check tile_rows_log2 and admits tile_cols_log2 up
to 6, but the scratch buffers here are sized for VP9_MAX_TILE_COLS (16)
columns, the most a 4096-wide frame can have, and VP9 has at most four
tile rows. set_tiles() also computes the tile data size as the payload
minus the header sizes from userspace, which wraps when the headers
claim more than the buffer, and then reads tile size markers past the
frame. A bad tile size only stopped the loop and the frame was still
submitted with fewer tiles than counted.

Refuse tile_rows_log2 above 2 and tile_cols_log2 above
ilog2(VP9_MAX_TILE_COLS) with the other frame checks. In set_tiles(),
refuse headers past the payload, size markers past the remaining data
and tile sizes past the frame, and fail the frame with -EINVAL instead of
submitting a partial one. The failed run is retired like any other run
error, which frees the bank.

Checked by reading: every legal VP9 stream at this driver's 4096x4096
limit stays accepted. Not built as a kernel module or run on hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
set_tiles() indexes the frame's mi_row_starts[], mi_col_starts[],
height_in_sbs_minus_1[] and width_in_sbs_minus_1[] with tile_row and
tile_col from each tile group entry. The V4L2 core does not validate the
entries, so any u32 from userspace reads far past the frame control.

Refuse an entry whose row or column is outside the frame's tile grid in
avd_av1_check_tiles(), which already checks each entry's offset and size.

Tested with tools/asahi/avd-av1-tail-tests.py (macOS needed extra include
and warning flags): 1804 production controls pass. Not built as a kernel
module or run on hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
The H.264 scratch buffers (motion vectors and colour data) and the
capture buffer are sized from the OUTPUT format, but the header pushed
to the engine takes the picture size from the SPS, which is not checked
against that format. A stream whose SPS is larger than the format makes
the engine work on a picture bigger than its buffers. HEVC already
refuses this case in avd_hevc_validate_sps().

Refuse, when a frame runs, an SPS whose macroblock-aligned size is
larger than the OUTPUT format. The V4L2 core rounds the format up to the
16-pixel height and 64-pixel width steps, so a stream whose format was
set from its own size always passes. The check is only at run time, so
setting the SPS before the format still works as before.

Checked by reading: v4l2_apply_frmsize_constraints() rounds up, so the
check cannot refuse a correctly configured stream. That the engine
writes past its buffers for such an SPS was not confirmed on hardware;
this is a defensive check in the safe direction. Not built as a kernel
module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
sep_bio_unregister() and the release of the last open file each decide,
under d->lock, whether they are the last user, and the one that is frees
d right after its own mutex_unlock(). But the other side may still be
inside mutex_unlock(&d->lock): the unlock slow path takes the wait lock
and wakes waiters after the lock has been handed over, and a spinning
waiter can take the mutex, finish, and free d in that window. The
mutex documentation forbids freeing the memory a mutex lives in while
another task may still be in its unlock.

Count one reference for the registration and one per open file, and
drop it after each side's unlock has returned. The side that drops the
last reference frees d, so nobody can still be inside d's mutex then.
misc_deregister() runs before the registration reference is dropped, so
no open can race with the final put.

Checked by reading the open, release, ioctl, poll and unregister paths.
Not built as a kernel module or run on hardware; the race itself is too
narrow to show on this host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
flush_interval defaulted to 1000 ms. Within that window apple_nvme_queue_rq()
completed a REQ_OP_FLUSH at once and sent one flush to the drive when the
window ended. The filesystem was told the data was durable while it was still
in the drive's cache, so a power loss or a crash in that window lost data that
fsync() had reported as safe. Post-M4 controllers were already exempt; every
earlier ANS (the t8015 and t8103 profiles, which the generic apple,nvme-ans2
compatible also selects for T600x and T8112) ran with the deferral on.

Make 0 the default, so every flush reaches the drive before it completes. Keep
the parameter for people who accept the risk, and say in its description that
a non-zero value acknowledges flushes before they reach the drive. Make the
variable static: it was a global symbol named flush_interval.

remove() also cancelled the deferred-flush work before it removed the
namespaces. Removing a namespace flushes its disk, so with the opt-in grace
period a flush could queue the work again; the work then ran on flush_ns after
namespace removal had freed it, and the flush it stood for never ran. Now
remove() clears the grace period first (apple_nvme_delayed_flush() reads it
once with READ_ONCE()), runs any deferred flush while its namespace still
exists, and disables the work after the namespaces are gone.

Verified with a host harness built from the real apple_nvme_delayed_flush()
text, old and new, under ASan and UBSan: with the old default 99 of 100 flushes
sent 10 jiffies apart were completed early; with the new default none are; an
opt-in interval behaves exactly as before; post-M4 never defers; once remove()
clears the interval a flush is issued and no work is queued. The kernel object
was not built here (macOS host), and the change has not been run on hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
T6040 (M4 Pro) is the T8132 controller with a different register layout. Every
other post-M4 ANS profile sets NVME_QUIRK_BROKEN_FUA: T8132 after writes were
lost across a reset on J713, T8140 after an fsynced overwrite reverted after an
abrupt reset, and T8142 and T6050 because FUA was never shown durable there.
T6040 alone trusted FUA.

Set the quirk on T6040 too. The block layer then follows each FUA write with a
flush. This is the safe direction: at worst it costs one extra flush per FUA
write; it cannot lose data that FUA alone would have kept.

Not tested on T6040 hardware; the change is a quirk bit in the profile table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
struct ane_bo keeps its page count in a u32, and ane_iommu_map_pages(),
ane_iommu_map_each() and the unmap paths computed sizes and offsets as
`npages << ane->shift` and `i << ane->shift`. Both sides are 32-bit, so with
16 KiB pages a page count of 2^18 or more wraps. A buffer of 2^18 + 1 pages
reserved a 16 KiB drm_mm node, while the default batch path
(ane_iommu_map_batch(), which already used size_t) mapped all 4 GiB + 16 KiB
from that node's start, over IOVA the allocator could hand to other buffers;
the per-page path mapped page i at the IOVA of a much lower page.
DRM_IOCTL_ANE_BO_INIT accepted any non-zero u64 size from any client that can
open the accel node, and round_up() of a size near U64_MAX wrapped to 0.

Record the size of the range ane->mm hands out (below 4 GiB) at domain init and
return -E2BIG from BO_INIT for a larger buffer, before anything is allocated. A
buffer that cannot be mapped whole is never created, and its page count always
fits the u32. Also do every page-to-IOVA shift in u64, as ane_iommu_map_batch()
already did, so the arithmetic stays right if the limit ever changes.

Verified with a host harness under ASan and UBSan: the old expressions give 0
for a 4 GiB buffer and wrap page offsets past 2^18 pages; with the new check
sizes up to the aperture are accepted with exact page counts and no truncation,
and aperture+1, 4 GiB, U64_MAX and sizes that wrap round_up() return -E2BIG,
for four aperture shapes. The harness models the patched expressions; the
kernel object was not built here, and no ANE hardware was used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
subpage_pipe_buf_retain() runs for every anonymous page spliced into a pipe
with nosteal_pipe_buf_ops (vmsplice). It allocated the reference array first
and only then looked up the page's first 4K quarter. On a native anonymous
page, and on every page while user4k is off, that lookup finds no owner, so the
array was freed again at once. The splice paid a kmalloc and a kfree for
nothing, and a failed allocation returned -ENOMEM for a page that never needed
it.

Look up the first quarter before allocating, and return early when it has no
owner. Release that one reference if the allocation then fails. Pages with
owners get exactly the same references as before.

Verified with a host harness built from the real old and new function text,
under ASan and UBSan, over 16,896 cases (offsets and lengths in 512-byte steps,
all 16 owner patterns of the four quarters, allocation success and failure):
return codes, fragment lists and native page puts match in every case, no slot
reference or allocation leaks, 4,224 calls no longer allocate, and the 4,224
-ENOMEM results on pages without owners are gone. The kernel object was not
built here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
spihid_assemble_message() joins multi-packet input reports in rep->buf, a
SPIHID_MAX_INPUT_REPORT_SIZE (2 KiB) devm_kmalloc() buffer. The first packet's
header sets the total size, and the only check was that offset, length and
remain fit in a u16. A first packet announcing a report of up to 64 KiB was
accepted, and each later packet was copied to rep->buf + offset, so the
packets after the first 2 KiB wrote past the buffer, and the finished report
was then read back at its full length.

Drop a report whose announced size does not fit the buffer, and any packet
that would write past it, with a rate-limited warning. Also drop the partial
report when a later packet disagrees about the total size, so its bytes are
not joined to a different report.

Verified with a host harness built from the real old and new function text
under ASan and UBSan. The old code hits a heap-buffer-overflow (a 246-byte
write just past the 2 KiB buffer) on a 20,000-byte report. The new code
delivers 247, 500, 1000, 2047 and 2048-byte reports unchanged, drops 2049 and
20,000-byte reports, a stray packet at offset 60,000 and a first packet with
remain 65,289, drops a partial report whose total changes, and still delivers a
good report afterwards. The kernel object was not built here, and no keyboard
or trackpad hardware was used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
…ut a buffer

Only the keyboard, trackpad and aux interfaces get a descriptor buffer
at probe; the management interface's hid_desc stays NULL. A HID report
descriptor message addressed to interface 0 is still accepted by
spihid_process_iface_hid_report_desc(), which copies it through that
NULL pointer.

Refuse a descriptor for an interface that has no buffer. Probe only asks
for descriptors of interfaces 1 and up, so a working device is not
affected.

Checked by reading the probe and message paths. Not built or run on
hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
KSM still assumes that a user page is one whole native page.
get_mergeable_page() already refuses a 4K-on-16K address space, and
madvise(MADV_MERGEABLE) fails there with EOPNOTSUPP. Three other ways
in were left open:

- prctl(PR_SET_MEMORY_MERGE) calls ksm_enable_merge_any(), which put
  the mm on the KSM list and marked its VMAs VM_MERGEABLE.
- MMF_VM_MERGE_ANY is in MMF_INIT_LEGACY_MASK, so it survives exec.
  ksm_execve() entered the new mm into KSM even when exec had picked
  a 4K granule for it.
- With the mm on the list, ksmd walked its VMAs and passed its pages
  to the merge code, which write-protects and replaces native PTEs.

Close all three, using the same mm_page_size(mm) != PAGE_SIZE test as
the madvise gate:

- ksm_enable_merge_any() returns -EOPNOTSUPP for such an mm, so
  PR_SET_MEMORY_MERGE fails the same way MADV_MERGEABLE does.
- ksm_execve() clears the inherited MMF_VM_MERGE_ANY and does not
  enter KSM. The exec still succeeds. arch_mm_init_exec() sets the
  granule in __mm_alloc() before mm_init() copies the flags, and
  create_init_stack_vma() calls ksm_execve() later, so the granule is
  known by then. This covers the second mm that bprm_set_page_shift()
  builds as well. PR_GET_MEMORY_MERGE then reports 0, and a native
  program that this process starts later does not inherit the setting.
- ksm_vma_flags() and __ksm_add_vma() never set VM_MERGEABLE for such
  an mm.
- scan_get_next_rmap_item() treats such an mm as having no mergeable
  VMAs. It then frees any rmap items and drops the mm from the KSM list,
  the same path an mm with no VM_MERGEABLE VMAs takes.

Without CONFIG_MM_SUBPAGE, mm_page_size() is the constant PAGE_SIZE and
every new test folds away. With the option built in but user4k off,
every mm is native and the tests are always false.

Verified on a host harness that compiles the real __ksm_should_add_vma,
__ksm_add_vma, ksm_vma_flags, ksm_add_vmas, ksm_enable_merge_any and
ksm_execve from this tree against small stubs. All 13 checks pass. The
same harness fails 7 of them on the code before this change. A build
with the option off passes the native checks. The scanner change was
checked by reading. No kernel was built or booted for this change, and
there is no user4k selftest for KSM yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
user4k.rst said the shared MM code "do[es] not change with the
parameter". That is true, but a reader can take it to mean a kernel
with the option built in and user4k off behaves like upstream. It does
not. The shared code is always built in, and some of it behaves
differently for every process:

- vm_insert_pages() returns EFAULT for a start address that is not
  aligned to the page size (mm/memory.c).
- The fault_around_bytes debugfs file accepts values down to 4K, so
  writing 0 reads back 4096 instead of the native page size.
- generic_access_phys() handles at most one user page per call. Callers
  that loop, such as access_process_vm(), move the same total.
- locked_vm is counted in 4K units (MM_ACCOUNT_SHIFT). Limit checks and
  VmLck give the same results for native address spaces.

List these in user4k.rst, and point to the list from the Kconfig help.

Also say plainly what KSM does for an address space with another
granule: it does not merge its memory. MADV_MERGEABLE and
PR_SET_MEMORY_MERGE fail with EOPNOTSUPP there, and an exec that picks
another granule drops an inherited PR_SET_MEMORY_MERGE setting.

Each listed difference was checked against the code in this tree.
The KSM text matches "mm/ksm: keep address spaces with another user
granule out of KSM".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
…able

The device tree binding says a port marked "external-facing" leads out of the
machine, and drivers/pci/of.c sets external_facing on such a port. Since
commit 3b96b89 ("PCI: Detect and trust built-in Thunderbolt chips") the
PCI core reads that flag only through arch_pci_dev_is_removable(), which
exists for x86 with ACPI. On arm64 it is a stub that returns false, so no
device behind an Apple PCIe-C (USB4 tunnel) root port was ever marked
untrusted or removable. Every such root port in the Apple device trees has
external-facing.

Because of that, a device plugged into a Thunderbolt or USB4 port got the
same IOMMU treatment as internal hardware: whatever default domain the
command line or Kconfig chose (identity with iommu.passthrough=1), lazy TLB
flushing, and no bounce buffering of sub-page buffers. On T6050, whose PCIe-C
DART is not read as a tunnel DART, the DART driver did not force translation
either.

Mark a device untrusted and removable when its upstream bridge is
external-facing and the flag came from the device tree (the bridge has an
of_node). Deeper devices inherit it, as before. The port itself stays
internal, as since commit 99b50be. ACPI systems are unchanged: their
external_facing still goes through arch_pci_dev_is_removable().

With the mark in place the IOMMU core forces a strict DMA domain for these
devices, refuses a driver that asks for identity, disables ATS, and
dma-iommu bounces buffers that do not fill whole IOVA pages through swiotlb.

Verified with a host harness that runs the patched set_pcie_untrusted() and
pci_set_removable() on a modelled DT topology (external-facing root port,
dock bridge, endpoint): both functions below the port are marked, the port
and an internal Wi-Fi function are not, and an ACPI-style external_facing
without a DT node is left alone. The unpatched code marks nothing. A script
that mirrors the device tree checks found external-facing on every enabled
PCIe-C root port in all 138 Apple board trees (80 tunnel references). The
kernel was not built here and no hardware was used. Expected cost: bounce
copies for small, unaligned buffers of tunnelled devices (16 KiB IOVA
granule), worth measuring with a dock and network or NVMe traffic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
The Apple NHI set iommu_dma_protection to true unconditionally. Userspace
(boltd) reads it from the domain's iommu_dma_protection attribute and, when
it is set, trusts the IOMMU to contain PCIe devices and can authorize them
without asking the user. Until the PCI core marked tunnelled devices
untrusted, that claim was not true: devices behind the tunnel could run with
an identity domain.

Check the router's PCIe tunnel in the device tree instead. Every PCIe host
in the tunnel must translate through a DART (iommu-map), and its root ports
must all be external-facing, so the PCI core marks every function below them
untrusted and the IOMMU core keeps them in strict DMA domains. A router with
no PCIe tunnel, or none enabled, gives devices no way to reach memory and
still reports protection, as before. A warning names a tunnel that is not
set up for isolation.

All current Apple trees pass the check, so boltd sees the same value as
before on every supported machine; the value is now backed by the untrusted
marking.

Verified with a script that applies the same rules as
apple_cio_pcie_tunnel_isolated() to all 138 Apple board trees compiled with
the in-tree dtc: all 80 enabled tunnel references (T8103, T8112, T6000-T6022,
T6030, T8132, T6050) qualify, and copies with external-facing or the host's
iommu-map removed are rejected. The kernel object was not built here and no
hardware was used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
apple_dart_def_domain_type() forces a DMA domain for tunnelled PCIe only when
the DART is read as a tunnel DART, which apple_dart_probe() decides from a
"usb4-pcie-tunnel-" container name. The T6050 trees name their containers
"pcie-tunnel-N" on purpose (the fixed 64-stream topology of the older tunnel
DARTs does not apply), and the T6022 fourth-port containers are named
"usb4-pcie-tunnel@1320000000" (no enabled router uses them today). Devices
behind such DARTs fell through to the default type.

Also return IOMMU_DOMAIN_DMA for a PCI device the PCI core marked untrusted
(everything below an external-facing root port). The core already refuses
any other domain for such a device; answering DMA here keeps the driver's
answer and the core's in agreement, so no later identity rule can make the
core refuse to probe the device. The "tunneled" flag and its hardware
handling are unchanged.

Not verified on hardware; the kernel object was not built here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
apple_dart_attach_dev_paging_unguarded() programs each of a device's stream
maps in turn. If the second one failed (a TLB invalidate that times out, a
refused cold ANE stream), the first kept pointing at the new domain's page
tables. Only a managed DART was undone. The IOMMU core does not revert the
device whose attach failed, because it expects that device unchanged, and it
may free the new domain right after. On a first attach there is no old
domain at all. The DART could then walk freed page tables.

On failure, put the old domain back on every stream map the attach touched:
bypass for the identity domain, the old tables for a paging domain of this
driver, and blocked translation otherwise (no old domain, the blocked domain,
a DCP domain) or when restoring fails. Locked streams keep the firmware's
roots; their mirrored entries stay in the domain's stream maps, which
apple_dart_domain_free() retires. A managed DART is still quarantined and its
streams removed, as before.

Verified with a host harness that compiles the patched function unchanged
against mocks of the hardware helpers, under ASan and UBSan: 11 cases
(first attach, identity, blocked, paging and DCP old domains, a failing
restore, locked and managed DARTs, an early failure and a success) leave
each stream on the old domain or blocked, never on the failed one, with
runtime PM balanced. The unpatched function fails 7 of them. The kernel
object was not built here and no hardware was used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
pci_reenable_device() calls the host bridge's enable_device() hook again
without a disable in between. The PCI core does that at a resume, for
drivers that use it, and after a bridge's resources are resized.
apple_pcie_enable_device() then allocated a second RID-to-SID slot for the
same requester ID, and apple_pcie_disable_device() releases only the first
match. Each cycle leaked a slot until the table was full and the next
enable failed with -ENOSPC. On a port whose table is indexed by SID, the
second enable failed at once with -EBUSY, which fails the resume.

Look up the function's own valid entry first and reuse its slot. Managed
(J713 radio) admission is unchanged and still refuses a second enable. The
slot of another function that shares the SID is not reused.

Verified with a host harness that compiles the patched enable and disable
hooks unchanged against mocks of the port registers, under ASan and UBSan:
21 enables of one function take one slot and one disable frees it, an
indexed port re-enables without -EBUSY, two functions sharing a SID keep one
slot each on an allocated table and the second is still refused on an
indexed one, and managed admission still returns -EBUSY. The unpatched hooks
leak a slot per re-enable and fail at the 17th. The kernel object was not
built here and no hardware was used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
…ped paths

Several working code paths and log lines were labelled "TEST" from T6050
bring-up: the T6050 path sleep quirk, the J714s/J716c retimer scan skip, the
10 ms notification timeout under QUIRK_CIO_MACOS_FRAMES (called a
"placeholder"), the PS_PROT readout after a CIO DART wake, and the J714s
PCIe-C sleep diagnostics. The labels suggest temporary code, and the
diagnostics printed at info level on every dock enumeration or sleep.

Describe what each one does instead, rename the PCIe-C diagnostic helpers
from _test_ to _diag_, and print the diagnostics with dev_dbg()/tb_port_dbg()
so they stay available through dynamic debug. No behaviour changes.

The larger set of TEST diagnostics in drivers/thunderbolt/switch.c (the
sleep-entry role and adapter traces) is left for a separate change.

Not built or run here; the change touches comments, names and log levels
only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
SEP_BIO_FDE_CREATE, FDE_SEAL and FDE_UNSEAL designated the key store user
as the raw uid. Every other user-bag ioctl designates USER_BAG_BASE + uid
(bag_designation), which is the bag SEP_BIO_KEYBAG_UNLOCK opens with the
user's password. The FDE work landed in parallel with the offset and was
never moved over.

The result: uid 1000 sealed its disk secret under designated user 1000,
which is the Linux identity bag (trusted keys, the machine ref-key, Touch
ID's catacomb user), not under the bag its password unlocks. Other uids
pointed at a bag that KEYBAG_UNLOCK never opens, so the uAPI promise
"opens it only while the bag of 'uid' is unlocked" did not hold.

Use bag_designation() in parse_fde() and FDE_CREATE. It also brings the
MAX_UID bound, so the separate i32::MAX check goes. Records made before
this change sit under the wrong bag and must be created again; the FDE
ioctls are a design draft, not a stable ABI.

The ref-key doc comment now names the real outer handle.

Verified: a host rustc --test copy of the designation math shows the old
code gave uid 1000 the identity bag's handle and the new code gives the
same handle as KEYBAG_UNLOCK for MIN_UID..MAX_UID, refusing MAX_UID + 1.
A new KUnit case, fde_uses_the_user_bag, asserts the handle is
-(USER_BAG_BASE + uid). The kernel Rust code was not compiled here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
The uAPI comment for SEP_BIO_REARM says the password "is used once to
unwrap the Linux-owned FV re-arm record". That FV unwrap left the re-arm
path some time ago (fv.rs keeps rearm_touchid_fv as dead code).
rearm_after_password() takes the password as _password and never reads
it. The lockout ends through a password verification of the Linux
identity key bag, made with the bag secret the kernel already stores.

So the kernel trusts the caller's own password check. A helper author
reading the header would think the kernel checks the password, and could
skip the check in userspace. Say what happens: the kernel neither checks
nor uses 'secret', the caller must verify the password first, the field
must still be 1..SEP_BIO_REARM_SECRET_MAX bytes with 'reserved' 0, and the
copy is wiped (Rearm's Drop). The Rust doc comments say the same.

No behaviour change. A per-user lockout that checks the password in the
enclave is the subject of upstream PRs aurora-silicon#2050 and aurora-silicon#2051 and is not done
here.

Verified by reading: bio::read_rearm, sbio::rearm_after_password,
sbio::clear_enclave_lockout (keybag::Slot::Identity, SBIO_PROBE_USER_ID)
and the #[allow(dead_code)] note on fv::rearm_touchid_fv.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
Several ioctls size a kernel allocation straight from userspace:

- SUBMIT copies cmdbuf_size bytes (a u32, so up to 4 GiB). Only G15 and
  G16 bound it (4 MiB); every other GPU kept the trait default of
  usize::MAX.
- SUBMIT allocates in_sync_count + out_sync_count sync items before any
  per-GPU check.
- VM_BIND copies stride * num_binds bytes and then reserves num_binds
  prepared operations. Without a GPU batch limit (bind_batch_limit()
  returns None), both are up to u32::MAX.

A request past the page allocator's largest order hits
WARN_ON_ONCE_GFP() in __alloc_pages(). Any user with the render node can
trigger it, and with panic_on_warn it takes the machine down.

Make the default max_cmdbuf_size 16 MiB (four times what G15 and G16
accept), so an oversized SUBMIT fails with E2BIG as it already does there.
Pass __GFP_NOWARN on the other user-sized allocations, so a request that
is too large fails with ENOMEM and no warning. No GPU's accepted range
changes except the command buffer cap. The timestamp mapping limit is
left to upstream PR aurora-silicon#2531.

Verified by reading the call paths (file.rs submit, parse_array,
vm_bind, vm_bind_g17, mmu/bind.rs) and the Kconfig page order (16 K
pages: 32 MiB largest kmalloc). The kernel Rust code was not compiled
here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
The SEP hwrng registers with quality 1024. That tells the hwrng core that
every bit read is fully random, so the core credits all of it to the
kernel's entropy pool. There is no public analysis of the enclave's noise
source or of how its firmware conditions the output before it reaches the
mailbox.

Register with 900, the figure most SoC TRNG drivers declare without a
measurement of their own (omap-rng, stm32-rng, mtk-rng and others). The
device still feeds the pool at the same rate and is still chosen as the
current hwrng when it is the only one. An administrator who trusts the
source can set rng_quality back to 1024 through sysfs.

Verified by reading drivers/char/hw_random/core.c: quality is clamped to
min(default_quality, 1024, quality) at registration and scales the credit
in hwrng_fillfn(). The kernel Rust code was not compiled here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
The "import <hex-key>" command was added for the Apple SEP source, but
the trusted-key core accepts it for every source: TPM, TEE, CAAM, DCP and
PKWM. Upstream has no such command. With it, root can make a TPM- or
TEE-sealed "trusted" key whose plaintext was chosen and seen in
userspace, which breaks what consumers of trusted keys (encrypted keys'
"trusted:" master key, dm-crypt key descriptions) expect: that the
plaintext was made in the kernel.

Add an "importable" flag to struct trusted_key_ops, next to
"migratable", and refuse "import" with -EINVAL unless the active source
sets it. The core records the flag when a source becomes active (built
in or registered at runtime) and clears it when the source withdraws.
The upstream sources leave it at 0, so they behave as upstream again:
"import" is an unknown command for them. The SEP source sets it, as
Documentation/security/keys/apple-sep.rst describes.

A new KUnit case, trusted_source_import, checks that import fails with
-EINVAL and seals nothing for a source without the flag, works for one
with it, and fails again once that source has withdrawn.

Verified: a host copy of the command parse shows "import" refused
without the flag and accepted with it. The kernel C code and the KUnit
case were not compiled or run here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
The SEP trusted-key source ignored everything after the command:
"new 32 blobauth=..." or "load <blob> pcrinfo=..." made or loaded a key
as if the option were absent. A caller who asks for a blob password or a
PCR binding gets a key without that protection and no error. The TPM
source would have applied the option.

Refuse any option after the command with -EINVAL in the shim's seal and
unseal trampolines, before the Rust callback runs. Trailing white space
still passes, so "new 32 " and a blob with a trailing newline work as
before. The in-tree users (tools/aurora-sep/load-driver and the
coordinator runtime check) pass no options.

Verified: a host C harness (clang, ASan and UBSan) that mirrors the
core's strsep() parse gives 0 for "new 32", "new 32 \t\n" and
"load abcd\n", and -EINVAL for blobauth=, keyauth=, pcrinfo= and
migratable= after new, load or import. The kernel code was not compiled
here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
On the T6050 and J714s profiles, the saved-state guard refuses every SMC
command once an unexpected reply sets saved_fault. Nothing clears the fault.
apple_smc_enter_atomic() and apple_smc_write_atomic() used the same guard, so
after a fault the power-off and restart handlers could not send MBSE = off1
or phra. The machine then stayed on, and macsmc-reboot only logged the
failure without its cause.

Only the power-off and restart handlers enter atomic mode, and only the final
MBSE write follows. So apple_smc_enter_atomic() now still enters atomic mode
when the guard refuses commands. It skips the NTAP write and warns.
apple_smc_write_atomic() sends the final command and warns. It stops routing
replies to a saved-state command that is still marked pending, so this
command's reply is taken as this command's. Every other command still goes
through the guard. Atomic mode already refuses them all.

macsmc-reboot now prints the error code. It also says that the next
power-off or restart handler is tried, which the notifier chain does on
NOTIFY_OK.

A KUnit case checks the guard paths. Without a fault, notifications are
turned off before atomic mode. With saved_fault set, atomic mode is still
entered and no command is sent. An ordinary write is still refused with
-EPROTO. drivers/mfd/macsmc.kunitconfig runs these tests and the
macsmc-power ones.

Verified: drivers/mfd/macsmc.kunitconfig resolves on arm64 with the tree's
kconfig (every option kept). The kernel and the KUnit case were not compiled
or run here (macOS host, no arm64 kernel toolchain). The real power-off after
a fault needs a T6050 or J714s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
…it at remove

Probe registered the SMC notifier and then ran INIT_WORK() on critical_work
again. devm_work_autocancel() had already set it up. An SMC critical-battery
event that came in between could have its queued work reset under it.
dbg_log_work was set up only after the notifier. Remove used cancel_work()
and cancel_delayed_work(), which do not wait, and unregistered the notifier
last. The debug work re-arms itself, so it could run, or queue itself again,
after devm had freed the driver state.

Set up both work items before anything can queue them, and drop the second
INIT_WORK(). At remove, unregister the notifier and clear g_power first. Then
disable_delayed_work_sync() the debug work and cancel_work_sync() the
critical work.

Two comments say what stays as it is. Probe does not reset the charge
inhibitors, as b8e84d0 decided. The user's CHLS limit during a
CHLS_HOLD is kept in RAM only, so a hold found at probe has no known limit.
Probe now logs that case.

Verified: read against the workqueue and devm helpers. Not compiled or run
here (macOS host). KUnit for this file has no probe or remove case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
…polkit-1

Without /etc/pam.d/polkit-1, aurora-touchid-setup wrote its own stack:
pam_fprintd, then bare pam_unix lines for auth, account, password and
session. That file overrides the polkit package's stack in /usr/lib/pam.d.
It dropped what system-auth adds, such as pam_faillock and the account
checks. --remove then took out only the fingerprint line, so the bare stack
stayed for good.

Now the script copies /usr/lib/pam.d/polkit-1 when there is one, and adds
only the pam_fprintd line. Otherwise it writes Arch's polkit-1 stack
(include system-auth). The file starts with a marker line. --remove deletes
/etc/pam.d/polkit-1 only when it carries that marker. An admin's own file is
edited back as before and never deleted.

Verified: a host harness runs configure_pam and remove_pam in a fake root
(a GNU sed -i stand-in, sudo off) for three cases. With no polkit-1: the
system-auth stack, then deleted again. With a packaged copy: it is copied,
and a second run adds no second line. With an admin's file: it is kept.
13/13 checks pass. The same harness fails 6 checks on the old script.
shellcheck is not installed here. bash -n passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
The install warns that the SEP driver creates an identity keybag and
writes to the enclave's anti-replay store, and says "press Ctrl-C now".
It then goes straight on. Run as documented, from curl into bash, the
warning scrolls past and there is no moment to stop.

sep_write_notice now asks for "yes" on /dev/tty, since stdin is the
script when piped. With no terminal, the install stops before anything
is installed, unless --yes is given (bash -s -- --yes). The kit's own
--yes after --m3max-kit counts too, and --yes after --reset-touchid or
--m3max-kit stays that command's own. --yes with any other command is
refused. The agent prompt says to pass --yes only once the owner has
agreed in writing. A Mac whose owner blocks apple_sep is still asked
nothing.

The handling of the file an earlier --read-only install wrote is not
changed (aurora-silicon#2591).

Two tests in test_sep_writes_always_on.py cover the new behaviour: a run
with no terminal and no --yes stops with nothing done, and --yes with
--uninstall is refused. The write notice test passes --yes.

Tested: test_sep_writes_always_on.py passes 24/24 (22 before, plus the
two new ones). macOS has bash 3.2, which cannot parse the installer's
extended glob at line 5457 unless extglob is on at parse time, so the
run used a bash wrapper with -O extglob; without it the same 15 tests
fail before and after this change. The answer typed on a real terminal
was not tested here: the sandbox refuses a pseudo-terminal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
CI compiled only apple-sep.o and the DWC3 object. It ran only
sep.kunitconfig and mt7932.kunitconfig. Most Apple drivers and 16 more
kunitconfig files had no CI at all. A change that broke them was only found
on hardware.

The new workflow has two jobs:
- apple-build: arm64 defconfig plus asahi.config with LLVM=1 and Rust 1.96.0
  (the host-tests pin), with the tree's own bindgen. It checks that every
  Apple driver is still in .config, so a driver that drops out cannot pass by
  building nothing. Then it compiles the Apple driver directories and the
  core files the user4k and KSM work touches.
- kunit: one arm64 QEMU run per Apple kunitconfig (ANE boot, transport and
  PM; DCP fabric and topology; asahi; spi-hid; AVD and AVD PM; AVE; ISP;
  JPEG; ProRes; scaler; macsmc; CLPC). fail-fast is off. sep and mt7932 stay
  in their own workflows.

PR aurora-silicon#2697 adds the AVE host harnesses to host-tests. This does not overlap
with it.

Verified: the YAML parses, and every matrix kunitconfig exists. With the
tree's kconfig on the host, each of the 16 kunitconfig files, plus the arm64
QEMU fragment, keeps every option it asks for. defconfig plus asahi.config
gives every option the build job checks. No job was run here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the careful audit; several of these are real bugs. Some blocking points before this can be reviewed for merge:

Packaging

  • All 30 commits carry a Co-Authored-By: Claude ... trailer. Please drop it from the commits and put Assisted-by: LLM (<vendor>:<model>) as the last line of the PR description instead of the "Generated with Claude Code" line.
  • Please split this per subsystem. Each commit already stands alone, and the areas have different owners and risks. A possible split: AVD; ANE; spi-hid; drm/asahi; SEP (bio_shim, userbag FDE, REARM docs, hwrng, trusted keys); nvme; PCI/DART/thunderbolt; mm (ksm, splice, user4k docs); macsmc; tools/aurora-sep; CI.
  • Nothing has been compiled yet, and the new workflow has not run on this branch (no checks reported). The new KUnit cases (fde_uses_the_user_bag, trusted_source_import, macsmc) have not run either. Please post at least an arm64 LLVM=1 build of the touched directories, plus the KUnit results, for each split PR.

Behaviour changes that need their own justification and numbers

  • drivers/nvme/host/apple.c:362: the flush_interval default goes from 1000 to 0. The durability argument holds: apple_nvme_delayed_flush() acks a flush before the drive has flushed. But this is a deliberate perf trade-off on M1/M2/M3 ANS, and the fallback you suggest is a module parameter. Please show fio fsync/sync-write numbers, before and after, on at least one M1, M2 and M3 machine.
  • apple.c:3352: NVME_QUIRK_BROKEN_FUA on T6040 is not backed by any measurement on T6040. It turns every FUA write on M4 Pro into a write plus a flush. Please post an M4 Pro row (FUA write throughput, and why FUA is not durable there). Also, if this really is the T8132 controller, as the comment says, reuse that data instead of copying the quirk list.
  • drivers/pci/probe.c:1742: the fix is correct. Upstream set_pcie_untrusted() only consults the ACPI-only arch_pci_dev_is_removable(), so DT external-facing (drivers/pci/of.c:63) no longer marks anything untrusted. But this is a PCI-core change and should be its own patch. The effect is that every tunnelled PCIe device on every USB4 Mac gets strict invalidation, swiotlb bouncing for sub-granule buffers, and no ATS. Please measure dock NVMe/NIC throughput on at least one M1/M2 machine and one M4 Pro. The apple_dart_def_domain_type() hunk (apple-dart.c:4496) is redundant, because the IOMMU core already forces a DMA domain for untrusted devices. The body says T6040 tunnel nodes arrive with J614s: PCIe-C on the Thunderbolt ports (Studio Display USB, audio, camera) #2069, but t6040-usb4.dtsi:315 already has them, with external-facing.
  • drivers/gpu/drm/asahi/gpu.rs:351: the 16 MiB default cap applies to every GPU except G16 (g16/mod.rs:541), so it is a SUBMIT admission change on G13, G14 and G17. Please run a deqp/CTS smoke on those. The comment's "G15 and G16 accept 4 MiB" does not match the code; only G16 overrides.
  • drivers/soc/apple/userbag.rs:936,1366: moving FDE keys to USER_BAG_BASE + uid matches every other bag_designation() caller, but it orphans existing FDE records. It needs a hardware create/unseal row.
  • drivers/soc/apple/hwrng.rs:29: 900 is not a measurement of this source. Fine as a policy change, but it should be separate and stated as one.
  • tools/aurora-sep/install-aurora-sep.sh:3757: the installer now blocks on a typed "yes" and fails without a tty. That breaks existing non-interactive installs, so it should be its own change. The --yes parsing is also order-dependent: --yes --reset-touchid dies, while --reset-touchid --yes works.
  • drivers/mfd/macsmc.c:368: sending MBSE after a protocol fault is reasonable, but it changes the power-off path, and there is no poweroff/reboot row.

Looks right (still wants hardware rows on the split PRs)

  • The AVD HEVC, VP9, AV1 and H.264 bounds look right, and the new VP9 set_tiles() error path reaches the queue's fail path. A fluster conformance run (HEVC, VP9 and H.264 on an M1/M2 machine; AV1 on M4 Pro or A18 Pro) would show that real streams are not falsely rejected.
  • ANE u64 shifts and the iova_size bound, the spi-hid report bounds and the NULL hid_desc check, the bio_shim.c refcount (the old code could free d while a concurrent release was still inside mutex_unlock()), and the macsmc-power init/teardown order all look correct.
  • 3b4bef8b51 relabels the board-gated sv6t9 and retimer code (pcie-apple-cio.c:236,246, retimer.c:510) as diagnostics but keeps the of_machine_is_compatible() gates. These are not new, but removing them would be better than renaming them.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr 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.

Pre-PR checklist audit (§1–§6) at 312c79da8f4b33532f486a9bdf8a4abf9922936e:

Hard Blockers

  1. §4 Attribution (hard rule): All 30 commits carry Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>. Commits must carry human author/committer identity and a human Signed-off-by: only, with zero AI trailers in commits.
  2. CI UNSTABLE / Zero Compilation / §5 Hardware Evidence:
    • All 4 GitHub Actions workflows on 312c79da8f4b (Apple build and KUnit, MT7932 KUnit, SEP source checks, Host tests) completed with action_required (fork PR workflows never executed), and no CI ran on the fork either.
    • Zero kernel objects have been compiled (LLVM=1 ARCH=arm64), none of the newly added KUnit cases (fde_uses_the_user_bag, trusted_source_import, macsmc_atomic_after_fault_test) have run, and zero hardware tests have run on any Mac.
  3. Scope Cohesion: 30 commits touching 49 files across 11+ unrelated subsystems (AVD, ANE, spi-hid, drm/asahi, NVMe durability, PCI core + DART + USB4/Thunderbolt, mm/ksm + splice + user4k docs, SEP/userbag/hwrng/trusted-keys, macsmc/power/reboot, tools/aurora-sep, and a new 16-suite CI workflow). High-blast-radius behavioral changes are bundled with clear memory-safety fixes. Split by subsystem so each PR can be compiled, reviewed by its subsystem owner, and hardware-verified independently.

Technical & Checklist Findings

  • drivers/nvme/host/apple.c:2926-2929 (residual UAF/re-arm race in apple_nvme_remove() + unmeasured perf change):
    WRITE_ONCE(anv->flush_interval, 0); flush_delayed_work(&anv->flush_dwork); nvme_remove_namespaces(&anv->ctrl); disable_delayed_work_sync(&anv->flush_dwork); still races when flush_interval > 0. nvme_stop_ctrl() does not stop namespace I/O queues (only nvme_remove_namespaces() does), so an in-flight apple_nvme_queue_rq() -> apple_nvme_delayed_flush() that read a non-zero interval before WRITE_ONCE can call kblockd_mod_delayed_work_on() after flush_delayed_work() returns and before nvme_remove_namespaces() frees ns, leaving flush_dwork armed to dereference a freed anv->flush_ns. Separately, flipping flush_interval from 1000 to 0 by default and adding NVME_QUIRK_BROKEN_FUA to apple_nvme_t6040_hw require before/after fio sync/FUA measurements on M1/M2/M3 and M4 Pro.
  • drivers/iommu/apple-dart.c:3552-3555 (incomplete error-path stream-map cleanup):
    When apple_dart_attach_dev_paging_unguarded() fails after apple_dart_domain_add_streams(), apple_dart_attach_paging_undo() restores hardware stream state (or disables DMA) for non-managed DARTs, but line 3554 still gates apple_dart_mod_streams(dart_domain->stream_maps, cfg->stream_maps, false) on cfg->stream_maps[0].dart->managed_sids. For non-managed DARTs, dart_domain->stream_maps retains stale stream entries for hardware now owned by old or blocked.
  • drivers/pci/probe.c:1742-1798 & drivers/iommu/apple-dart.c:4496 (PCI-core scope & redundancy):
    pci_dev_below_of_external_port() is a generic PCI-core change affecting every DT platform and forces strict DMA / swiotlb bouncing / no ATS for all tunneled PCIe devices behind USB4 docks—it needs its own PR with dock NVMe/NIC throughput measurements on M1/M2 and M4 Pro. With pdev->untrusted set, the IOMMU core already forces IOMMU_DOMAIN_DMA, making the to_pci_dev(dev)->untrusted addition in apple_dart_def_domain_type() redundant.
  • §1 Board gating (3b4bef8b51): drivers/pci/controller/pcie-apple-cio.c:236,246 and drivers/thunderbolt/retimer.c:510 relabel TEST diagnostics to dev_dbg but keep of_machine_is_compatible("apple,j714s") / of_machine_is_compatible("apple,j716c") gates in shipped paths.
  • drivers/gpu/drm/asahi/gpu.rs:351: Imposes a 16 MiB max_cmdbuf_size() cap across G13/G14/G15/G17/G18 with no dEQP/CTS smoke runs; the comment inaccurately claims G15 and G16 override to 4 MiB (only drivers/gpu/drm/asahi/g16/mod.rs:541 overrides).
  • drivers/media/platform/apple/avd/avd-h264.c:1020-1027: The HEVC/VP9/AV1/H.264 bounds checks look sound (and v4l2_apply_frmsize_constraints rounds H.264 coded_fmt to 64x16 while avd_h264_validate_sps rejects interlaced), though checking H.264 SPS dimensions only in avd_h264_run() rather than avd_h264_validate_sps() still allows avd_h264_start() to allocate oversized bank->slices before the first frame fails. All four AVD commits need hardware fluster runs (M1/M2 + M4/A18) to confirm no false rejections on valid streams.
  • drivers/soc/apple/userbag.rs & drivers/mfd/macsmc.c: Moving FDE designation to USER_BAG_BASE + uid breaks/orphans existing FDE records and needs a hardware create/unseal test; bypassing apple_smc_saved_guard() in apple_smc_enter_atomic() / apple_smc_write_atomic() alters the shutdown/reboot path and needs hardware poweroff/reboot verification plus the KUnit run.
  • tools/aurora-sep/install-aurora-sep.sh:10961-10975: --yes parsing is order-dependent (--yes --reset-touchid fails with die, whereas --reset-touchid --yes succeeds), and failing without /dev/tty breaks existing non-interactive scripted installs.

Sound Fixes Ready Once Split, Cleaned (§4), Compiled, and Hardware-Verified (§5)

  • avd-hevc.c, avd-vp9.c, avd-av1.c, avd-h264.c input bounds; ane_drv.c u64 shifts + iova_size bound; spi-hid-apple-core.c report buffer bounds + NULL hid_desc check; bio_shim.c refcounted teardown; macsmc-power.c work init/teardown ordering; mm/ksm.c + include/linux/ksm.h + fs/splice.c user4k guards; pcie-apple.c RID-to-SID slot reuse; trusted_core.c + trusted_shim.c importable + option rejection; aurora-touchid-setup packaged polkit-1 preservation.

Assisted-by: LLM (Gemini 4 Neon)

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.

3 participants