irqlZwPassive 規則 (wdm)

IrqlZwPassive 規則指定驅動程式只在 IRQL = PASSIVE_LEVEL執行時呼叫 ZwClose

驅動程式模型:WDM

此規則找到的錯誤檢查 () 錯誤檢查0xC4:DRIVER_VERIFIER_DETECTED_VIOLATION (0x2001F)

範例

下列程式代碼違反此規則:

NTSTATUS 
DriverCloseResources (
    _In_ PDRIVER_CONTEXT Context
    )
{
    …

    NT_ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);

    //
    // ExAcquireFastMutex sets the IRQL to APC_LEVEL, and the caller continues 
    // to run at APC_LEVEL after ExAcquireFastMutex returns.
    //
  
    ExAcquireFastMutex(&Context->FastMutex);
    
    ....
    
    if (NULL != Context->Handle) {

            //
            // RULE VIOLATION! - ZwClose can be called only at PASSIVE_LEVEL 
            //
            
            ZwClose(Context->Handle);      
            Context->Handle = NULL;
    }
    
    ....

    //
    // N.B. ExReleaseFastMutex restores the original IRQL.
    //
     
    ExReleaseFastMutex(&Context->FastMutex);
    
    ....
}

測試方法

在編譯時期

執行 靜態驅動程式驗證器 並指定 IrqlZwPassive 規則。

使用下列步驟來執行程式碼的分析:
  1. 準備程式代碼 (使用角色類型宣告) 。
  2. 執行靜態驅動程式驗證程式。
  3. 檢視和分析結果。

如需詳細資訊,請參閱 使用靜態驅動程式驗證器尋找驅動程式中的瑕疵

运行时

執行 驅動程式驗證器 ,然後選取 [DDI 合規性檢查 ] 選項。

適用於

ZwCloseZwCreateKeyZwDeleteKeyZwEnumerateKeyZwEnumerateValueKeyZwFlushKeyZwOpenKeyZwQueryValueKeyZwQueryValueKeyZwSetValueKey