From 928f21c5736160651d479b4be37dadc682d89284 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 13 Jul 2021 10:20:21 +0200 Subject: [PATCH] driver: switch to MS-recommended memory alloc Suggested-by: Static Driver Verifier Signed-off-by: Simon Rozman --- driver/driver.vcxproj | 2 +- driver/wintun.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/driver/driver.vcxproj b/driver/driver.vcxproj index 7d9dd73..4f7037b 100644 --- a/driver/driver.vcxproj +++ b/driver/driver.vcxproj @@ -89,7 +89,7 @@ - NDIS_MINIPORT_DRIVER=1;NDIS620_MINIPORT=1;NDIS683_MINIPORT=1;NDIS_WDM=1;%(PreprocessorDefinitions) + NDIS_MINIPORT_DRIVER=1;NDIS620_MINIPORT=1;NDIS683_MINIPORT=1;NDIS_WDM=1;POOL_ZERO_DOWN_LEVEL_SUPPORT;POOL_NX_OPTIN=1;%(PreprocessorDefinitions) /volatile:iso %(AdditionalOptions) true diff --git a/driver/wintun.c b/driver/wintun.c index 0b4bfe1..ae42552 100644 --- a/driver/wintun.c +++ b/driver/wintun.c @@ -988,10 +988,10 @@ TunInitializeEx( /* Leaking memory 'Ctx'. Note: 'Ctx' is freed in TunHaltEx or on failure. */ #pragma warning(suppress : 6014) - TUN_CTX *Ctx = ExAllocatePoolWithTag(NonPagedPoolNx, sizeof(*Ctx), TUN_MEMORY_TAG); +#pragma warning(suppress : 28160) + TUN_CTX *Ctx = ExAllocatePoolZero(NonPagedPool, sizeof(*Ctx), TUN_MEMORY_TAG); if (!Ctx) return NDIS_STATUS_FAILURE; - NdisZeroMemory(Ctx, sizeof(*Ctx)); Ctx->MiniportAdapterHandle = MiniportAdapterHandle; @@ -1420,6 +1420,8 @@ DriverEntry(DRIVER_OBJECT *DriverObject, UNICODE_STRING *RegistryPath) { NTSTATUS Status; + ExInitializeDriverRuntime(DrvRtPoolNxOptIn); + NdisVersion = NdisGetVersion(); if (NdisVersion < NDIS_MINIPORT_VERSION_MIN) return NDIS_STATUS_UNSUPPORTED_REVISION;