← Back to all chapters

Chapter 07Down the Rabbit Hole: io_uring, or How a Syscall Became a Data Structure

7 min read
rabbit-holelinuxoperating-systemssecurity

Two facts pulled me in, and they seemed to contradict each other.

  • Everyone's adopting it. PostgreSQL 18 ships io_method = io_uring. QEMU has aio=io_uring. TigerBeetle sends every I/O through it.
  • Google turned it off. In June 2023 Google said 60% of kernel exploit submissions to their kCTF bounty hit io_uring, about a million dollars in payouts. They disabled it on ChromeOS and production servers, and blocked it for Android apps.

The answer to both turned out to be the same design decision.

Why the old ways were slow#

A syscall's cost isn't the work you asked for; it's the entry and exit, plus the Spectre/Meltdown mitigations on every crossing.

Old optionProblem
Linux aio (io_submit)Only truly async for O_DIRECT. Buffered I/O "behaves in a synchronous manner". 2+ syscalls per I/O.
epollSays a fd can be read; you still read yourself. Regular files are always "ready", so no help for disk.
Thread pool (libuv)Works, but 2+ context switches even on a page-cache hit.

Jens Axboe tried extending aio twice, then started over. Goal: "no memory copies for either submissions or completion events, and no memory indirections". Merged in Linux 5.1, 2019.

Two trays on a counter#

Picture a cook and a pantry assistant. The cook drops order slips in one tray, rings a bell once, and keeps cooking. Results come back in another tray, tagged with the slip number, in any order.

 your process                               kernel
 ────────────                               ──────

 SQ ring (submission)
 ┌─────┬─────┬─────┬─────┬─────┐
 │ SQE │ SQE │ SQE │     │     │ ──── io_uring_enter ────▶  runs N ops
 └─────┴─────┴─────┴─────┴─────┘      (one syscall)
   64 B: opcode, fd, buf, len, offset, user_data

 CQ ring (completion)
 ┌─────┬─────┬─────┬─────┬─────┐
 │ CQE │ CQE │     │     │     │ ◀─── results, any order ───  kernel
 └─────┴─────┴─────┴─────┴─────┘
   16 B: user_data, res (bytes or -errno), flags
Both rings are mapped into the process and the kernel. user_data is echoed back untouched.
SQESQESQEheadkernel consumes from heretailyou add entries hereSQ ringshared memory3 entries pending.Handing them over = bumpingan index. No copy.
The ring is a circular buffer: the producer advances the tail, the consumer advances the head. Slot count here is illustrative.

One io_uring_enter can submit 64 reads, or 256. With SQPOLL, a kernel thread watches the ring and you skip the call entirely.

One read with liburing (code)

The shape of a single read with liburing, the helper library almost everyone uses. Like the dive's version, I haven't compiled this; it follows the documented call sequence.

struct io_uring ring;
struct io_uring_params p = {0};
p.flags = IORING_SETUP_SINGLE_ISSUER | IORING_SETUP_DEFER_TASKRUN;  // kernel >= 6.1
io_uring_queue_init_params(256, &ring, &p);
 
struct io_uring_sqe *sqe = io_uring_get_sqe(&ring);
io_uring_prep_read(sqe, fd, buf, 4096, 0);   // fd, buffer, len, file offset
sqe->user_data = 42;                         // echoed back in the CQE
 
io_uring_submit_and_wait(&ring, 1);          // one syscall: submit + wait
struct io_uring_cqe *cqe;
io_uring_wait_cqe(&ring, &cqe);
// cqe->res = bytes read or -errno; cqe->user_data == 42
io_uring_cqe_seen(&ring, cqe);

The part the one-liner hides#

"Async I/O through two rings" hides the surprise: most operations aren't async at all. The kernel first tries each one inline, non-blocking, in your thread. Only on -EAGAIN does it fall back.

What happens to one SQE. Click a box.

So "async buffered file I/O" on Linux is a thread pool doing blocking syscalls: libuv's design, moved into the kernel and made cheaper. Truly async paths are O_DIRECT + NOWAIT on NVMe, and sockets via poll.

Jasny et al. Figure 3: the SQ ring feeds requests to the kernel, which completes them inline (2a), parks them in a poll set for non-blocking waits (2b), or hands them to an async worker pool for blocking waits (2c), before posting to the CQ ring.

Figure 3 from Jasny, El-Hindi, Ziegler, Leis and Binnig, "High-Performance DBMSs with io_uring: When and How to Use It", PVLDB 19(9), 2026, arXiv:2512.04859, licensed CC BY 4.0. Cropped and recompressed.

