Skip to content

About

AGX user-client research toolkit for Apple Silicon M2/M3/M4. Dispatch map, DYLD interpose tracer, unentitled chain replicator, per-chip kext diff.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AGX User-Client Research Toolkit

Reference for AGXDeviceUserClient and IOGPUDeviceUserClient on Apple Silicon (M2/M3/M4). Contains a full selector map, a working chain replicator, DYLD interpose tooling, and a decoded kernel dispatch table.

Built over two days of probing against macOS 26.3 (xnu-12377.91.3) on an M4 Air. Every code path reached here has been triggered empirically or disassembled from the kext.

No exploitable bugs found. The kernel side is tight on every path probed. This repo is the artifact: a starting position for future audits.

Quick facts

Item Value
Target class AGXDeviceUserClient / IOGPUDeviceUserClient
Parent service AGXAccelerator{G15G,G16G,G17G,G17P}
User-client type 0x100005 (the one Metal opens)
Max selector index 0x3b (60 entries)
Trap surface 16 indices. 3 stubs, 1 mystery, 6 used by IOGPU.framework
Kernel API uniform across M2/M3/M4 (verified by kext diff)

Findings

User-client type matters

Type 5 opens but only a restricted subset of selectors respond. Type 0x100005 (what Metal uses) gets the full dispatch. A flag at self[0x103] bit 0 selects between sDeviceMethods and sDeviceMethodsRestricted tables.

Full dispatch table decoded

Every selector 0x00 through 0x3b has a known {fn_ptr, scalar_in_cnt, struct_in_sz, scalar_out_cnt, struct_out_sz}. Selectors 0x0d, 0x13, 0x14 are NULL-slotted. The dispatcher NULL-checks before branching (returns kIOReturnNotFound cleanly). Table lives in __DATA_CONST.__const inside IOGPUFamily.

Submit paths

Two ways in, both locked:

  1. Trap 0 (fast, buffers ≤0x40 bytes). Kernel copies and forwards to GPU firmware. Buffer contents go through firmware-side validation (asynchronous). Kernel-side returns success or BadArgument strictly on shape.

  2. Selector 0x1d (slow). Does umulh for 64-bit overflow check on count * cb_size, then exact comparison of struct_in_sz == count * cb_size, then cb_size == queue.limit. Rejects anything else.

Per-selector notes

  • 0x2e IOCQCreate. Bitfield validation on the two scalar inputs. s0 ∈ {0, 1} accepts, any s0 with bits 31..63 set also accepts, middle values reject with kIOReturnVMError. Not a pointer dereference (tested with scratch pointers and unmapped addresses).

  • 0x31 SubmitIOCommands. Triggered via MTLIOCommandQueue + loadBuffer. 32-byte input struct with a kernel pointer at offset 0x10 (the cb_kptr returned by 0x32 CreateIOCommandBuffer). Mutating that pointer via the DYLD interpose hook causes Metal's waitUntilCompleted to hang forever. DoS primitive for Metal I/O, not memory corruption.

  • 0x38 group_add_resources. First 8 bytes of the struct_in are authenticated as a PAC-signed kernel vtable pointer. User cannot forge a valid PAC. Unreachable from userspace.

  • 0x09 new_resource. 252 out of 354 field mutations were accepted. None leaked into downstream behavior: resources created with bogus input bytes behave identically to the baseline resource when hit with 0x28, 0x29, 0x17.

Chip comparison

Extracted the AGX kext for four chip families:

  • AGXG15G (M2)
  • AGXG16G (M3 / base M4)
  • AGXG17G (M4 Pro/Max)
  • AGXG17P (M4 variant)

All four share identical AGXDeviceUserClient::externalMethod and identical sets of 42 user-client symbols. Chip-specific code lives in internal firmware helpers (register-list generation, event ring drainers). Same user-facing ABI across the family.

Harness layout

Core building blocks

File Purpose
harness/iokit_hook.c DYLD interpose of IOConnectCallMethod, IOServiceOpen, IOConnectTrap4. Dumps all args and structs.
harness/iokit_hook_mutate.c Interpose variant that mutates selector 0x31 struct bytes from env vars.
harness/full_chain.m Replicates Metal's init flow on a fresh unentitled connection.
harness/iocb_full.m Full IOCommandQueue + IOCommandBuffer lifecycle.

Probes by target

harness/
  probe.c              blind selector prober (user-client type discovery)
  metal_bridge.m       Metal-warmed harness
  trap_time.m          trap timing fingerprint
  trap1_probe.m        exhaustive trap 1 (mystery) attempts
  shmem_call.m         ShmemCreate (0x0e) working
  shmem_race.m         destroy/use race (kernel locked tight)
  queue_call.m         QueueCreate (0x07)
  submit_attack.m      trap 0 fast path attacks
  slow_submit_attack.m sel 0x1d slow path mult-overflow attacks
  resource_create.m    sel 0x09 mutation probe
  iosurface_create.m   sel 0x28 CreateIOSurface
  iocq_fuzz.m          sel 0x2e 2D accept landscape
  iocb_full.m          full IOCommandBuffer chain
  iocb_race.m          50k x 2-thread CB lifecycle race (kernel locked)
  fuzz_newresource.m   structure-aware field fuzz on 0x09
  fuzz_chain.m         chained fuzz (mutate create, test downstream)
  null_ptr_sel.m       selectors 0x0d/0x13/0x14 NULL-check validation

Notes and references

notes/
  day1-progress.md     target selection, initial mapping
  day2-progress.md     kernel disasm, fuzzing, chip diff
  selector-map.md      selector to user-space API mapping
findings/
  trap-surface.md      full trap classification
refs/
  linux/               AsahiLinux AGX driver (ABI oracle)
  extracted/           extracted Apple binaries (gitignored)

Reproducing from scratch

# 1. Install ipsw
brew install blacktop/tap/ipsw

# 2. Extract the decompressed kernelcache for your chip.
#    mac15g = M2, mac16g = M3 / base M4, mac17g = M4 Pro/Max
KC=/System/Volumes/Preboot/*/restore/kernelcache.release.mac16g
ipsw kernel dec "$KC" --output refs/extracted

# 3. Extract AGX + IOGPUFamily kexts
ipsw kernel extract refs/extracted/kernelcache.release.mac16g.decompressed \
    com.apple.AGXG16G --output refs/extracted
ipsw kernel extract refs/extracted/kernelcache.release.mac16g.decompressed \
    com.apple.iokit.IOGPUFamily --output refs/extracted

# 4. Build the interpose tool
clang -dynamiclib -framework IOKit -o harness/iokit_hook.dylib harness/iokit_hook.c

# 5. Observe Metal's IOKit traffic
DYLD_INSERT_LIBRARIES=./harness/iokit_hook.dylib <any-Metal-app>

Status

Not actively hunting. Research is complete as a static artifact.

If you pick this up, the next useful frontiers are:

  1. Kernel log visibility via sudo log stream to catch async firmware faults.
  2. Fuzzing through chip-specific code paths on M4 Pro/Max hardware.
  3. The mystery of trap 1: does real kernel work but rejects every input we tried.

About

AGX user-client research toolkit for Apple Silicon M2/M3/M4. Dispatch map, DYLD interpose tracer, unentitled chain replicator, per-chip kext diff.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages