> Windows Syscalls
ntoskrnl.exeT1559T1106

NtAlpcDeleteSecurityContext

Frees an ALPC SECURITY_QOS context previously created with NtAlpcCreateSecurityContext.

Prototype

NTSTATUS NtAlpcDeleteSecurityContext(
  HANDLE  PortHandle,
  ULONG   Flags,
  ALPC_HANDLE  ContextHandle
);

Arguments

NameTypeDirDescription
PortHandleHANDLEinHandle to the ALPC port that owns the security context.
FlagsULONGinReserved. Must be 0.
ContextHandleALPC_HANDLEinOpaque ALPC_HANDLE returned by NtAlpcCreateSecurityContext; identifies the QoS context to release.

Syscall IDs by Windows version

Windows versionSyscall IDBuild
Win10 15070x7Fwin10-1507
Win10 16070x7Fwin10-1607
Win10 17030x80win10-1703
Win10 17090x80win10-1709
Win10 18030x81win10-1803
Win10 18090x81win10-1809
Win10 19030x81win10-1903
Win10 19090x81win10-1909
Win10 20040x83win10-2004
Win10 20H20x83win10-20h2
Win10 21H10x83win10-21h1
Win10 21H20x83win10-21h2
Win10 22H20x83win10-22h2
Win11 21H20x83win11-21h2
Win11 22H20x83win11-22h2
Win11 23H20x83win11-23h2
Win11 24H20x85win11-24h2
Server 20160x7Fwinserver-2016
Server 20190x81winserver-2019
Server 20220x83winserver-2022
Server 20250x85winserver-2025

Kernel module

ntoskrnl.exeNtAlpcDeleteSecurityContext

Related APIs

NtAlpcCreateSecurityContextNtAlpcRevokeSecurityContextNtAlpcImpersonateClientOfPortNtAlpcQueryInformation

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 ENDP

MITRE ATT&CK mappings

Last verified: 2026-05-20