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
| Name | Type | Dir | Description |
|---|---|---|---|
| ProcessHandle | HANDLE | in | Handle to the process that owns the AWE PFN array. Usually NtCurrentProcess(). |
| NumberOfPages | PULONG_PTR | in/out | On input: number of pages to free. On output: number actually freed. |
| UserPfnArray | PULONG_PTR | in | Array of opaque PFN identifiers obtained from NtAllocateUserPhysicalPages. |
Syscall IDs by Windows version
| Windows version | Syscall ID | Build |
|---|---|---|
| Win10 1507 | 0xDE | win10-1507 |
| Win10 1607 | 0xE1 | win10-1607 |
| Win10 1703 | 0xE4 | win10-1703 |
| Win10 1709 | 0xE5 | win10-1709 |
| Win10 1803 | 0xE6 | win10-1803 |
| Win10 1809 | 0xE7 | win10-1809 |
| Win10 1903 | 0xE8 | win10-1903 |
| Win10 1909 | 0xE8 | win10-1909 |
| Win10 2004 | 0xED | win10-2004 |
| Win10 20H2 | 0xED | win10-20h2 |
| Win10 21H1 | 0xED | win10-21h1 |
| Win10 21H2 | 0xEE | win10-21h2 |
| Win10 22H2 | 0xEE | win10-22h2 |
| Win11 21H2 | 0xF3 | win11-21h2 |
| Win11 22H2 | 0xF4 | win11-22h2 |
| Win11 23H2 | 0xF4 | win11-23h2 |
| Win11 24H2 | 0xF6 | win11-24h2 |
| Server 2016 | 0xE1 | winserver-2016 |
| Server 2019 | 0xE7 | winserver-2019 |
| Server 2022 | 0xF2 | winserver-2022 |
| Server 2025 | 0xF6 | winserver-2025 |
Kernel module
Related APIs
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 ENDPMITRE ATT&CK mappings
Last verified: 2026-05-20