> Windows Syscalls
ntoskrnl.exeT1106T1070

NtFreeUserPhysicalPages

Releases physical pages previously allocated via NtAllocateUserPhysicalPages, returning them to the system page pool.

Prototype

NTSTATUS NtFreeUserPhysicalPages(
  HANDLE     ProcessHandle,
  PULONG_PTR NumberOfPages,
  PULONG_PTR UserPfnArray
);

Arguments

NameTypeDirDescription
ProcessHandleHANDLEinHandle to the process that owns the AWE PFN array. Usually NtCurrentProcess().
NumberOfPagesPULONG_PTRin/outOn input: number of pages to free. On output: number actually freed.
UserPfnArrayPULONG_PTRinArray of opaque PFN identifiers obtained from NtAllocateUserPhysicalPages.

Syscall IDs by Windows version

Windows versionSyscall IDBuild
Win10 15070xDEwin10-1507
Win10 16070xE1win10-1607
Win10 17030xE4win10-1703
Win10 17090xE5win10-1709
Win10 18030xE6win10-1803
Win10 18090xE7win10-1809
Win10 19030xE8win10-1903
Win10 19090xE8win10-1909
Win10 20040xEDwin10-2004
Win10 20H20xEDwin10-20h2
Win10 21H10xEDwin10-21h1
Win10 21H20xEEwin10-21h2
Win10 22H20xEEwin10-22h2
Win11 21H20xF3win11-21h2
Win11 22H20xF4win11-22h2
Win11 23H20xF4win11-23h2
Win11 24H20xF6win11-24h2
Server 20160xE1winserver-2016
Server 20190xE7winserver-2019
Server 20220xF2winserver-2022
Server 20250xF6winserver-2025

Kernel module

ntoskrnl.exeNtFreeUserPhysicalPages

Related APIs

FreeUserPhysicalPagesAllocateUserPhysicalPagesMapUserPhysicalPagesNtAllocateUserPhysicalPagesNtMapUserPhysicalPages

Syscall stub

4C 8B D1                  mov r10, rcx
B8 F6 00 00 00            mov eax, 0xF6
F6 04 25 08 03 FE 7F 01   test byte ptr [0x7FFE0308], 1
75 03                     jne short +3
0F 05                     syscall
C3                        ret
CD 2E                     int 2Eh
C3                        ret

Undocumented notes

The cleanup counterpart to `NtAllocateUserPhysicalPages`. Walks the PFN array, decrements each page's reference count in the system PFN database, and returns the pages to the standby / free list. Pages that are still mapped via `NtMapUserPhysicalPages` are first unmapped from the caller's address-space window. Like its allocator twin, the call requires the process to either currently hold `SeLockMemoryPrivilege` or to have held it at the time of allocation — the kernel records the originating token at allocation time and uses it for ownership checks. Calling `NtFreeUserPhysicalPages` on PFN values that did not come from the same allocator returns `STATUS_INVALID_PARAMETER_3` without touching system state.

Common malware usage

Minimal direct offensive value — it is purely the destructor for an already-rare allocation path. Where it does appear is in **anti-forensics cleanup**: implants that staged shellcode in AWE-backed non-pageable pages (to survive memory-pressure swap captures) call `NtFreeUserPhysicalPages` immediately before the implant exits, so a post-incident `vmcore` or hibernation-file analysis sees no residual non-pageable region tied to the dead process. Also appears in **kernel R/W primitive teardown** chains where the attacker allocates AWE pages to alias kernel memory through a vulnerable driver and then frees them to remove the only persistent forensic trail. Commodity malware essentially never touches it.

Detection opportunities

Mirror of the allocator's signal — pair calls of `NtAllocateUserPhysicalPages` and `NtFreeUserPhysicalPages` from the same non-database-server process are the high-fidelity tell, especially when the lifetime is short (allocate → map → execute → free in the same second). Sysmon Event ID 1 for the parent process combined with kernel ETW `Microsoft-Windows-Kernel-Memory` event 14 (`PfnPageRelease` family) lets you reconstruct the lifecycle. The `SeLockMemoryPrivilege` audit (Event 4673) usually fires only on the allocate path; if you see a freeing process where the audit log has no matching grant, the privilege was already enabled in the parent token — investigate how it got there.

Direct syscall examples

cFree AWE pages and the windowing region

// Pair with the NtAllocateUserPhysicalPages example: tear down the AWE working
// set so that the shellcode-bearing physical pages are returned to the free list
// before the implant exits.
#include <windows.h>

void awe_free(ULONG_PTR* pfn, SIZE_T pages, PVOID windowBase) {
    // First unmap from the window so no live VAD references the PFNs.
    MapUserPhysicalPages(windowBase, pages, NULL);
    VirtualFree(windowBase, 0, MEM_RELEASE);

    ULONG_PTR n = pages;
    FreeUserPhysicalPages(GetCurrentProcess(), &n, pfn);
    // Wrapper resolves to NtFreeUserPhysicalPages internally.
}

asmx64 direct stub (Win11 24H2 / Server 2025, SSN 0xF6)

NtFreeUserPhysicalPages PROC
    mov  r10, rcx
    mov  eax, 0F6h
    syscall
    ret
NtFreeUserPhysicalPages ENDP

MITRE ATT&CK mappings

Last verified: 2026-05-20