Firecracker VM Escape: PwnEscape Part 2
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Firecracker VM Escape: PwnEscape Part 2
Firecracker is supposed to keep untrusted code inside a microVM. We escaped it and achieved code execution as root on the host.
Firecracker 的设计初衷是将不受信任的代码限制在 microVM 内部。我们成功逃逸并获得了宿主机上的 root 权限代码执行能力。
We found how it saved registers, changed where it would resume, and made it execute a call of our choosing when it returned from KVM. The guest then restored the temporary stack changes. Firecracker kept running, and the VM remained accessible over SSH.
我们发现了它保存寄存器的方式、修改恢复执行位置的方法,并使其在从 KVM 返回时执行我们指定的调用。随后,客户机恢复了临时的栈更改。Firecracker 继续运行,且虚拟机仍可通过 SSH 访问。
PwnEscape Part 1 introduced the host memory primitive behind this work. Here we follow the next part of the chain: using that access to find Firecracker in memory and take over a live thread from inside the guest. This is a continuation to show CVE-2026-99999 on a Firecracker setup.
PwnEscape 第一部分介绍了这项工作背后的宿主机内存原语。在此,我们继续后续的链式攻击:利用该访问权限在内存中定位 Firecracker,并从客户机内部接管一个活跃线程。这是展示 Firecracker 环境下 CVE-2026-99999 的后续内容。
A Firecracker microVM has a process on the host that manages it. Each virtual CPU, or vCPU, has a thread in that process. The thread enters KVM to run the guest and returns to Firecracker when an event needs handling in userspace. Firecracker documents this arrangement in its architecture overview.
Firecracker microVM 由宿主机上的一个进程进行管理。每个虚拟 CPU(vCPU)在该进程中都有一个对应的线程。该线程进入 KVM 以运行客户机,并在需要处理用户空间事件时返回 Firecracker。Firecracker 在其架构概述中记录了这种安排。
The call that runs the virtual CPU looks like this:
运行虚拟 CPU 的调用如下所示:
While the thread is in that system call, the host kernel holds its saved userspace registers in a structure called pt_regs. These registers describe the Firecracker thread: its instruction pointer says where execution should resume, and its stack pointer says which userspace stack it should use.
当线程处于该系统调用中时,宿主机内核将其保存的用户空间寄存器存放在一个名为 pt_regs 的结构中。这些寄存器描述了 Firecracker 线程:其指令指针指示了执行应恢复的位置,而栈指针则指示了它应使用的用户空间栈。
That made the return from KVM_RUN an attractive target. If we could locate and modify the saved frame, we could choose the code Firecracker executed when the thread returned to userspace. A guest operation that caused such a return would provide the trigger.
这使得从 KVM_RUN 的返回成为了一个极具吸引力的目标。如果我们能定位并修改保存的帧,就能选择线程返回用户空间时 Firecracker 所执行的代码。导致此类返回的客户机操作将提供触发条件。
We already had access to selected host physical memory through a guest mapping. To use it, we needed to identify the Firecracker process, find code we could call in that process, and locate the register frame belonging to its active vCPU thread. The starting point was a page of memory we controlled inside the guest.
我们已经通过客户机映射获得了对部分宿主机物理内存的访问权限。为了利用这一点,我们需要识别 Firecracker 进程,找到该进程中我们可以调用的代码,并定位属于其活跃 vCPU 线程的寄存器帧。起点是我们控制的客户机内部的一页内存。
Figure 1. The guest identifies its Firecracker process, finds the saved registers for a vCPU thread, and redirects the thread when it returns from KVM.
图 1. 客户机识别其 Firecracker 进程,找到 vCPU 线程的保存寄存器,并在其从 KVM 返回时重定向该线程。
The guest and host use different physical address spaces. A page has a guest physical address, or GPA, inside the VM and a host physical address, or HPA, in the machine backing it. On the target, Extended Page Tables (EPT) provide the translation between them.
客户机和宿主机使用不同的物理地址空间。一页内存拥有一个客户机物理地址(GPA,位于虚拟机内部)和一个宿主机物理地址(HPA,位于支撑它的机器上)。在目标系统上,扩展页表(EPT)提供了两者之间的转换。
We placed a recognizable byte pattern, a nonce, in a guest page. The first resolver took that page’s known GPA and its contents as inputs. Together, they gave us an address to translate and a way to check whether the translation reached our page.
我们在客户机的一页内存中放置了一个可识别的字节模式(nonce)。第一个解析器将该页已知的 GPA 及其内容作为输入。两者结合,为我们提供了一个待转换的地址,以及一种检查转换是否到达我们目标页面的方法。
The resolver searched the host physical ranges covered by the memory primitive for candidate EPT roots. An EPT root is the starting point of the translation tables. For each candidate, the resolver followed the entries selected by the guest address until it reached a physical page, then checked that page for the nonce.
解析器在内存原语覆盖的宿主机物理范围内搜索候选的 EPT 根。EPT 根是转换表的起点。对于每个候选者,解析器根据客户机地址选择的条目进行追踪,直到到达物理页,然后检查该页中是否存在 nonce。
The snippets below are explanatory pseudocode with descriptive helper names. They show the data passed between stages and the checks used to connect them.
以下片段是带有描述性辅助名称的解释性伪代码。它们展示了各阶段之间传递的数据以及用于连接它们的检查逻辑。
The nonce check connected a proposed translation to memory we controlled. The broader search produced two candidates; validation of the nested page tables reduced them to one EPT root. Walking that root gave us the host physical address of our guest page.
Nonce 检查将建议的转换与我们控制的内存关联起来。更广泛的搜索产生了两个候选者;通过对嵌套页表的验证,将其缩减为一个 EPT 根。遍历该根节点,我们得到了客户机页面的宿主机物理地址。
We called this result guest_page_hpa and passed it to the next resolver. We now had a recognizable object in host memory. The next task was finding the host process that mapped it.
我们将此结果称为 guest_page_hpa,并将其传递给下一个解析器。现在,我们在宿主机内存中拥有了一个可识别的对象。接下来的任务是找到映射该对象的宿主机进程。
Firecracker maps memory used by the guest into its own address space. That mapping gave us a way to work backward from the guest page to the process.
Firecracker 将客户机使用的内存映射到其自身的地址空间中。这种映射为我们提供了一种从客户机页面反向推导至进程的方法。
Host processes use page tables to translate their virtual addresses into physical memory. The top level is called the page global directory, or PGD. Recovering the appropriate PGD would let us translate addresses inside Firecracker and read its code and stack through the memory primitive.
宿主机进程使用页表将其虚拟地址转换为物理内存。最高层级被称为全局页目录(PGD)。恢复相应的 PGD 将使我们能够转换 Firecracker 内部的地址,并通过内存原语读取其代码和栈。
Our reverse mapper searched the native host page tables for a mapping of guest_page_hpa. A normal page table walk starts with a virtual address and produces a physical address. Here, we looked for a mapping to a physical page we already knew, then recovered the virtual address and page table root associated with it.
我们的反向映射器在宿主机原生页表中搜索 guest_page_hpa 的映射。正常的页表遍历从虚拟地址开始并产生物理地址。在这里,我们寻找指向已知物理页的映射,然后恢复与之关联的虚拟地址和页表根。
The check runs in both directions:
检查双向运行:
This connected the host process’s virtual mapping to the physical page found through EPT. The reverse mapper returned one validated address space. We retained its root as host_pgd and used it to inspect the process.
这连接了宿主机进程的虚拟映射与通过 EPT 找到的物理页。反向映射器返回了一个经过验证的地址空间。我们保留其根节点作为 host_pgd,并用它来检查该进程。
The next resolver looked for the Firecracker executable in those mappings. It identified an ELF image and checked a known byte sequence in Firecracker’s write(2) wrapper. That connected the recovered address space to the binary we were targeting.
下一个解析器在这些映射中寻找 Firecracker 可执行文件。它识别出一个 ELF 镜像,并检查了 Firecracker 的 write(2) 包装器中已知的字节序列。这便将恢复出的地址空间与我们目标二进制文件关联了起来。
ASLR changes where an executable is loaded. The difference between an address in the ELF image and its corresponding runtime address is the load bias. Once the mapper had identified the image, it could recover that bias and use it to locate the code required by the exploit:
ASLR 会改变可执行文件的加载位置。ELF 镜像中的地址与其对应的运行时地址之间的差值即为加载偏移(load bias)。一旦映射器识别出镜像,它就能恢复该偏移量,并利用它定位漏洞利用所需的代码:
The mapper returned the load bias as firecracker_base. With that value and host_pgd, we could locate code in the running process, translate its virtual address to host physical memory, and compare the bytes there with the expected binary.
映射器将加载偏移返回为 firecracker_base。有了该值和 host_pgd,我们就能定位运行中进程的代码,将其虚拟地址转换为宿主机物理内存,并将那里的字节与预期的二进制文件进行比较。
We checked three locations: the write(2) wrapper that would produce our proof, the continuation after the KVM ioctl, and a short xor eax,eax; ret sequence needed to return cleanly. Their purposes become relevant when we construct the return path below.
我们检查了三个位置:将产生我们证明的 write(2) 包装器、KVM ioctl 之后的延续点,以及为了干净返回所需的短序列 xor eax,eax; ret。当我们在下方构建返回路径时,它们的作用将变得至关重要。
At this point, the guest could inspect the Firecracker image and its private mappings. We still needed the saved registers of the thread currently running our VM.
至此,客户机已经能够检查 Firecracker 镜像及其私有映射。我们仍然需要当前运行我们虚拟机的线程所保存的寄存器。
Figure 2. The nonce identifies the guest page in host memory. Its mapping leads to a host page table root, which lets the next resolver locate and validate the Firecracker image.
图 2. Nonce 在宿主机内存中识别出客户机页面。其映射指向一个宿主机页表根,这使得下一个解析器能够定位并验证 Firecracker 镜像。
The frame finder took host_pgd and firecracker_base from the preceding stages. It used them to recognize the host thread’s saved state.
帧查找器从前述阶段获取 host_pgd 和 firecracker_base。它利用这些信息来识别宿主机线程的保存状态。
The mos
(注:原文在此处中断)