Repository navigation
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
Conversation
… 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>
Contributor
|
Thanks for the careful audit; several of these are real bugs. Some blocking points before this can be reviewed for merge: Packaging
Behaviour changes that need their own justification and numbers
Looks right (still wants hardware rows on the split PRs)
Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
requested changes
Nov 22, 2026
DjDeveloperr
left a comment
Contributor
There was a problem hiding this comment.
Pre-PR checklist audit (§1–§6) at 312c79da8f4b33532f486a9bdf8a4abf9922936e:
Hard Blockers
- §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 humanSigned-off-by:only, with zero AI trailers in commits. - 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 withaction_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.
- All 4 GitHub Actions workflows on
- 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 inapple_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 whenflush_interval > 0.nvme_stop_ctrl()does not stop namespace I/O queues (onlynvme_remove_namespaces()does), so an in-flightapple_nvme_queue_rq()->apple_nvme_delayed_flush()that read a non-zerointervalbeforeWRITE_ONCEcan callkblockd_mod_delayed_work_on()afterflush_delayed_work()returns and beforenvme_remove_namespaces()freesns, leavingflush_dworkarmed to dereference a freedanv->flush_ns. Separately, flippingflush_intervalfrom1000to0by default and addingNVME_QUIRK_BROKEN_FUAtoapple_nvme_t6040_hwrequire before/afterfiosync/FUA measurements on M1/M2/M3 and M4 Pro.drivers/iommu/apple-dart.c:3552-3555(incomplete error-path stream-map cleanup):
Whenapple_dart_attach_dev_paging_unguarded()fails afterapple_dart_domain_add_streams(),apple_dart_attach_paging_undo()restores hardware stream state (or disables DMA) for non-managed DARTs, but line 3554 still gatesapple_dart_mod_streams(dart_domain->stream_maps, cfg->stream_maps, false)oncfg->stream_maps[0].dart->managed_sids. For non-managed DARTs,dart_domain->stream_mapsretains stale stream entries for hardware now owned byoldor 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. Withpdev->untrustedset, the IOMMU core already forcesIOMMU_DOMAIN_DMA, making theto_pci_dev(dev)->untrustedaddition inapple_dart_def_domain_type()redundant.- §1 Board gating (
3b4bef8b51):drivers/pci/controller/pcie-apple-cio.c:236,246anddrivers/thunderbolt/retimer.c:510relabelTESTdiagnostics todev_dbgbut keepof_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 MiBmax_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 (onlydrivers/gpu/drm/asahi/g16/mod.rs:541overrides).drivers/media/platform/apple/avd/avd-h264.c:1020-1027: The HEVC/VP9/AV1/H.264 bounds checks look sound (andv4l2_apply_frmsize_constraintsrounds H.264coded_fmtto 64x16 whileavd_h264_validate_spsrejects interlaced), though checking H.264 SPS dimensions only inavd_h264_run()rather thanavd_h264_validate_sps()still allowsavd_h264_start()to allocate oversizedbank->slicesbefore 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 toUSER_BAG_BASE + uidbreaks/orphans existing FDE records and needs a hardware create/unseal test; bypassingapple_smc_saved_guard()inapple_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:--yesparsing is order-dependent (--yes --reset-touchidfails withdie, whereas--reset-touchid --yessucceeds), and failing without/dev/ttybreaks 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.cinput bounds;ane_drv.cu64 shifts +iova_sizebound;spi-hid-apple-core.creport buffer bounds + NULLhid_desccheck;bio_shim.crefcounted teardown;macsmc-power.cwork init/teardown ordering;mm/ksm.c+include/linux/ksm.h+fs/splice.cuser4k guards;pcie-apple.cRID-to-SID slot reuse;trusted_core.c+trusted_shim.cimportable+ option rejection;aurora-touchid-setuppackaged polkit-1 preservation.
Assisted-by: LLM (Gemini 4 Neon)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch:
aurora/shipshape-audit-fixes, onintegration/auroraat 606d37e. 30 commits, one per fix, each with its own message.Summary
Left out because other PRs already cover them: the GPU timestamp mapping limit (#2531) and the
dcp_trace.cremoval (#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.
tile_ids[](ASan: heap-buffer-overflow incompute_tile_ids). After: refused with -EINVAL. 11 edge cases pass, and 200 000 random layouts compute only in-bounds, permutation-correct scan tables.tools/asahi/avd-av1-tail-tests.py: 1804 production controls pass.-(USER_BAG_BASE + uid)for every uid; KUnitfde_uses_the_user_bag.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.
flush_interval=1000restores the old behaviour.external-facing, or the router reports no DMA protection.--yes.blobauth=,keyauth=and similar options instead of ignoring them.max_cmdbuf_sizedefault 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