Abstract
I identified and confirmed a use-after-free vulnerability in the Linux kernel's
vsock loopback transport, present in linux-6.12.79.
The bug lives in virtio_transport_consume_skb_sent() inside
net/vmw_vsock/virtio_transport_common.c and is triggered by a race between the
loopback workqueue and the socket teardown path.
The vulnerability yields a KASAN-silent UAF write primitive — a controlled
subtraction on a size_t field of a kernel object — and a UAF read
that exposes raw kernel text and data pointers from a refcount=0 socket. This research was
conducted using an AI-augmented kernel research pipeline where an AI language
model acted as a continuous technical collaborator across the full research cycle.
Discovery & Initial Hypothesis
Why vsock?
The vmw_vsock subsystem implements virtual socket communication. The loopback
transport — using VMADDR_CID_LOCAL — routes packets through a kernel workqueue
rather than real hardware. This path is less audited than the mainline network stack, manages
socket-owned SKBs carrying a raw back-pointer (skb->sk), and uses a dedicated
workqueue worker that runs asynchronously relative to socket teardown.
Source Navigation
The three files at the center of this bug:
| File | Role |
|---|---|
af_vsock.c | Socket lifecycle, release/destruct path |
vsock_loopback.c | Workqueue, pkt_queue, loopback send |
virtio_transport_common.c | consume_skb_sent, close path, credits |
In vsock_loopback_work(), every SKB dequeued from pkt_queue passes
through virtio_transport_consume_skb_sent(skb, false). This function dereferences
skb->sk with no refcount held on the socket:
/* net/vmw_vsock/virtio_transport_common.c */ void virtio_transport_consume_skb_sent(struct sk_buff *skb, bool consume) { struct sock *s = skb->sk; /* raw pointer — no refcount held */ if (s && skb->len) { struct vsock_sock *vs = vsock_sk(s); struct virtio_vsock_sock *vvs = vs->trans; /* may be freed */ spin_lock_bh(&vvs->tx_lock); /* UAF spin_lock */ vvs->bytes_unsent -= skb->len; /* UAF WRITE */ spin_unlock_bh(&vvs->tx_lock); } }
If the socket is closed while SKBs still sit in the loopback queue, the workqueue will dereference freed memory when it eventually runs. That is the bug.
Vulnerability Deep Dive
struct virtio_vsock_sock — Memory Layout
Allocated via kzalloc(sizeof(*vvs), GFP_KERNEL) in
virtio_transport_do_socket_init(). Size ≈ 80 bytes → kmalloc-96.
| Offset | Field | Type | Notes |
|---|---|---|---|
| +0x00 | rx_lock | spinlock_t | receive lock |
| +0x08 | rx_queue | sk_buff_head | receive queue |
| +0x18 | tx_lock | spinlock_t | protects tx fields |
| +0x20 | bytes_unsent | size_t | UAF write target |
| +0x28 | tx_cnt | u32 | tx packet counter |
| +0x30 | peer_buf_alloc | u32 | peer buffer size |
| +0x40 | vsk | *vsock_sock | back-pointer |
The write primitive lands at vvs+0x20, subtracting
skb->len (controlled via SEND_SIZE, typically 8192).
This is a controlled subtraction on a freed size_t, repeatable once
per in-flight SKB.
The Close Path — What kfree(vvs) Actually Requires
close(fd) → vsock_release() → __vsock_release()vsk->transport->release(vsk) = virtio_transport_release(). Sets SOCK_DEAD flag.virtio_transport_close() — the branching pointpeer_shutdown == SHUTDOWN_MASK → sends RST → returns true → immediate teardown.Slow path: schedules
close_work with VSOCK_CLOSE_TIMEOUT = 8 * HZ. kfree(vvs) deferred 8 seconds.
sock_put(sk) → refcount drop → vsock_sk_destruct()vsock_deassign_transport() → virtio_transport_destruct().kfree(vvs) — slot enters kmalloc-96 free listvsk->trans = NULL set immediately after. cancel_pkt is never called in this path — SKBs in pkt_queue survive untouched.vsock_loopback_cancel_pkt() (which drains pkt_queue via
virtio_transport_purge_skbs()) is only called from
vsock_connect_timeout and vsock_shutdown — never from
__vsock_release(). In-flight SKBs keep their raw skb->sk
pointer through the entire teardown.
The Race Window
/* Timeline confirmed via GDB — single-CPU QEMU */ [user] send(fd, buf, 8192, MSG_DONTWAIT) /* × 6 — SKBs in pkt_queue */ [user] close(fd) /* virtio_transport_close() → schedules 8s work */ /* vvs still ALIVE */ [wq] vsock_loopback_work() runs [wq] consume_skb_sent(skb, false) [wq] s = skb->sk /* UAF READ — refcount=0, sk semi-live */ [wq] vvs = vs->trans /* vvs still live, closing */ [wq] vvs->bytes_unsent -= 8192 /* WRITE on live-but-dying vvs */ [8s] virtio_transport_close_timeout() [8s] kfree(vvs) /* freed HERE, not at close() time */
Confirmation via GDB
Hardware Watchpoint Strategy
I attached GDB to the QEMU kernel via -s -S flags and used conditional
breakpoints to detect the UAF condition: sk->__sk_common.skc_refcnt.refs.counter == 0
at the time consume_skb_sent runs. Hardware watchpoints were then armed on
the identified vvs+0x20.
# GDB script break virtio_transport_consume_skb_sent commands silent set $sk = skb->sk set $ref = ((struct sock*)$sk)->__sk_common.skc_refcnt.refs.counter set $vvs = ((struct vsock_sock*)$sk)->trans set $len = skb->len if $len > 0 && $ref == 0 set $last_uaf_vvs = $vvs printf "*** UAF HIT vvs=%p len=%d ***\n", $vvs, $len printf "offset+0x20 = 0x%lx\n", *(size_t*)((char*)$vvs + 0x20) end continue end break virtio_transport_destruct commands silent set $d = ((struct vsock_sock*)$rdi)->trans if $target_vvs == 0 && $d == $last_uaf_vvs set $target_vvs = $d printf "FREED vvs=%p\n", $target_vvs watch *(size_t*)((char*)$target_vvs + 0x20) end continue end
UAF Write Confirmed
*** UAF HIT vvs=0xffff88800b80a400 len=8192 *** offset+0x20 = 0x2000 ← bytes_unsent BEFORE decrement AFTER write: offset+0x20 = 0x0 ← bytes_unsent -= 8192 confirmed ✓ FREED vvs=0xffff88800b80a400 — watchpoint armed 0xffff88800b80a400: 0xffff888009d16c00 0x0000 ← SLUB freelist ptr 0xffff88800b80a420: 0x0000000000000000 0x0000 ← slot available for reuse
bytes_unsent decremented by exactly skb->len = 8192,
multiple times per connection (once per SKB in flight). KASAN does not trigger because the object
is refcount=0 but not yet kfree'd at write time. After kfree(vvs), the slot's first
8 bytes contain a SLUB freelist pointer — confirming entry into the kmalloc-96 free list.
UAF Read — Kernel Pointer Exposure
At the time consume_skb_sent reads skb->sk, the sock structure
is tearing down at refcount=0. GDB inspection showed live kernel pointers:
sk+0x28: 0xffffffff88dc23e0 ← sk_prot (kernel .text pointer) sk+0x30: 0xffffffff8a40b700 ← sk_net (kernel .data pointer)
If exfiltrated to userspace, these provide a direct KASLR bypass —
sk_prot is a fixed offset from _text.
Spray Landing Confirmed
512 add_key("user", ...) calls with 72-byte payloads (→ kmalloc-96) sprayed
immediately after kfree(vvs). Watchpoint confirmed the marker landing:
Old value = 0 New value = 3501 ← 0xdad marker — spray landed in freed slot ✓ Old value = 3501 New value = 0 ← kvfree_sensitive() zeroes temp payload buffer ✗
Cache alignment confirmed. The problem: kvfree_sensitive() at the end of the
add_key syscall zeroes and frees the temporary payload buffer — not the persistent
user_key_payload. This drove the requirement for a different spray object.
Exploitation Primitives & Constraints
Spray Object Analysis
| Requirement | Reason |
|---|---|
| kmalloc-96 | Must match freed vvs slab cache (size ≈ 80 → kmalloc-96) |
| Not zeroed on alloc/free | Value at +0x20 must survive the UAF write |
| +0x20 readable | UAF write target is fixed — must be able to observe corruption |
| No spinlock hazard at +0x00 | consume_skb_sent calls spin_lock_bh(&vvs->tx_lock) at +0x18; +0x00 must be safe |
| Persists after allocation | spray → workqueue runs → read back = three separate time points |
Candidate Objects
add_key temp buffer — eliminated. kvfree_sensitive() zeroes it at syscall return. Confirmed by GDB watchpoint.
user_key_payload — viable in principle. 18 + datalen bytes total; for kmalloc-96: datalen = 78. Persists in keyring, readable via keyctl(KEYCTL_READ), not zeroed. Problem: the temp payload copy (also kmalloc(78)) competes for the same freed slot.
msg_msg — the canonical cross-cache technique (Popov et al.).
0x30 header + 48 data = 96 → kmalloc-96. msg_msg.next sits at +0x20 — the exact write target. UAF decrement corrupts it to 0 - 8192 = 0xffffffffffffe000. Following this corrupt pointer in msgrcv() yields an OOB kernel read → KASLR bypass.
/* msg_msg layout */ struct msg_msg { struct list_head m_list; /* +0x00 — 16 bytes */ long m_type; /* +0x10 */ size_t m_ts; /* +0x18 */ struct msg_msgseg *next; /* +0x20 ← UAF write lands here */ void *security; /* +0x28 */ }; /* data starts at +0x30 */
Blocker with this kernel: init_on_alloc=0 — freshly allocated
msg_msg objects have stale data at +0x00 (m_list fields). The spinlock acquired via
spin_lock_bh(&vvs->tx_lock) on the reclaimed slot can hang or crash
if m_list.prev is nonzero.
The Ordering Problem
/* DESIRED — cross-cache UAF write */ [1] spray: msg_msg blocked in msgsnd (m_list = 0, allocated) [2] close(fd) → kfree(vvs) IMMEDIATELY (fast path) [3] spray reclaims freed slot [4] workqueue runs → consume_skb_sent → vvs->bytes_unsent -= 8192 → ACTUALLY writes msg_msg.next -= 8192 ← cross-cache confirmed /* ACTUAL — observed every time */ [1] close(fd) → 8s slow path [2] workqueue runs → consume_skb_sent ← write on live vvs [3] [8s later] kfree(vvs) [4] spray → slot reclaimed (write already done, too late)
Fast path catch-22: virtio_transport_close() takes the fast path
only when peer_shutdown == SHUTDOWN_MASK at the time of close(fd).
The peer's shutdown packet arrives via the same loopback workqueue as the data SKBs,
processed in FIFO order. By the time peer_shutdown is set,
consume_skb_sent has already run for all data SKBs. You cannot get
peer_shutdown set without the workqueue running — and the workqueue running
means the write already fired.
-= skb->len) on
vvs->bytes_unsent at vvs+0x20. Fires once per SKB (~6×
per connection). KASAN-silent. Repeatable.Blocked: Cross-cache write requires
kfree(vvs) before workqueue —
not achievable on single-CPU QEMU with current trigger sequence.Strongest path forward: Exfiltrate the UAF-read kernel pointers (
sk_prot, sk_net) to userspace for KASLR bypass without
needing the cross-cache step.
AI-Augmented Research Pipeline
This research was conducted using an AI collaboration pipeline in which a large language model served as a continuous technical co-researcher — from source reading and hypothesis formation through GDB script generation, PoC development, and exploit primitive analysis. I document this methodology because it represents a reproducible approach to kernel vulnerability research that meaningfully changes the speed and depth of analysis.
How the Pipeline Operated
The workflow was entirely human-directed. I controlled all decisions about what to investigate, what to run, and what the evidence meant. The AI operated as a stateful technical assistant with continuous access to source code, GDB output, and PoC results shared iteratively across the session. The model reasoned, proposed, and generated — it never ran code or made independent decisions.
| Task | AI Contribution | Human Role |
|---|---|---|
| Source reading | Traced call graphs across 5 files simultaneously; identified missing cancel_pkt in __vsock_release | Directed subsystem focus |
| Struct layout | Computed field offsets for virtio_vsock_sock, msg_msg, user_key_payload from source | Verified against GDB and /proc/kcore |
| GDB scripts | Generated conditional breakpoints, hardware watchpoints, refcount checks, before/after logging | Executed on live kernel, reported output |
| PoC code | Wrote and refined C exploit across 8+ versions based on GDB feedback | Compiled, ran, reported results |
| Primitive analysis | Identified kvfree_sensitive as the blocker, analyzed fast-path catch-22 from source | Confirmed or refuted each hypothesis empirically |
| Spray objects | Analyzed msg_msg, user_key_payload, pipe_buffer — computed kmalloc size for each | Tested each candidate |
The Iterative Feedback Loop
Each iteration: I share raw GDB output → AI reads it precisely (e.g., identifying that a watchpoint was firing on a different vvs address than the target, meaning the freed slot was reclaimed by a new listener socket rather than the spray) → diagnosis → corrected PoC. The cycle repeated continuously until each hypothesis was either confirmed or definitively ruled out with evidence.
The most significant example: after listener thread interference was identified as stealing
the freed slab slot (new vsock_create_connected() calls reclaiming the address),
the AI proposed a volatile flag to stop the listener — but source tracing revealed
accept() is a blocking syscall that won't check flags. This drove exploration
of the fast-path ordering problem, which ultimately defined the open research challenge.
What the AI Could Not Do
The model could not independently verify kernel addresses, run GDB, or access the target
system. When it proposed recv() before close() as a fast-path
trigger, careful source tracing revealed it cannot work — the workqueue delivers both
data SKBs and the peer shutdown packet in the same run. My empirical GDB
observations were the ground truth throughout. The model's value was in speed of
cross-file analysis, not in replacing empirical validation.
Methodological Takeaways
Using an AI pipeline for kernel research replaces the single-researcher mental model of
a call graph with a model that maintains working context across multiple files in parallel —
reading af_vsock.c, virtio_transport_common.c, and
vsock_loopback.c cross-referencing them on demand. This accelerates hypothesis
generation dramatically. However, the pipeline succeeds precisely because
I maintain epistemic control — every hypothesis is tested
empirically, every GDB output shared in full, and I exercise judgment about
direction. The model is a force multiplier for existing expertise, not a replacement for it.
What I Learned About the Kernel
Socket Lifecycle is Non-Trivial
The gap between close(fd) and kfree(vvs) can be 8 seconds in the
slow path. VSOCK_CLOSE_TIMEOUT = 8 * HZ is a protocol-level timeout. During
this window the socket structure is unreferenced but not freed — a distinct bug class from
classic UAF where the object is freed at syscall return.
SKB Back-Pointers Are Not Reference-Counted
skb->sk is set via skb_set_owner_w() in
virtio_transport_alloc_skb(), which takes a refcount. But in the loopback
path, consume_skb_sent(skb, false) does not consume the SKB — the receiver
does. The refcount is released by sock_wfree (SKB destructor) only when the
SKB is freed by the receiver. The window between socket teardown and SKB freeing is the
entire vulnerability surface.
SLUB Cache Behavior with init_on_alloc=0
With CONFIG_INIT_ON_ALLOC_DEFAULT_ON=n, freshly allocated objects carry stale
data. This eliminates one of the standard Popov-style msg_msg spray assumptions — that
m_list fields are zero immediately post-allocation. Spray object selection must
account for the allocator config.
Single-CPU Workqueue Scheduling
Bounded workqueues (flags=0) run on CFS-scheduled worker threads. On a single-CPU system
after close(fd), the scheduler returns to userspace before selecting the
workqueue worker. sched_yield() explicitly hands control to the worker.
This determinism makes the UAF reliably reproducible but prevents the ordering reversal
needed for cross-cache exploitation.
cancel_pkt as a Missing Safety Net
A minimal fix: call transport->cancel_pkt(vsk) inside
__vsock_release() before transport->release(vsk), ensuring
no SKBs remain in the loopback queue with a back-pointer to the socket being torn down.
Conclusion
I identified, confirmed, and deeply analyzed a use-after-free in the Linux kernel's vsock
loopback transport — virtio_transport_consume_skb_sent() in
net/vmw_vsock/virtio_transport_common.c, present in linux-6.12.79.
The bug yields a KASAN-silent, controlled, repeatable write primitive on a kernel object at a known offset, alongside a UAF read of kernel text and data pointers. The fundamental exploitation challenge — reversing execution ordering so the cross-cache write fires into a spray object rather than a live vvs — is an open problem constrained by single-CPU workqueue scheduling and the absence of a userspace mechanism to defer the loopback workqueue.
The research demonstrates that AI-augmented kernel analysis is a practically viable methodology — capable of identifying, tracing, and characterizing complex multi-file kernel race conditions at depth and speed that significantly exceeds purely manual analysis, provided I maintain empirical control and treat every model hypothesis as a testable claim.
Affected Versions
| Field | Value |
|---|---|
| Kernel | linux-6.12.79 |
| Subsystem | net/vmw_vsock |
| Function | virtio_transport_consume_skb_sent() |
| Files | virtio_transport_common.c, vsock_loopback.c, af_vsock.c |
| Slab cache | kmalloc-96 |
| KASAN | Not triggered |
| Config required | CONFIG_VSOCKETS + CONFIG_VIRTIO_VSOCKETS |