Skip to content

Commit

Permalink
Rearrange initialization of filter module list
Browse files Browse the repository at this point in the history
As soon as we call NdisFRegisterFilterDriver, NDIS can start attaching
adapters. All members have to be initialized already. Additionally, the
global `g_arrFiltMod` has to be initialized when declared because
otherwise the compiler keeps rearranging things and setting `Next` to
NULL *after* the adapters are attached, resulting in NPF_OpenAdapter
always failing.
  • Loading branch information
bonsaiviking committed Jul 14, 2019
1 parent f0aa98a commit 1fafdb5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
2 changes: 0 additions & 2 deletions packetWin7/npf/npf/Openclos.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ extern ULONG g_Dot11SupportMode;
extern PDEVICE_OBJECT g_LoopbackDevObj;
#endif

extern NDIS_HANDLE FilterDriverHandle_WiFi; // NDIS handle for WiFi filter driver

static
VOID
NPF_ReleaseOpenInstanceResources(POPEN_INSTANCE pOpen);
Expand Down
51 changes: 28 additions & 23 deletions packetWin7/npf/npf/Packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ ULONG PacketDebugFlag = PACKET_DEBUG_LOUD;

#endif

PDEVICE_EXTENSION GlobalDeviceExtension;

SINGLE_LIST_ENTRY g_arrFiltMod; //Adapter filter module list head
SINGLE_LIST_ENTRY g_arrFiltMod = {0}; //Adapter filter module list head
NDIS_SPIN_LOCK g_FilterArrayLock; //The lock for adapter filter module list.

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
Expand Down Expand Up @@ -388,13 +386,40 @@ DriverEntry(
NPF_CreateDevice(DriverObject, &AdapterName, &g_NPF_Prefix_WIFI, TRUE);
}

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
// Use Winsock Kernel (WSK) to send loopback packets.
// TODO: Allow this to continue but disable loopback if there's an error
Status = NPF_WSKStartup();
if (!NT_SUCCESS(Status))
{
TRACE_EXIT();
return Status;
}

Status = NPF_WSKInitSockets();
if (!NT_SUCCESS(Status))
{
NPF_WSKCleanup();
TRACE_EXIT();
return Status;
}
#endif

/* Have to set this up before NdisFRegisterFilterDriver, since we can get Attach calls immediately after that! */
NdisAllocateSpinLock(&g_FilterArrayLock);

// Register the filter to NDIS.
Status = NdisFRegisterFilterDriver(DriverObject,
(NDIS_HANDLE) FilterDriverObject,
&FChars,
&FilterDriverHandle);
if (Status != NDIS_STATUS_SUCCESS)
{
#ifdef HAVE_WFP_LOOPBACK_SUPPORT
NPF_WSKFreeSockets();
NPF_WSKCleanup();
#endif
NdisFreeSpinLock(&g_FilterArrayLock);
TRACE_MESSAGE1(PACKET_DEBUG_LOUD, "NdisFRegisterFilterDriver: failed to register filter with NDIS, Status = %x", Status);
TRACE_EXIT();
return Status;
Expand Down Expand Up @@ -429,26 +454,6 @@ DriverEntry(
}
}

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
// Use Winsock Kernel (WSK) to send loopback packets.
Status = NPF_WSKStartup();
if (!NT_SUCCESS(Status))
{
TRACE_EXIT();
return Status;
}

Status = NPF_WSKInitSockets();
if (!NT_SUCCESS(Status))
{
TRACE_EXIT();
return Status;
}
#endif

NdisAllocateSpinLock(&g_FilterArrayLock);
g_arrFiltMod.Next = NULL;

TRACE_EXIT();
return STATUS_SUCCESS;

Expand Down

0 comments on commit 1fafdb5

Please sign in to comment.