Skip to content

Commit

Permalink
Add assertions for LWF callbacks which should not be used for Loopbac…
Browse files Browse the repository at this point in the history
…k capture
  • Loading branch information
bonsaiviking committed Sep 22, 2021
1 parent 6bd9c88 commit 9e66ba0
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 7 deletions.
72 changes: 71 additions & 1 deletion packetWin7/npf/npf/Openclos.c
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,12 @@ Return Value:
UNREFERENCED_PARAMETER(NdisFilterHandle);
TRACE_ENTER();

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!((PNPCAP_FILTER_MODULE) NdisFilterHandle)->Loopback);
#endif


if (!NT_VERIFY(FilterDriverContext == (NDIS_HANDLE)FilterDriverObject))
{
IF_LOUD(DbgPrint("NPF_RegisterOptions: driver doesn't match error, FilterDriverContext = %p, FilterDriverObject = %p.\n", FilterDriverContext, FilterDriverObject);)
Expand Down Expand Up @@ -2268,6 +2274,11 @@ NPF_AttachAdapter(

TRACE_ENTER();

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

do
{
if (!NT_VERIFY(FilterDriverContext == (NDIS_HANDLE)FilterDriverObject))
Expand Down Expand Up @@ -2466,6 +2477,11 @@ NPF_Pause(
UNREFERENCED_PARAMETER(PauseParameters);
TRACE_ENTER();

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

NdisInitializeEvent(&Event);
NdisResetEvent(&Event);

Expand Down Expand Up @@ -2508,6 +2524,11 @@ NPF_Restart(

TRACE_ENTER();

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

if (RestartParameters == NULL)
{
// Can't validate, but probably fine. Also, I don't think this is possible.
Expand Down Expand Up @@ -2584,7 +2605,13 @@ NOTE: Called at PASSIVE_LEVEL and the filter is in paused state

TRACE_ENTER();

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is called for loopback module by NPF_Unload. */
NT_ASSERT(pFiltMod->AdapterBindingStatus == FilterPaused || pFiltMod->Loopback);
#else
NT_ASSERT(pFiltMod->AdapterBindingStatus == FilterPaused);
#endif

/* No need to lock the group since we are paused. */
for (Curr = pFiltMod->OpenInstances.Next; Curr != NULL; Curr = Curr->Next)
{
Expand Down Expand Up @@ -2646,6 +2673,11 @@ NOTE: Called at <= DISPATCH_LEVEL (unlike a miniport's MiniportOidRequest)

TRACE_ENTER();

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

// Special case: if their new packet filter doesn't change the lower one
// then we don't pass it down but just return success.
if (Request->RequestType == NdisRequestSetInformation
Expand Down Expand Up @@ -2779,6 +2811,11 @@ Routine Description:
PFILTER_REQUEST_CONTEXT Context;
PNDIS_OID_REQUEST OriginalRequest = NULL;

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

FILTER_ACQUIRE_LOCK(&pFiltMod->OIDLock, NPF_IRQL_UNKNOWN);

Request = pFiltMod->PendingOidRequest;
Expand Down Expand Up @@ -2840,6 +2877,11 @@ Routine Description:

TRACE_ENTER();

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

Context = (PFILTER_REQUEST_CONTEXT)(&Request->SourceReserved[0]);
OriginalRequest = (*Context);

Expand Down Expand Up @@ -2932,6 +2974,11 @@ NOTE: called at <= DISPATCH_LEVEL
{
PNPCAP_FILTER_MODULE pFiltMod = (PNPCAP_FILTER_MODULE) FilterModuleContext;

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

// TRACE_ENTER();
// IF_LOUD(DbgPrint("NPF: Status Indication\n");)

Expand Down Expand Up @@ -2975,6 +3022,11 @@ NOTE: called at PASSIVE_LEVEL
PNPCAP_FILTER_MODULE pFiltMod = (PNPCAP_FILTER_MODULE) FilterModuleContext;
NDIS_DEVICE_PNP_EVENT DevicePnPEvent = NetDevicePnPEvent->DevicePnPEvent;

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

/* TRACE_ENTER();*/

//
Expand Down Expand Up @@ -3039,6 +3091,11 @@ NOTE: called at PASSIVE_LEVEL

TRACE_ENTER();

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

//
// The filter may do processing on the event here, including intercepting
// and dropping it entirely. However, the sample does nothing with Net PNP
Expand Down Expand Up @@ -3087,7 +3144,10 @@ Routine Description:
{
PNPCAP_FILTER_MODULE pFiltMod = (PNPCAP_FILTER_MODULE) FilterModuleContext;

/* TRACE_ENTER();*/
#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

if (NetBufferLists->SourceHandle == pFiltMod->AdapterHandle)
{
Expand Down Expand Up @@ -3135,6 +3195,11 @@ Return Value:
{
PNPCAP_FILTER_MODULE pFiltMod = (PNPCAP_FILTER_MODULE) FilterModuleContext;

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

NdisFCancelSendNetBufferLists(pFiltMod->AdapterHandle, CancelId);
}

Expand Down Expand Up @@ -3166,6 +3231,11 @@ Return Value:
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
UNREFERENCED_PARAMETER(FilterModuleContext);

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!((PNPCAP_FILTER_MODULE)FilterModuleContext)->Loopback);
#endif

return Status;
}

Expand Down
14 changes: 10 additions & 4 deletions packetWin7/npf/npf/Read.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,11 @@ NPF_SendEx(
{
PNPCAP_FILTER_MODULE pFiltMod = (PNPCAP_FILTER_MODULE) FilterModuleContext;

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

TRACE_ENTER();

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
Expand Down Expand Up @@ -563,6 +568,11 @@ NPF_TapEx(
UNREFERENCED_PARAMETER(PortNumber);
UNREFERENCED_PARAMETER(NumberOfNetBufferLists);

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
/* This callback is only for the NDIS LWF, not WFP/loopback */
NT_ASSERT(!pFiltMod->Loopback);
#endif

if (NDIS_TEST_RECEIVE_AT_DISPATCH_LEVEL(ReceiveFlags))
{
NDIS_SET_RETURN_FLAG(ReturnFlags, NDIS_RETURN_FLAGS_DISPATCH_LEVEL);
Expand All @@ -573,10 +583,6 @@ NPF_TapEx(
!(NdisTestNblFlag(NetBufferLists, NDIS_NBL_FLAGS_IS_LOOPBACK_PACKET)
&& NetBufferLists->SourceHandle == pFiltMod->AdapterHandle)

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
// Do not capture the normal NDIS receive traffic, if this is our loopback adapter.
&& pFiltMod->Loopback == FALSE
#endif
)
{
NPF_DoTap(pFiltMod, NetBufferLists, NULL, NDIS_TEST_RECEIVE_AT_DISPATCH_LEVEL(ReceiveFlags));
Expand Down
8 changes: 6 additions & 2 deletions packetWin7/npf/npf/Write.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ Return Value:
PNPCAP_FILTER_MODULE pFiltMod = (PNPCAP_FILTER_MODULE) FilterModuleContext;

TRACE_ENTER();
/* This callback is used for NDIS LWF as well as WFP/loopback */

//
// If your filter injected any send packets into the datapath to be sent,
Expand Down Expand Up @@ -1128,6 +1129,8 @@ NPF_SendCompleteExForEachOpen(

//-------------------------------------------------------------------

#ifdef HAVE_WFP_LOOPBACK_SUPPORT

_IRQL_requires_min_(PASSIVE_LEVEL)
_IRQL_requires_max_(DISPATCH_LEVEL)
_IRQL_requires_same_
Expand All @@ -1139,6 +1142,9 @@ void NTAPI NPF_NetworkInjectionComplete(
{
TRACE_ENTER();

/* This method should only be used for Loopback (for now, though see #516) */
NT_ASSERT(((PNPCAP_FILTER_MODULE) pContext)->Loopback);

if (pNetBufferList->Status != STATUS_SUCCESS)
{
TRACE_MESSAGE1(PACKET_DEBUG_LOUD,
Expand All @@ -1154,8 +1160,6 @@ void NTAPI NPF_NetworkInjectionComplete(
return;
}


#ifdef HAVE_WFP_LOOPBACK_SUPPORT
_Use_decl_annotations_
NTSTATUS
NPF_LoopbackSendNetBufferLists(
Expand Down

0 comments on commit 9e66ba0

Please sign in to comment.