IrqlZwPassive 规则 (wdm)
IrqlZwPassive规则指定,仅当驱动程序在 IRQL = PASSIVE_LEVEL 上执行时,才调用ZwClose 。
驱动程序模型: WDM
Bug 检查 () 找到此规则: bug 检查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 规则。 使用以下步骤来运行代码分析:有关详细信息,请参阅 使用静态驱动程序验证器查找驱动程序中的缺陷。 |
运行时 |
---|
适用于
ZwCloseZwCreateKeyZwDeleteKeyZwEnumerateKeyZwEnumerateValueKeyZwFlushKeyZwOpenKey ZwQueryKey ZwQueryValueKeyZwSetValueKey