From ec023725fc5fb4f0631f4779c5cde16f3b3fe221 Mon Sep 17 00:00:00 2001 From: Yuri Benditovich Date: Sat, 30 Nov 2024 13:36:52 +0200 Subject: [PATCH] netkvm: fail init if failed to open NIC configuration Under driver verifier with low resources simulation the attempt to access NIC configuration may fail, important fields of the context are not initialized correctly causing driver verifier BSOD on attempt to allocate zero bytes from memory. Fail initialization if the NIC configuration is not accessible. Signed-off-by: Yuri Benditovich --- NetKVM/Common/ParaNdis_Common.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/NetKVM/Common/ParaNdis_Common.cpp b/NetKVM/Common/ParaNdis_Common.cpp index e02dda9e5..e2028fb59 100755 --- a/NetKVM/Common/ParaNdis_Common.cpp +++ b/NetKVM/Common/ParaNdis_Common.cpp @@ -237,9 +237,10 @@ Loads NIC parameters from adapter registry key context PUCHAR *ppNewMACAddress - pointer to hold MAC address if configured from host ***********************************************************/ -static void ReadNicConfiguration(PARANDIS_ADAPTER *pContext, PUCHAR pNewMACAddress) +static bool ReadNicConfiguration(PARANDIS_ADAPTER *pContext, PUCHAR pNewMACAddress) { NDIS_HANDLE cfg; + bool ret = false; tConfigurationEntries *pConfiguration = (tConfigurationEntries *) ParaNdis_AllocateMemory(pContext, sizeof(tConfigurationEntries)); if (pConfiguration) { @@ -247,6 +248,7 @@ static void ReadNicConfiguration(PARANDIS_ADAPTER *pContext, PUCHAR pNewMACAddre cfg = ParaNdis_OpenNICConfiguration(pContext); if (cfg) { + ret = true; GetConfigurationEntry(cfg, &pConfiguration->PhysicalMediaType); GetConfigurationEntry(cfg, &pConfiguration->isLogEnabled); GetConfigurationEntry(cfg, &pConfiguration->debugLevel); @@ -384,6 +386,7 @@ static void ReadNicConfiguration(PARANDIS_ADAPTER *pContext, PUCHAR pNewMACAddre } NdisFreeMemory(pConfiguration, 0, 0); } + return ret; } void ParaNdis_ResetOffloadSettings(PARANDIS_ADAPTER *pContext, tOffloadSettingsFlags *pDest, PULONG from) @@ -799,7 +802,10 @@ NDIS_STATUS ParaNdis_InitializeContext( return NDIS_STATUS_RESOURCES; } - ReadNicConfiguration(pContext, CurrentMAC); + if (!ReadNicConfiguration(pContext, CurrentMAC)) + { + return NDIS_STATUS_RESOURCES; + } pContext->fCurrentLinkState = MediaConnectStateUnknown;