# Refcount imbalance frees live object

Release path decrements a refcount on an object another holder still references, via fd reuse, mid-call free, or error-path over-release

_Area: Memory corruption and native code. Seen in 3 disclosed reports; one confirmed bounty: $10,000; latest 2026-11-27. Updated 2026-11-28._

## How it works

An object is reference-counted: each holder takes a reference (increment) and releases one (decrement), and the object is freed only when the count reaches zero. The bug is a decrement that is not paired with a matching increment, or a release that targets the wrong object. The count hits zero while a real holder still points at the object, so it is freed underneath that holder — a use-after-free. Three ways the pairing breaks: matching a stored object by a reusable identifier (fd) instead of its pointer [E1](https://bugbountylibrary.com/r/h1%3A3320669.md); freeing an actor mid-call and then touching it [E2](https://bugbountylibrary.com/r/p0%3ACVE-2020-6820.md); and an error path that runs rollback over objects that were never incremented [E3](https://bugbountylibrary.com/r/blog%3Aeshard-com-blog-kernel-uaf-1-trigger.md).

## Where it shows up

- Kernel/IPC code that stores a user-supplied fd and later matches on that fd to release a reference [E1](https://bugbountylibrary.com/r/h1%3A3320669.md)
- Cleanup/rollback functions that walk a buffer or list using a cursor (`failed_at`, `buffer_offset`) that can still be zero/falsy [E3](https://bugbountylibrary.com/r/blog%3Aeshard-com-blog-kernel-uaf-1-trigger.md)
- Error jumps that skip the increment/translation loop but still fall into the release path [E3](https://bugbountylibrary.com/r/blog%3Aeshard-com-blog-kernel-uaf-1-trigger.md)
- Actor/stream close paths where `Send__delete`/`Shutdown` can free an object and the caller then reads a field (`mId`) [E2](https://bugbountylibrary.com/r/p0%3ACVE-2020-6820.md)
- `CloseAll`/`NoteClosed`/`Shutdown` ordering in IPDL or similar generated IPC layers [E2](https://bugbountylibrary.com/r/p0%3ACVE-2020-6820.md)

## How to review

For every decrement/free, find the matching increment and prove they act on the same object identity. The invariant: a release must reference the exact object that was acquired, and no path may decrement an object that was not incremented on that same path. Check: does the release match by pointer or by a reusable key (fd, id)? Can the cleanup cursor be falsy so rollback covers untranslated entries? Does any call free an object and then dereference it in the same function? Trace each error branch to confirm it does not run release logic over entries the loop never processed.

## How finders spotted it

- Read the handler and noticed `clear_queue` compared `ne->socket_fd != socket_fd` (fd, not pointer) and unconditionally `fdrop()`ed, while the set path took a `getsock_cap` reference — fd reuse breaks the pairing [E1](https://bugbountylibrary.com/r/h1%3A3320669.md)
- Noticed the alignment check on `offsets_size` jumps to `err_bad_offset` before the translation loop, leaving `failed_at` at 0, so the ternary selects the whole-buffer branch and releases never-translated objects — a dec without inc [E3](https://bugbountylibrary.com/r/blog%3Aeshard-com-blog-kernel-uaf-1-trigger.md)
- Root-cause analysis of an in-the-wild zero-day, hypothesizing manual audit/variant analysis of a similar prior patch or fuzzing of IPDL interfaces [E2](https://bugbountylibrary.com/r/p0%3ACVE-2020-6820.md)

## Variants seen

- fd-keyed release causing double `fdrop` and UaF in a kernel syscall [E1](https://bugbountylibrary.com/r/h1%3A3320669.md)
- Mid-call free of an IPC actor then field access in the browser process [E2](https://bugbountylibrary.com/r/p0%3ACVE-2020-6820.md)
- Error-path over-release of a refcounted node in an IPC driver [E3](https://bugbountylibrary.com/r/blog%3Aeshard-com-blog-kernel-uaf-1-trigger.md)

## Impact and severity

All three yield kernel- or browser-process use-after-free. E1 escalates via repeated `fcntl(F_SETFL)` on the stale fd to a controllable UaF for kernel code execution [E1](https://bugbountylibrary.com/r/h1%3A3320669.md). E2 was chained with a renderer compromise (CVE-2020-6819) to escape the sandbox in a real zero-day [E2](https://bugbountylibrary.com/r/p0%3ACVE-2020-6820.md). E3 is the first step of a roadmap to KASLR defeat, arbitrary read, and root [E3](https://bugbountylibrary.com/r/blog%3Aeshard-com-blog-kernel-uaf-1-trigger.md). Severity is raised by chaining with a second weakness and by the freed object being reachable for reallocation.

## Seen in real software
Open-source packages and projects, and products, where this pattern was found. If the target runs one, compare the version it runs with the fix.
- **Android Binder driver** (binder_transaction / binder_transaction_buffer_release) (version not stated): Kernel UaF to Root #1: Freeing an Object That’s Still in Use (CVE-2023-20938). Report: https://bugbountylibrary.com/r/blog%3Aeshard-com-blog-kernel-uaf-1-trigger.md

## Evidence
- E1: https://bugbountylibrary.com/r/h1%3A3320669.md
- E2: https://bugbountylibrary.com/r/p0%3ACVE-2020-6820.md
- E3: https://bugbountylibrary.com/r/blog%3Aeshard-com-blog-kernel-uaf-1-trigger.md
