XXNU Source Handbook Download offline version from here
Part 13 · Chapter 13.01

Security mechanisms and policy boundaries

Guide index · Architecture

XNU security is distributed across object ownership, authorization checks, executable validation, and protected execution interfaces. There is no single function that decides whether an operation is allowed. A syscall may first validate its arguments and descriptor, evaluate Unix credentials, invoke MAC policy callbacks, and finally enter a VM or IPC operation with additional checks. Which checks run depends on that operation and the build configuration.

This chapter describes the xnu-12377.121.6 source in this folder. It distinguishes mechanisms implemented here from policy modules, libraries, firmware, and services reached through interfaces. The presence of a callout does not reveal the complete policy implemented by its provider.

Security mechanisms and policy boundaries diagram
Security mechanisms and policy boundaries diagram · Open SVG
Mermaid source
flowchart TD
    U[Syscall / Mach request / executable load] --> O[Resolve referenced kernel objects]
    O --> C[Credentials and kauth checks]
    O --> M[MAC framework callbacks]
    U --> S[Signature registration and trust decisions]
    S --> V[VM page integrity and mapping enforcement]
    C --> A[Operation implementation]
    M --> A
    A --> R[Selected audit record and result]
    O --> E[Exclaves resource and service authorization]
    E --> X[External execution plus XNU upcalls]

The diagram identifies relationships, not a mandatory ordering of checks for every API.

For the storage behind signed-file policy, read code-signature blob storage: RO wrapper allocation, serialized byte ownership, pointer reconstruction, PAC preparation, borrowed/retained access, permitted field writes and cleanup. The UBC/pager companion supplies its enclosing vnode/VM lifetime.

Reading routes

The structure companions follow credential values and writable lifetime state, MAC label slots and ownership, and thread identity in thread_ro. Read them beside the operation chapters below to connect authorization inputs to allocation, protected updates, references, publication and cleanup. Ports and kobject associations supplies the corresponding storage and conversion model for Mach capabilities.

Executable-memory policy connects MAP_JIT admission and protection changes to monitor association, ARM64 faults and SPTM frame types. It distinguishes current permissions, maximum permissions, entry classification and the physical mapping that a later access obtains.

Two operation companions connect identity and execution state: exec identity and inherited state follows credentials, IPC reset and token publication, while ARM64 thread-state conversion follows kernel-selected import policy, pointer authentication, exception/signal replies and final saved-state writes. Message integrity explains the separate kmsg signature and descriptor-pointer mechanisms.

Page Questions answered
Credentials, authorization, and task rights Where does caller identity live? How are immutable credentials replaced? How do kauth and MAC combine results? Why does a PID not itself grant task access?
Credential publication and policy lifetimes How do temporary references, long-term holdings, SMR, retrying publication, kauth listeners, and dynamic MAC policies interact?
Personas and membership resolution How do persona IDs, credentials and membership-query identity differ, how are adoption/drop and caches managed, and where does the external resolver enter?
Task and thread capabilities How are control/read/inspect/name rights acquired and converted? Which policy and flavor checks apply? How do lazy ports, no-senders cleanup, reset and identity tokens retain or invalidate access?
Code signing and platform policy How does a signature become a vnode's cs_blob? What does a VM validation bit mean? Where are AMFI, CoreTrust, trust-cache, and monitor boundaries?
Signature format and structural validation How do SuperBlob/CodeDirectory layouts, code and special hash slots, scatter ranges, algorithms and CDHash fit together? What does the local parser actually check?
Vnode signature attachment and lifetime How do loader and file-control inputs become protected cs_blob state? How do publication, duplicates, generation revalidation, supplemental signatures and teardown work?
Executable signature policy How do exec permissions, initial command-buffer hashes, process flags, launch constraints, detached signatures, library validation and monitor-region association connect?
File-page validation and cached integrity How are file offsets hashed? When are cached masks reused or reset? How do COW, writes, UPLs, optional bitmaps and VM/monitor checks affect executable mappings?
Trust-cache control How do cache type, entitlement and Image4 inputs select a backend? Who retains payloads, how are query results represented, and what changes after loading or unloading?
Code-signing process controls and CSR How do csops commands resolve process identity, query metadata or mutate policy? Which errors follow partial output/state changes, and how does ARM64 boot policy become a CSR check?
Audit records and sessions How are records selected, accumulated, committed, serialized, and delivered? Which thread owns a record at each stage?
Audit pipeline How do selection, commit backpressure, worker batches, rotation, pipe drops, and output errors change record ownership?
Audit-session capabilities How do session IDs, credential/process references, exported ports and send epochs interact across self, join, spawn and teardown?
SPTM, TXM, and Exclaves entry/exit map Which security boundary does each mechanism implement? How do ordinary calls, upcalls, interrupts and protected-domain resumes differ?
SPTM How do bootstrap, frame/table typing, mapping operations, result buffers, epochs and protected entry/exit hooks fit together?
TXM How do the call ABI, protected stacks, signature/trust lifecycle and address-space policy connect to executable mappings?
Exclaves overview and execution How do the trap, per-thread RPC context, hosted scheduler, secure entry, upcalls and interrupt resumption work?
Exclaves resources and memory How do task lifecycle, resource ports, service permissions and physical-page ownership interact?
Exclaves service integration What can storage, sensor, driver, notification, always-on and diagnostic requests ask XNU to do?
Allocator type isolation How do compiler layouts, fixed zone budgets and variable heaps constrain allocation placement? What does free validation actually check?
Read-only zones and restricted mapping categories How are controlled mutation and kernel-private mapping policy connected to allocator classification? Which enforcement is external?

