# Kernel UaF to Root #1: Freeing an Object That’s Still in Use

Misaligned offsets_size in Android Binder's binder_transaction() error path over-decrements a binder_node refcount, freeing it while a queued transaction still points at it.

- Payout: Research
- Severity: high
- Program: Google
- Write-up by: @
- Disclosed: 2026-11-27
- CVE: CVE-2023-20938
- Write-up quality: 8/10
- Original: https://www.eshard.com/blog/kernel-uaf-1-trigger
- Library page: https://bugbountylibrary.com/r/blog%3Aeshard-com-blog-kernel-uaf-1-trigger
- Tags: area:mobile domain:mobile impact:data-leak impact:privesc kind:research platform:research sev:high tech:android tech:linux technique:source-review vuln:dos vuln:memory-corruption vuln:race-condition

**Target:** Android Binder driver (/dev/hwbinder) on Pixel 6, kernel 5.10 arm64
**Root cause:** binder_transaction() jumps to err_bad_offset on a misaligned offsets_size before the object-translation loop runs, so failed_at is 0 and binder_transaction_buffer_release walks the whole buffer, calling binder_dec_node on never-translated BINDER_TYPE_BINDER objects — a decrement with no matching increment.
**Steps:**
1. Server shares a node (binder id 0xBEEF0000, cookie 0x42424242) with Client; Client gets a handle uaf_handle.
2. Client BC_ACQUIREs the handle, then BC_FREE_BUFFERs the delivery buffer so the ref survives but mmap space is reclaimed.
3. Client sends a one-way transaction to uaf_handle, leaving a queued transaction pointing at the node and raising local_strong_refs to 1.
4. Client sends a malformed one-way transaction to srv_handle carrying `fbo.hdr.type = BINDER_TYPE_BINDER; fbo.binder = 0xBEEF0000` with `offs` = 8 bytes of 0x00 + 7 bytes of 0xFF (offsets_size = 15, misaligned).
5. Kernel hits err_bad_offset, failed_at=0, rollback walks whole buffer and calls binder_dec_node on the node, dropping local_strong_refs 1→0.
6. Client BC_RELEASEs the handle; ref.strong→0, internal_strong_refs→0, node freed synchronously via binder_free_node/kfree while the queued transaction still points at it.
7. Server reads its queue (BR_TRANSACTION); kernel copies node->ptr (+0x58) and node->cookie (+0x60) from freed memory into tr->target.ptr and tr->cookie.
**How found:** Code-reading of binder_transaction(): noticed the alignment check on offsets_size jumps to err_bad_offset before the translation loop, and that failed_at (buffer_offset) is still 0, so the ternary in binder_transaction_buffer_release selects the whole-buffer branch and releases objects that were never translated — a dec without inc.
**Exploitation:** Two cooperating attacker-controlled processes (Server owning the node, Client manipulating refcounts) drive the refcount to zero via the error-path over-decrement plus BC_RELEASE, freeing the binder_node while a one-way transaction remains queued. The Server then reads its queue, and the kernel copies ptr/cookie out of the freed kmalloc-128 slot, yielding a stale read of freed memory (initially 0xBEEF0000/0x42424242, later whatever reclaims the slot).
**Escalation:** Series roadmap: leak a live kernel heap address to defeat KASLR, turn the dangling pointer into a constrained unlink write, escalate to arbitrary read, then zero credentials for root. This post only demonstrates the UaF read.
**Insight:** In refcounted IPC drivers, audit error paths that jump past the increment loop but still run the rollback: check whether the 'failed_at' cursor is falsy (0) so cleanup walks the entire buffer, and whether the rollback resolves objects in the target process's table rather than the sender's. Also: keep the owner from reading its queue so has_strong_ref stays 0 and the free is synchronous, preserving the dangling pointer.

## Proof of concept (copied exactly from the original report)

**Malformed transaction with misaligned offsets_size triggering UaF**

```
struct flat_binder_object fbo = { 0 };
fbo.hdr.type = BINDER_TYPE_BINDER;
fbo.binder = 0xBEEF0000; 
/* name the node by the Server's OWN id, not the handle we received (see Inside the binder_node) */

/* 15 bytes: 8 bytes of real offset (0) + 7 bytes of poison */
uint8_t offs[2 * sizeof(uint64_t) - 1];
memset(offs, 0x00, sizeof(uint64_t)); /* offset = 0 */
memset(offs + sizeof(uint64_t), 0xFF, sizeof(uint64_t) - 1); /* poison */

/* addressed to srv_handle (the Server): the rollback resolves fbo.binder in the
 * *target* process's node table, which must be the Server that owns the node.
 * offsets_size = 15 is misaligned -> err_bad_offset -> the rollback above */
binder_transaction(bs, /*one_way=*/true, srv_handle,
 &fbo, sizeof(fbo), offs, sizeof(offs));
```

**One-way transaction leaving dangling pointer queued**

```
/* a one-way transaction targeting the node leaves a pointer to it queued */
binder_transaction(bs, /*one_way=*/true, uaf_handle, NULL, 0, NULL, 0);
```

**Server reads freed node fields via queued transaction**

```
struct binder_transaction_data *tr = binder_read_until(bs, BR_TRANSACTION);
*cookie = tr->cookie; /* bytes at freed-node offset +0x60 */
*target_ptr = tr->target.ptr; /* bytes at freed-node offset +0x58 */
```

