From a2d46f3c00763dbb7eb2a4917336cd08d1f93a87 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 31 Jul 2019 14:10:37 +0000 Subject: Disable APC when taking rwlock Signed-off-by: Jason A. Donenfeld --- wintun.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'wintun.c') diff --git a/wintun.c b/wintun.c index 0dbd1dd..c8c1247 100644 --- a/wintun.c +++ b/wintun.c @@ -835,6 +835,7 @@ TunDispatchDeviceControl(DEVICE_OBJECT *DeviceObject, IRP *Irp) switch (Stack->Parameters.DeviceIoControl.IoControlCode) { case TUN_IOCTL_REGISTER_RINGS: { + KeEnterCriticalRegion(); ExAcquireResourceSharedLite(&TunDispatchCtxGuard, TRUE); #pragma warning(suppress : 28175) TUN_CTX *Ctx = DeviceObject->Reserved; @@ -842,6 +843,7 @@ TunDispatchDeviceControl(DEVICE_OBJECT *DeviceObject, IRP *Irp) if (Ctx) Status = TunRegisterBuffers(Ctx, Irp); ExReleaseResourceLite(&TunDispatchCtxGuard); + KeLeaveCriticalRegion(); break; } case TUN_IOCTL_FORCE_CLOSE_HANDLES: @@ -862,12 +864,14 @@ _Use_decl_annotations_ static NTSTATUS TunDispatchClose(DEVICE_OBJECT *DeviceObject, IRP *Irp) { + KeEnterCriticalRegion(); ExAcquireResourceSharedLite(&TunDispatchCtxGuard, TRUE); #pragma warning(suppress : 28175) TUN_CTX *Ctx = DeviceObject->Reserved; if (Ctx) TunUnregisterBuffers(Ctx, IoGetCurrentIrpStackLocation(Irp)->FileObject); ExReleaseResourceLite(&TunDispatchCtxGuard); + KeLeaveCriticalRegion(); return NdisDispatchClose(DeviceObject, Irp); } @@ -1083,8 +1087,10 @@ TunHaltEx(NDIS_HANDLE MiniportAdapterContext, NDIS_HALT_ACTION HaltAction) InterlockedSetPointer(&Ctx->MiniportAdapterHandle, NULL); #pragma warning(suppress : 28175) InterlockedSetPointer(&Ctx->FunctionalDeviceObject->Reserved, NULL); + KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&TunDispatchCtxGuard, TRUE); /* Ensure above change is visible to all readers. */ ExReleaseResourceLite(&TunDispatchCtxGuard); + KeLeaveCriticalRegion(); ExFreePoolWithTag(Ctx, TUN_MEMORY_TAG); } -- cgit v1.2.3-59-g8ed1b