Skip to content

Commit 1a6c366

Browse files
authoredSep 7, 2024
do not intercept OIDs to non-default port (microsoft#122)
1 parent 223a9b1 commit 1a6c366

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed
 

‎src/mp/sys/miniport.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ MiniportInitializeHandler(
757757
RegAttributes->AttributeFlags =
758758
NDIS_MINIPORT_ATTRIBUTES_NDIS_WDM |
759759
NDIS_MINIPORT_ATTRIBUTES_SURPRISE_REMOVE_OK |
760-
NDIS_MINIPORT_ATTRIBUTES_NO_PAUSE_ON_SUSPEND;
760+
NDIS_MINIPORT_ATTRIBUTES_NO_PAUSE_ON_SUSPEND |
761+
NDIS_MINIPORT_ATTRIBUTES_NO_OID_INTERCEPT_ON_NONDEFAULT_PORTS;
761762
RegAttributes->CheckForHangTimeInSeconds = 0;
762763
RegAttributes->InterfaceType = NdisInterfacePNPBus;
763764

‎src/mp/sys/oid.c

+10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ CONST NDIS_OID MpSupportedOidArray[] =
3939
OID_PNP_SET_POWER,
4040
OID_PNP_QUERY_POWER,
4141
OID_OFFLOAD_ENCAPSULATION,
42+
OID_GEN_RECEIVE_SCALE_CAPABILITIES,
4243
OID_GEN_RECEIVE_SCALE_PARAMETERS,
44+
OID_GEN_DRIVER_VERSION,
4345
OID_TCP_OFFLOAD_PARAMETERS,
4446
OID_TCP_OFFLOAD_HW_PARAMETERS,
4547
OID_QUIC_CONNECTION_ENCRYPTION,
@@ -153,6 +155,7 @@ MpProcessQueryOid(
153155
PUINT BytesWritten = &NdisRequest->DATA.QUERY_INFORMATION.BytesWritten;
154156
PUINT BytesNeeded = &NdisRequest->DATA.QUERY_INFORMATION.BytesNeeded;
155157
BOOLEAN DoCopy = TRUE;
158+
UINT16 DriverVersion;
156159
ULONG LocalData = 0;
157160
ULONG DataLength = sizeof(LocalData);
158161
VOID *Data = &LocalData;
@@ -222,6 +225,13 @@ MpProcessQueryOid(
222225
LocalData = Adapter->MtuSize + ETH_HDR_LEN;
223226
break;
224227

228+
case OID_GEN_DRIVER_VERSION:
229+
DriverVersion =
230+
(NDIS_MINIPORT_MAJOR_VERSION << RTL_BITS_OF(UINT8)) | NDIS_MINIPORT_MINOR_VERSION;
231+
DataLength = sizeof(DriverVersion);
232+
Data = &DriverVersion;
233+
break;
234+
225235
case OID_GEN_VENDOR_ID:
226236
LocalData = 0x00FFFFFF;
227237
break;

‎test/functional/lib/tests.cpp

+42-9
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,34 @@ LwfOidSubmitRequestFn(
917917
CXPLAT_THREAD_RETURN(0);
918918
}
919919

920+
template <typename T>
921+
static
922+
unique_malloc_ptr<T>
923+
LwfOidAllocateAndSubmitRequest(
924+
_In_ const unique_fnlwf_handle &Handle,
925+
_In_ OID_KEY Key,
926+
_Out_ UINT32 *BytesReturned
927+
)
928+
{
929+
unique_malloc_ptr<T> InformationBuffer;
930+
UINT32 InformationBufferLength = 0;
931+
FNLWFAPI_STATUS Result;
932+
933+
Result = LwfOidSubmitRequest(Handle, Key, &InformationBufferLength, NULL);
934+
TEST_EQUAL_RET(FNLWFAPI_STATUS_MORE_DATA, Result, InformationBuffer);
935+
TEST_TRUE_RET(InformationBufferLength > 0, InformationBuffer);
936+
937+
InformationBuffer.reset((T *)CxPlatAllocNonPaged(InformationBufferLength, POOL_TAG));
938+
TEST_NOT_NULL_RET(InformationBuffer.get(), InformationBuffer);
939+
940+
Result = LwfOidSubmitRequest(Handle, Key, &InformationBufferLength, InformationBuffer.get());
941+
TEST_FNLWFAPI_RET(Result, InformationBuffer);
942+
TEST_TRUE_RET(InformationBufferLength > 0, InformationBuffer);
943+
*BytesReturned = InformationBufferLength;
944+
945+
return InformationBuffer;
946+
}
947+
920948
static
921949
bool
922950
WaitForWfpQuarantine(
@@ -1521,28 +1549,33 @@ MpBasicWatchdog()
15211549
static
15221550
VOID
15231551
MpVerifyPortState(
1524-
_In_ const unique_fnlwf_handle& LwfHandle,
1552+
_In_ const unique_fnlwf_handle &LwfHandle,
15251553
_In_ NDIS_PORT_NUMBER PortNumber,
15261554
_In_ BOOLEAN ExpectFound
15271555
)
15281556
{
15291557
OID_KEY OidKey;
1530-
InitializeOidKey(&OidKey, OID_GEN_PORT_STATE, NdisRequestQueryInformation);
1531-
OidKey.PortNumber = PortNumber;
1558+
InitializeOidKey(&OidKey, OID_GEN_ENUMERATE_PORTS, NdisRequestQueryInformation);
15321559
NDIS_PORT_STATE PortState = {0};
1533-
UINT32 PortStateSize = sizeof(PortState);
1560+
UINT32 BytesReturned;
1561+
BOOLEAN Found = FALSE;
15341562

15351563
//
15361564
// Verify the port state is accurately reported to NDIS components.
15371565
//
15381566

1539-
FNLWFAPI_STATUS Status = LwfOidSubmitRequest(LwfHandle, OidKey, &PortStateSize, &PortState);
1567+
auto PortArray =
1568+
LwfOidAllocateAndSubmitRequest<NDIS_PORT_ARRAY>(LwfHandle, OidKey, &BytesReturned);
1569+
TEST_NOT_NULL(PortArray.get());
15401570

1541-
if (ExpectFound) {
1542-
TEST_FNLWFAPI(Status);
1543-
} else {
1544-
TEST_NOT_EQUAL(FNLWFAPI_STATUS_SUCCESS, Status);
1571+
for (UINT64 i = 0; i < PortArray->NumberOfPorts; i++) {
1572+
const NDIS_PORT_CHARACTERISTICS *PortCharacteristics = (const NDIS_PORT_CHARACTERISTICS *)
1573+
RTL_PTR_ADD(PortArray.get(), PortArray->OffsetFirstPort + PortArray->ElementSize * i);
1574+
1575+
Found |= PortCharacteristics->PortNumber == PortNumber;
15451576
}
1577+
1578+
TEST_EQUAL(ExpectFound, Found);
15461579
}
15471580

15481581
EXTERN_C

0 commit comments

Comments
 (0)
Please sign in to comment.