Chapter 6: B8G_ARENA_V1 & O(1) Origin Disposal
Chapter 6: B8G_ARENA_V1 & O(1) Origin Disposal
"In Von Neumann runtimes, memory dies one pointer at a time. In Post-Neumann runtimes, memory dies by authority boundary."
1. Historical Contrast: From LKD Slab Caches & V8 GC to Origin Arenas
Classic systems engineering treated allocation and deallocation as symmetric per-object operations. In Robert Love's Linux Kernel Development (3rd Ed.), the kernel's kmalloc / SLAB / SLUB allocators maintain per-CPU object caches and free-lists so individual struct inode or sk_buff objects can be recycled in nanoseconds. Similarly, in the Purple Dragon era of managed runtimes (JVM, V8 Oilpan / Orinoco), garbage collectors trace live object graphs and sweep unreachable cells across generational heaps.
Both models share a fatal assumption: lifetime is a property of an object, not of a security origin. At modern browser scale — where a single tab invokes 18+ third-party C/C++ parsers (ffmpeg, dav1d, pdfium, libwebp, harfbuzz, sqlite, skia) alongside V8 — per-object lifetime tracking creates three compounding failures:
O(N)Teardown Latency: Closing a complex origin triggers cascading C++ destructors, PartitionAlloc bucket scrubs, and V8 tracing sweeps proportional to live object countN.- Cross-Origin Use-After-Free (UAF) Persistence: When a parser frees a buffer back to a process-wide slab or PartitionAlloc bucket, the physical page stays mapped in the same address space. A subsequent origin allocating the same size class inherits the exact virtual address — turning dangling pointers into exploitable cross-origin UAF gadgets.
- Silent Memory Leaks in C Parsers: One missed
free()along an error path inside a 400,000-line codec leaks indefinitely until the renderer process is OOM-killed.
2. The White Dragon Principle: B8G_ARENA_V1 Bump + Atomic Unmap
The White Dragon Book eliminates per-object deallocation across untrusted parser boundaries. Every browser origin (origin_id) receives a dedicated virtual memory region (B8G_ARENA_V1) reserved directly from the OS kernel (VirtualAlloc on Windows, mmap on POSIX) and injected into every zero-header B8G-ABI module via B8gOriginAllocator.
// sections/chromium-build/inmem-linker/b8g_origin_linker.h
#define B8G_DEP_ABI_VERSION 3u
typedef struct B8gOriginAllocator {
void* (*alloc)(void* origin_arena, size_t bytes, size_t align);
void* (*realloc)(void* origin_arena, void* ptr, size_t bytes);
void (*free)(void* origin_arena, void* ptr); // O(1) no-op; reclaimed atomically on dispose
} B8gOriginAllocator;
typedef struct B8gDepModuleV3 {
uint32_t abi_version;
uint32_t dep_id;
const char* name;
const char* cas_sha256;
void* (*init_origin)(void* origin_arena, const B8gOriginAllocator* alloc);
void (*dispose_origin)(void* module_state);
const void* dispatch_table;
} B8gDepModuleV3;
Allocation inside B8gOriginArena::AllocCb is a single aligned pointer bump ((offset + mask) & ~mask) with zero locks, zero free-list traversals, and zero per-object metadata headers. Individual free() calls are deterministic no-ops.
When v8::Context tears down or the tab navigates cross-origin, B8gOriginArena::Dispose() executes in O(1): it invokes module disposers, unloads origin-bound handles, and returns both the W^X trampoline page and the entire data arena directly to the OS kernel via a single VirtualFree(base, 0, MEM_RELEASE) or munmap(base, capacity) call.
void B8gOriginArena::Dispose() {
for (uint32_t i = 0; i < B8G_DEP_MAX; ++i) {
if (loaded_mask & (1u << i)) {
if (dep_disposers[i] && dep_states[i]) dep_disposers[i](dep_states[i]);
loaded_mask &= ~(1u << i);
}
}
if (wx_trampoline_page) { VirtualFree(wx_trampoline_page, 0, MEM_RELEASE); }
if (base) { VirtualFree(base, 0, MEM_RELEASE); }
base = nullptr; capacity = 0; offset = 0;
}
Because the virtual address range is unmapped at the page-table level, any dangling pointer held by a buggy codec immediately traps as an unmapped page fault (SIGSEGV / ACCESS_VIOLATION) rather than silently corrupting a recycled slab belonging to another origin.
3. Verified Hardware Benchmarks (CHROME-INMEM-LINKER-BENCHMARK.md)
On real x86-64 hardware, binding the surviving Chromium KEEP-ALGO third-party decoders (dav1d, libwebp, libjpeg-turbo, pdfium, sqlite, zstd, brotli) to B8G_ARENA_V1 yields deterministic teardown independent of allocation count:
- Single Origin Atomic Wipe:
233 µs(VirtualFree/munmapof arena + W^X trampoline page). - 100 Sequential Tab Lifecycles:
2.01 mstotal wall-clock (~20.1 µsamortized per lifecycle). - Post-Disposal Leaked Bytes:
0 bytes— guaranteed mathematically by kernel page-table release, even if a C parser omits 100% of its internalfree()calls.
4. Architecture Comparison: Von Neumann / LKD / V8 vs. White Dragon
| Dimension | LKD Slab / SLUB (kmalloc) |
V8 Orinoco / Oilpan GC | PartitionAlloc (Chromium) | White Dragon B8G_ARENA_V1 |
|---|---|---|---|---|
| Allocation Cost | Free-list pop + lock/per-CPU | Bump + write barrier | Thread-cache bucket pop | Single aligned pointer bump |
| Deallocation Complexity | O(N) per object kfree() |
O(Live + Dead) trace/sweep |
O(N) + quarantine scrub |
O(1) (VirtualFree/munmap) |
| Origin Teardown Time | Proportional to object count | 5–80 ms major GC pause |
2–15 ms destructor cascade |
233 µs (100 tabs in 2.01 ms) |
| Leaked Bytes on Parser Bug | Permanent until reboot/OOM | Retains cycle/root leaks | Permanent until tab kill | 0 bytes (kernel page release) |
| Cross-Origin UAF Persistence | High (recycled slab address) | Medium (sandboxed heap) | Mitigated via MiraclePtr | Zero (VA range unmapped) |
5. Key Takeaway
Stop asking C/C++ third-party libraries to be polite about free(). Give every security origin its own B8G_ARENA_V1 slab, let parsers bump-allocate at L1 speed, and evaporate the entire virtual address space in 233 µs when the origin dies.