Skip to content

Commit

Permalink
netkvm: fail init if failed to open NIC configuration
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ybendito authored and YanVugenfirer committed Dec 11, 2024
1 parent ab1c77e commit ec02372
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions NetKVM/Common/ParaNdis_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,18 @@ 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)
{
*pConfiguration = defaultConfiguration;
cfg = ParaNdis_OpenNICConfiguration(pContext);
if (cfg)
{
ret = true;
GetConfigurationEntry(cfg, &pConfiguration->PhysicalMediaType);
GetConfigurationEntry(cfg, &pConfiguration->isLogEnabled);
GetConfigurationEntry(cfg, &pConfiguration->debugLevel);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit ec02372

Please sign in to comment.