Each path is load-bearing. Drop inline and every cache hit pays a context switch. Drop poll and every blocked socket needs a thread. Drop the pool and a buffered read stalls the submit call, breaking "submitting never blocks".

The one equation#

cost per op = c_s / B + c_o

c_s = cost of one io_uring_enter, c_o = per-op kernel work, B = ops per enter. Batching divides the fixed cost, down to a floor.

cycles/op
 1300 ┤ ●  batch 1
      │  ╲
      │   ╲
      │    ╲
      │     ╲
  250 ┤      ╰──────────●──────────  batch 32+: flat. This floor is c_o.
      └──────────────────────────────▶ batch size B
Jasny et al., no-op requests. Only the two endpoints are measured values; the curve is the shape they describe.

The second equation is Little's law: IOPS = queue depth / latency. A 100 µs NVMe read at 1M IOPS needs ~100 requests in flight. Sync I/O has depth one per thread. A sync POSIX buffer manager did 16.5K txn/s on one thread; a redesigned io_uring one did 376K. The win isn't fewer syscalls; it's concurrency from one thread.

  • Sync POSIX buffer manager16.5K
  • Redesigned io_uring376K
One thread, transactions per second (Jasny et al.).

The naive port gains almost nothing#

Jasny et al. swapped I/O calls for io_uring, changing nothing else:

WorkloadDrop-in swapAfter redesign (on top)
Buffer manager1.06x2.05x
Network shuffle1.10x2.31x
PostgreSQL (same guidelines)+14%

The redesign: batching, fibers, DEFER_TASKRUN (no inter-processor interrupts mid-batch), registered buffers, NVMe passthrough, polling.

Same story elsewhere. The liburing wiki says swapping epoll for io_uring "does not lead to an outcome that fully takes advantage" of it. Alibaba Cloud measured ~10% over epoll at 1,000 connections. libuv turned io_uring on for files in 1.45.0, then switched back to its thread pool in 1.49.0.

Where it breaks: the security bill#

The core idea is turning a syscall into data. That's what makes it fast, and what makes it a second syscall interface security tools can't see.

 app ──▶ io_uring_enter ──▶ seccomp ✓ "allowed"
            │
            └─ SQ ring:  OPENAT  READ  CONNECT  SEND   ◀── never inspected
seccomp filters the syscall, not the opcodes inside the ring.

In 2025 ARMO's "Curing" rootkit ran its C2 and file ops entirely through io_uring. Falco missed it, Tetragon's default policies missed it, Microsoft Defender missed it.

Today's mitigation is mostly "off": the kernel.io_uring_disabled sysctl, and Docker's default seccomp profile blocks it. Google: safe only for trusted components.

The CVEs, and quieter ways to get hurt

The bugs cluster around object lifetime: who owns a buffer or file when the ring, the user mapping and the kernel all hold references.

  • CVE-2021-41073: type confusion; a kernel pointer stored for provided buffers got treated as a user pointer and freed.
  • CVE-2022-2602: race between registered files in flight and the Unix socket garbage collector.
  • CVE-2023-2598: fixed-buffer registration could reach physical pages past the buffer's end; full local privilege escalation.

Quieter footguns:

  • Completions are unordered, so an fsync can complete before the write it covers is issued, unless you link them.
  • In-flight disk I/O usually can't be cancelled. That collides with Rust, where dropping a future cancels it: the kernel may still write into a buffer you think is freed.
  • Worker threads count against RLIMIT_NPROC. Cloudflare saw a ring burn CPU retrying thread creation at that limit.

The question I'm left with#

Can you sandbox io_uring per operation, without turning it off?

Early 2026 proposals add task-level restrictions and a classic-BPF filter so containers can allow some opcodes. But per the dive, it filters per opcode and can't inspect arguments like seccomp. Worse, arguments point into shared memory the app can change anytime: a time-of-check/time-of-use gap. The kernel copies the SQE, but the iovecs it points to are still user memory.

Meanwhile the API grows: zero-copy receive in 6.15, and a series to let BPF run the submit loop in-kernel. More opcodes, more surface. A smarter filter, a per-ring allowlist, or "trusted code only"? Nobody in my sources seems to know.

Sources#

© 2026 Bharat Kaurav. Built with Next.js & Tailwind.

>_ bk@netherwatcheresc to close

Welcome, reader. Type help to see what this shell can do.