# CVE-2026-84607 — AppleAVE2 State-Consistency Race → Kernel Code Execution

**Component:** com.apple.driver.AppleAVE2 (AVEVideoEncoder kernel driver)  
**Versions:** 905.40.1 (26.6.2, vulnerable) → 905.43.1 (26.7.2, patched)  
**Impact:** Arbitrary code execution with kernel privileges from a sandboxed app  
**Credit:** Ruslan Dautov  
**Apple description:** "A race condition was addressed with improved locking"

> **ATTRIBUTION CORRECTION (2026-11-13):** The AlphaLayerID=255 kernel panic is NOT this CVE.
> 84607's actual fix is a per-frame **eEncType vs sSessionCfg.sEnc.eType state-consistency guard**
> — a race/type-confusion between encoder types. Its trigger shape is mid-session encoder-type
> mutation, not an out-of-range parameter. The bounds-validation patch (which the AlphaLayerID
> panic hits) belongs to the Hcamael-family batch: CVE-2026-112468/9/70/705.
> See `ave2_param_classification.md` for current trigger attribution.

## Binary Diff Summary

| Metric | 26.6.2 | 26.7.2 | Delta |
|--------|--------|--------|-------|
| Binary size | 2,629.5 KB | 2,645.5 KB | +16 KB |
| Strings | 12,290 | 12,387 | +97 |
| Version | 905.40.1 | 905.43.1 | - |
| Build date | Jul 30 2026 | Oct 8 2026 | - |

## Patch Analysis

The 26.7.2 patch adds **extensive input validation** for video encoder parameters received from the IOKit user client (`AppleAVE2UserClient`). These parameters were previously accepted without bounds checking, allowing kernel memory corruption.

### New Validation Functions

1. **`AVE_Client_CheckMCTFInfo`** — Motion Compensated Temporal Filter validation
2. **`AVE_Client_CheckLRMEInfo`** — Low Resolution Motion Estimation validation  
3. **`AVE_HEVC_CheckVPSExtBounds`** — HEVC VPS extension bounds checking

### New Bounds Checks (Previously Unbounded)

#### AVC (H.264) Parameters
- PPS count: `num_slice_groups_minus1 == 0 && num_ref_idx_l0_default_active_minus1 <= 15 && num_ref_idx_l1_default_active_minus1 <= 15`
- SPS: `log2_max_frame_num_minus4 <= 12 && log2_max_pic_order_cnt_lsb_minus4 <= 12`

#### HEVC (H.265) Parameters  
- VPS: `vps_max_sub_layers_minus1 < 7 && vps_num_layer_sets_minus1 < 16 && vps_num_hrd_parameters <= 16 && vps_num_rep_formats_minus1 < 2 && vps_max_layer_id < 63`
- VPS extension: `vps_max_layers_minus1 < 64`, layer/OLS totals bounded
- SPS: `sps_max_sub_layers_minus1 < 7 && num_long_term_ref_pics_sps <= 16`
- PPS: `num_tile_columns_minus1 <= 256 && num_tile_rows_minus1 <= 256 && chroma_qp_offset_list_len_minus1 <= 5 && num_extra_slice_header_bits == 0`
- RPS: `num_short_term_ref_pic_sets < 65 && (num_long_term_sps + num_long_term_pics) <= 16`

#### Encoder Configuration
- Temporal layers: `0 < iNumOfTemporalLayer && (iNumOfTemporalLayer - 1) < 7` (was `0 <= ... <= 7`, off-by-one)
- B-frame count: `0 <= iNumOfFrame[AVE_FrameType_B] && iNumOfFrame[AVE_FrameType_B] <= 3`
- LookAhead frame count: new range check
- Parameter set count: `0 <= iNum && iNum < (1 + min(2, 64) * 10)` = max 21

### Off-by-One Fix
```
OLD: 0 <= iNumOfTemporalLayer && (iNumOfTemporalLayer - 1) <= 7  // allows 0 and 8
NEW: 0 <  iNumOfTemporalLayer && (iNumOfTemporalLayer - 1) <  7  // requires 1-7
```

## Vulnerability Characterization

### Attack Surface
The `AppleAVE2UserClient` IOKit user client is accessible from sandboxed apps via the `VideoToolbox` framework. The user client accepts video encoder commands:
- `AVE_UCCmd_Start` — Start encoding session
- `AVE_UCCmd_Stop` — Stop encoding session
- `AVE_UCCmd_Process` — Submit frame for encoding
- `AVE_UCCmd_Complete` — Complete encoding
- `AVE_UCCmd_Flush` — Flush encoder pipeline
- `AVE_UCCmd_Reset` — Reset encoder state

### Root Cause
User-controlled video codec parameters (SPS, PPS, VPS, RPS from H.264/H.265 bitstreams) are passed from userspace to the kernel driver without validation. These values are used for:
1. **Buffer size calculations** — integer overflow → undersized allocation → heap overflow
2. **Array indexing** — out-of-bounds read/write
3. **Loop iteration counts** — unbounded loops → kernel DoS or memory corruption
4. **DPB (Decoded Picture Buffer) management** — reference frame count used for array sizing

### Exploitation Strategy (on 26.6.2)

