NtAlpcDeleteSecurityContext
Frees an ALPC SECURITY_QOS context previously created with NtAlpcCreateSecurityContext.
Prototype
NTSTATUS NtAlpcDeleteSecurityContext( HANDLE PortHandle, ULONG Flags, ALPC_HANDLE ContextHandle );
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| PortHandle | HANDLE | in | Handle to the ALPC port that owns the security context. |
| Flags | ULONG | in | Reserved. Must be 0. |
| ContextHandle | ALPC_HANDLE | in | Opaque ALPC_HANDLE returned by NtAlpcCreateSecurityContext; identifies the QoS context to release. |
Syscall IDs by Windows version
| Windows version | Syscall ID | Build |
|---|---|---|
| Win10 1507 | 0x7F | win10-1507 |
| Win10 1607 | 0x7F | win10-1607 |
| Win10 1703 | 0x80 | win10-1703 |
| Win10 1709 | 0x80 | win10-1709 |
| Win10 1803 | 0x81 | win10-1803 |
| Win10 1809 | 0x81 | win10-1809 |
| Win10 1903 | 0x81 | win10-1903 |
| Win10 1909 | 0x81 | win10-1909 |
| Win10 2004 | 0x83 | win10-2004 |
| Win10 20H2 | 0x83 | win10-20h2 |
| Win10 21H1 | 0x83 | win10-21h1 |
| Win10 21H2 | 0x83 | win10-21h2 |
| Win10 22H2 | 0x83 | win10-22h2 |
| Win11 21H2 | 0x83 | win11-21h2 |
| Win11 22H2 | 0x83 | win11-22h2 |
| Win11 23H2 | 0x83 | win11-23h2 |
| Win11 24H2 | 0x85 | win11-24h2 |
| Server 2016 | 0x7F | winserver-2016 |
| Server 2019 | 0x81 | winserver-2019 |
| Server 2022 | 0x83 | winserver-2022 |
| Server 2025 | 0x85 | winserver-2025 |
Kernel module
Related APIs
Syscall stub
4C 8B D1 mov r10, rcx B8 85 00 00 00 mov eax, 0x85 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
ALPC supports a *cached* `SECURITY_QUALITY_OF_SERVICE` model: a client (or server) calls `NtAlpcCreateSecurityContext` once to materialise a QoS context with a frozen client token, then references that context by `ALPC_HANDLE` in subsequent `NtAlpcImpersonateClientOfPort` calls instead of re-snapshotting the token every time. `NtAlpcDeleteSecurityContext` releases the context permanently — the snapshot token is dereferenced, the per-port context table slot is freed, and any in-flight impersonation referencing the context will start receiving `STATUS_INVALID_HANDLE`. This is paired with `NtAlpcRevokeSecurityContext`, which keeps the context entry but invalidates it; deletion is the destructor.
Common malware usage
Defensive housekeeping primitive — limited offensive interest. The only realistic abuse is a **race-condition use-after-free** where an attacker forces a server to delete a security context while another thread on the same port is mid-impersonation. The kernel ref-counts the underlying QoS object, so a clean UAF is hard to construct, but a few historic ALPC port bugs (`AlpcpCleanupPort`, ca. 2017-2019) involved improper ordering between `NtAlpcDeleteSecurityContext` and concurrent send/receive — fixed in cumulative updates. Offensively, the call may also be used by ALPC fuzzers to verify that a server's per-context state is properly torn down (a leak detector).
Detection opportunities
Not a useful detection signal in isolation — every long-lived ALPC server (RPCSS, LSASS, spoolsv, sihost) calls it routinely as connections come and go. The only worthwhile signal is *anomalous order*: deletion followed shortly by a server crash, or deletion preceded by an unusual burst of `NtAlpcImpersonateClientOfPort` against the same context handle — both suggest someone is poking at a TOCTOU. Defenders should focus on the lifetime correlation in ETW rather than on this syscall directly.
Direct syscall examples
cCached-QoS cleanup
// Server tears down a cached impersonation context once a client disconnects.
#include <windows.h>
#include <winternl.h>
typedef PVOID ALPC_HANDLE;
NTSTATUS NTAPI NtAlpcDeleteSecurityContext(HANDLE, ULONG, ALPC_HANDLE);
void ReleaseClientQos(HANDLE serverPort, ALPC_HANDLE ctx) {
if (ctx) {
NtAlpcDeleteSecurityContext(serverPort, 0, ctx);
}
}asmx64 direct stub (Win11 24H2)
; Direct syscall stub for NtAlpcDeleteSecurityContext (SSN 0x85 on Win11 24H2 / Server 2025)
NtAlpcDeleteSecurityContext PROC
mov r10, rcx ; PortHandle
mov eax, 85h ; SSN
syscall
ret
NtAlpcDeleteSecurityContext ENDPMITRE ATT&CK mappings
Last verified: 2026-05-20