For an initial source walk, follow setuid() through kauth_cred_proc_update(), then read MAC_CHECK, ubc_cs_blob_add(), cs_validate_hash(), and audit_syscall_enter()/audit_commit(). These paths demonstrate identity replacement, policy composition, integrity metadata, and asynchronous accounting without requiring every security hook to be read first.

Main structures and boundaries

Object/interface Responsibility
ucred, proc_ro, thread_ro Immutable identity value, process publication point, and current-thread credential cache
mac_policy_conf, mac_policy_ops, label Registered policy operations and policy-specific label slots
cs_blob and ubc_info Signature coverage, hashes, signer/entitlement information, and attachment to file-backed VM
kaudit_record In-progress audit record, selected destinations, optional user data, and queue linkage
exclaves_resource Named, typed external resource with XNU lifetime and type-specific state
SPTM bootstrap/per-CPU state and frame types Inputs and completion state for protected mapping/retyping operations; detailed structure map
TXM call/stack/shared data Selector arguments, protected call lifetime, typed results and policy state; TXM
Exclaves thread context, SCID and per-core scheduler buffers Separate RPC and scheduling protocols with interrupt-safe execution state; execution

CONFIG_MACF, CONFIG_AUDIT, CONFIG_CSR, CONFIG_CSR_FROM_DT, and CONFIG_EXCLAVES materially change these paths; declarations are in config/MASTER. Code-signing monitor and architecture options introduce additional branches. This chapter is not a statement that every mechanism is active on every product built from XNU.

Sources inspected and limits

Area Depth of this reading Limits
Credentials, personas and kauth Allocation/uniquing and insertion-race cleanup, temporary/long-term references, SMR acquisition/retirement, retrying process publication, thread-cache refresh, setuid, kauth registration/dispatch/removal; persona registry/adoption/drop and process accounting; membership/identity caches and resolver work/result/timeout ownership External directory-service databases and persona policy, every identity-changing syscall and all resolver/invalidation races remain outside the selected traces; ACL algorithms have a separate VFS companion
MAC Deep registry registration/unload and static/dynamic busy protocol, check/grant/perform macros, label ownership/access and build-dependent seal assertion; representative vnode/process/socket/IOKit wrappers Individual platform policy implementations and every hook not available or not audited
Task/thread capabilities PID lookup and acquisition gates, flavor conversion and MIG ownership, task/map reference handoff, lazy read/inspect ports, generation-checked no-senders, IPC disable/reset and identity-token resolution External task-access policy and generated stubs, every entitlement/product variant and concurrent teardown interleaving remain outside the selected traces
Code signing Deep selected SuperBlob/CodeDirectory parsing, hash/coverage selection, loader/fcntl input and blob construction, MAC/monitor ordering, protected publication, duplicate/generation/revalidation/free and supplemental attachment; exec flags/constraints/detached acceptance, mmap/LV and monitor association; per-page hashing/masks/bitmap, write/COW/UPL invalidation and invalid-page outcomes Complete CMS/certificate/provisioning and AMFI policy, protected monitor internals, external daemon/dyld behavior, every format/configuration and race are unavailable or outside the selected trace
Trust and signing controls Typed trust-cache frontend, ordinary/PPL/TXM backend ownership and queries, unload boundaries; csops process identity, command authority, output/mutation and VM effects; ARM64 CSR boot state, checks and consumers Imported TrustCache formats/type-policy tables, AMFI/Image4/monitor verification and boot-policy generation remain external; no runtime or complete configuration/concurrency proof
Audit Syscall entry/exit, record construction/commit/free, worker batching/backpressure, trail write/rotation/failure, pipe selection/drop/read, user-record attachment; session registry and masks, lazy port export/send epochs, join/spawn, process/reference counts, no-senders and END/CLOSE/SMR removal Every BSM token case, all control/session-device commands, external policy decisions and userspace audit daemon behavior are not traced
SPTM Deep bootstrap, entry/exit/resume, physical/table typing, representative mapping/retyping, epoch/result storage, lockdown and external-interface review Monitor implementation and external transition ABI bodies unavailable; full hardware state cannot be inferred
TXM Deep stack/call/error/retry paths, shared data, region ownership, signature/profile/trust operations, address-space/executable policy integration External policy/cryptography and some public-header structure omissions remain boundaries
Exclaves Deep trap/proxy/hosted scheduler and interrupt paths; resource/port/task lifetimes; page donation/shared mapping; representative service and diagnostic handoffs Secure scheduler/services, FrameMint implementation, generated transport and all provider/race combinations unavailable or not exhaustively audited

Follow process lifecycle for exec and credentials, executable loading for Mach-O parsing, VFS authorization for pathname permissions, VM for page faults, IPC for ports and rights, networking for socket policy, drivers for user clients, and platform for protected memory and boot mechanisms.

Search the handbook

Search every chapter, interface and code excerpt.

    Diagram

    Source preview

    Open full file