1. **Trigger:** Create a `VTCompressionSession` (or `VTDecompressionSession`) via VideoToolbox
2. **Control:** Submit crafted SPS/PPS/VPS with out-of-range values:
   - `num_ref_idx_l0_default_active_minus1 > 15` → OOB array access
   - `log2_max_frame_num_minus4 > 12` → arithmetic overflow
   - `iNumOfTemporalLayer = 8` (off-by-one) → array index OOB
   - `vps_max_layers_minus1 >= 64` → VPS array overflow
   - `num_tile_columns_minus1 > 256` → tile array overflow
3. **Corrupt:** Kernel heap corruption via undersized allocation or OOB write
4. **Escalate:** Standard kernel heap exploitation techniques (zone confusion, fake object)

### Key Advantage
This bug **bypasses the sandbox entirely** — it goes directly from app → kernel without needing a sandbox escape. The VideoToolbox API is available to all apps, including those in the app sandbox.

## IOKit Structure

```
AppleAVE2Driver (IOService)
  └── AppleAVE2UserClient (IOUserClient) 
        ├── AVE_Client_DispatchCmd → ProcessInputCmd_*
        ├── CreateExternalSurfaces / DestroyExternalSurfaces
        ├── DARTMapExternalSurfaces / DARTUnmapExternalSurfaces
        └── Thread pool: GetIdleThreadID / CreateThread / DestroyIdleThreads
```

## Thread Model (Potential Race Component)
The driver manages a work thread pool:
- `m_psaTCmd[iThreadID]` — per-thread command array
- `GetIdleThreadID` / `CreateThread` / `DestroyIdleThreads` / `TaskThreadsIdle`
- Mutex-protected but the race may be between validation and use (TOCTOU)

## DEVICE TEST RESULTS (2026-11-12)

**Device:** iPhone 17 Pro (iPhone18,1), iOS 26.6.2, Kernel 25.6.0  
**UID:** 501, PID 37822, sandboxed app container

### Approach 1: VideoToolbox API — FULL SUCCESS

```
[+] HEVC compression session created (AppleAVE2)
[*] PrepareToEncode: 0
[*] Encoding frame (sends params to AppleAVE2 kernel driver)...
[*] EncodeFrame: 0
[+] Got encoded sample buffer from hardware encoder
[*] CompleteFrames: 0
```

**The entire pipeline is confirmed reachable from sandbox:**
1. `VTCompressionSessionCreate` with `kCMVideoCodecType_HEVC` → success
2. Frame submission → params flow to AppleAVE2 kernel driver
3. Kernel processes frame and returns encoded sample buffer
4. No sandbox intervention at any stage

### Approach 2: Direct IOKit — BLOCKED (expected)

```
[+] Found AppleAVE2 service: 0x1213
[-] IOServiceOpen failed: 0xe00002e2 ((iokit/common) not permitted)
[*] Sandbox may block direct IOKit path. Use VideoToolbox path instead.
```

Direct `IOServiceOpen` to AppleAVE2 is blocked by sandbox. **VideoToolbox is the only viable path** — which is exactly the attack vector for this CVE.

### Implications for Exploitation

1. **Pipeline confirmed:** VideoToolbox → AppleAVE2 kernel driver path works from sandbox
2. **No sandbox escape needed:** VideoToolbox API is sandbox-allowed, params flow straight to kernel
3. **CRITICAL CAVEAT — encoder vs decoder direction:**

AppleAVE2 is an **encoder**. VPS/SPS/PPS are typically the encoder's **output**, not its input. The 97 unchecked parameters must be classified by reachability:

| Class | Description | Settable by app? |
|-------|-------------|------------------|
| **A: Session config** | `iNumOfTemporalLayer` (off-by-one), MCTF/LRME info, encoder-level counts | **YES** — `AVE_Client_Check*` naming confirms client-supplied |
| **B: Bitstream-derived** | `vps_max_layers_minus1`, `num_tile_columns_minus1`, etc. | **MAYBE** — only if encoder derives them from settable properties |
| **C: Decode-only** | Pure decode-side parsing fields | **NO** — unreachable via encode path |

The `AVE_Client_CheckMCTFInfo` and `AVE_Client_CheckLRMEInfo` naming pattern confirms Class A params are client-supplied. `AVE_HEVC_CheckVPSExtBounds` suggests some VPS structure arrives from somewhere — needs property dictionary analysis to determine if app-settable.

**The true exploit surface is Class A + settable Class B, NOT all 97.**

4. **Next required step:** Dump `VTSessionCopySupportedPropertyDictionary` on device to map which properties the app can set, then cross-reference against the 97 unchecked params

### Key Detail: Compression vs Decompression

The PoC used `VTCompressionSessionCreate` (encoding). The driver also accepts decompression via `VTDecompressionSessionCreate`, which may offer different/additional unchecked parameters. Both paths reach AppleAVE2 kernel driver.

## Next Steps (Updated)
1. ~~Test on target device~~ **DONE — pipeline confirmed**
2. **Dump property dictionary on device** — `VTSessionCopySupportedPropertyDictionary` to enumerate all settable properties, types, and ranges
3. **Classify 97 unchecked params into A/B/C** — cross-reference diff validation sites against property dictionary and kext config structs
4. Import both AppleAVE2 kexts into Ghidra — trace which config structs map to which properties
5. Craft malformed values for **Class A + settable Class B only** via `VTSessionSetProperty` + encode
6. Test controlled OOB write — this is the first panic-capable test; have `.ips` log pulling ready
7. Develop heap shaping strategy for A19 MIE-protected kernel allocator
