内存泄漏 - DRIVER_VERIFIER_DETECTED_VIOLATION (C4): 0x62

来源:互联网 发布:管家婆软件怎么用 编辑:程序博客网 时间:2024/06/05 18:59

调试内存泄漏 - DRIVER_VERIFIER_DETECTED_VIOLATION (C4): 0x62

此主题尚未评级 评价此主题

当驱动程序上载而没有首先释放其所有池分配时,驱动程序验证程序生成 Bug Check 0xC4: DRIVER_VERIFIER_DETECTED_VIOLATION,并具有 0x62 的参数值 1。未释放的内存分配(也称为内存泄漏)是操作系统性能降低的一个常见原因。这些分配会使系统池成为碎片,最终导致系统崩溃。

当你将内核调试程序连接到运行驱动程序验证程序的测试计算机时,如果驱动程序验证程序检测到冲突,Windows 会进入调试程序并显示关于错误的简短描述。

在驱动程序卸载时调试内存泄漏

  • 使用 !analyze 来显示有关调试检查的信息
  • 使用 !verifier 3 扩展命令查找有关池分配的信息
  • 如果你有符号,可以在发生内存分配的源文件中找到
  • 检查日志以查看内存分配
  • 修复内存泄露

使用 !analyze 来显示有关调试检查的信息

在进行任何错误检查时,一旦你可以控制调试程序,第一步最好是运行 !analyze -v 命令。

kd> !analyze -vConnected to Windows 8 9600 x86 compatible targetLoading Kernel Symbols.................................................................................Loading User Symbols.......................Loading unloaded module list........********************************************************************************                                                                             **                        Bugcheck Analysis                                    **                                                                             ********************************************************************************DRIVER_VERIFIER_DETECTED_VIOLATION (c4)A device driver attempting to corrupt the system has been caught.  This isbecause the driver was specified in the registry as being suspect (by theadministrator) and the kernel has enabled substantial checking of this driver.If the driver attempts to corrupt the system, bugchecks 0xC4, 0xC1 and 0xA willbe among the most commonly seen crashes.Arguments:Arg1: 00000062, A driver has forgotten to free its pool allocations prior to unloading.Arg2: 9707712c, name of the driver having the issue.Arg3: 9c1faf70, verifier internal structure with driver information.Arg4: 00000003, total # of (paged+nonpaged) allocations that weren't freed.Type !verifier 3 drivername.sys for info on the allocationsthat were leaked that caused the bugcheck.

具有 0x62 的参数值 1 (Arg1) 的Bug Check 0xC4: DRIVER_VERIFIER_DETECTED_VIOLATION 描述如下:

DRIVER_VERIFIER_DETECTED_VIOLATION (C4) Arg1Arg2Arg3Arg4原因驱动程序验证程序标志0x62驱动程序的名称。Reserved未释放的分配总数,包括分页和未分页的池。驱动程序在上载而没有首先释放其池分配。 在 Windows 8.1 中,如果驱动程序卸载而不首先释放它已使用 IoAllocateWorkItem 分配的任何工作项目 (IO_WORKITEM),也会发生此调试检查。此有此参数的错误检查仅在池跟踪选项激活时发生。指定池跟踪 (verifier /flags 0x8)池跟踪选项将启用,并带有标准标志 (verifier /standard )。

 

使用 !verifier 3 扩展命令查找有关池分配的信息

对于此特定错误检查,在参数 4 (Arg4) 中提供的信息最重要。Arg4 显示未释放的分配数。!analyze 命令的输出还显示 !verifier 调试程序扩展命令,可以用来显示这些分配的内容。 下例显示了 !verifier 3 MyDriver.sys 命令的完整输出:

kd> !verifier 3 Mydriver.sysVerify Flags Level 0x000209bb  STANDARD FLAGS:    [X] (0x00000000) Automatic Checks    [X] (0x00000001) Special pool    [X] (0x00000002) Force IRQL checking    [X] (0x00000008) Pool tracking    [X] (0x00000010) I/O verification    [X] (0x00000020) Deadlock detection    [X] (0x00000080) DMA checking    [X] (0x00000100) Security checks    [X] (0x00000800) Miscellaneous checks    [X] (0x00020000) DDI compliance checking  ADDITIONAL FLAGS:    [ ] (0x00000004) Randomized low resources simulation    [ ] (0x00000200) Force pending I/O requests    [ ] (0x00000400) IRP logging    [ ] (0x00002000) Invariant MDL checking for stack    [ ] (0x00004000) Invariant MDL checking for driver    [ ] (0x00008000) Power framework delay fuzzing    [ ] (0x00040000) Systematic low resources simulation    [ ] (0x00080000) DDI compliance checking (additional)    [ ] (0x00200000) NDIS/WIFI verification    [ ] (0x00800000) Kernel synchronization delay fuzzing    [ ] (0x01000000) VM switch verification    [X] Indicates flag is enabledSummary of All Verifier Statistics  RaiseIrqls           0x0  AcquireSpinLocks     0x0  Synch Executions     0x0  Trims                0x0  Pool Allocations Attempted             0x2db1a  Pool Allocations Succeeded             0x2db1a  Pool Allocations Succeeded SpecialPool 0x2db1a  Pool Allocations With NO TAG           0x0  Pool Allocations Failed                0x0  Current paged pool allocations         0x0 for 00000000 bytes  Peak paged pool allocations            0x0 for 00000000 bytes  Current nonpaged pool allocations      0x3 for 00001058 bytes  Peak nonpaged pool allocations         0x13 for 0004A4A0 bytesDriver Verification List------------------------  MODULE: 0x84226b28 MyDriver.sys (Loaded)    Pool Allocation Statistics: ( NonPagedPool / PagedPool )      Current Pool Allocations: ( 0x00000003 / 0x00000000 )      Current Pool Bytes:       ( 0x00001058 / 0x00000000 )      Peak Pool Allocations:    ( 0x00000013 / 0x00000000 )      Peak Pool Bytes:          ( 0x0004A4A0 / 0x00000000 )      Contiguous Memory Bytes:       0x00000000      Peak Contiguous Memory Bytes:  0x00000000    Pool Allocations:      Address     Length      Tag   Caller          ----------  ----------  ----  ----------      0x982a8fe0  0x00000020  VMdl  0x9a3bf6ac  MyDriver!DeviceControlDispatch      0x8645a000  0x00001008  mdrv  0x9a3bf687  MyDriver!DeviceControlDispatch      0x9a836fd0  0x00000030  Vfwi  0x9a3bf6ed  MyDriver!GetNecessaryObjects

在该示例中,驱动程序 MyDriver.sys 有两个内存分配和一个 I/O 工作项目还未正确释放。 每个列表显示当前分配的地址、大小、使用的池标签,以及做出分配请求的驱动程序代码中的地址。 如果为有问题的驱动程序加载了符号,它也将在调用方地址的旁边显示函数的名称。

在显示的标签中,只有一个(用于地址 0x8645a000 的分配)由驱动程序本身 (mdrv) 提供。 当驱动程序验证程序验证的驱动程序调用 IoAllocateMdl时,将使用标签 VMdl。 类似地,当驱动程序验证程序验证的驱动程序使用 IoAllocateWorkItem 请求分配工作项目时,将使用标签 Vfwi

如果你有符号,可以在发生内存分配的源文件中找到

当为驱动程序加载了符号时,如果这些符号包含行号信息,则可以使用 ln CallerAddress 命令来显示进行调用的行。 此输出也将显示进行分配的函数中的偏移。

kd> ln 0x9a3bf6ac  d:\coding\wdmdrivers\mydriver\handleioctl.c(50)+0x15(9a3bf660)   MyDriver!DeviceControlDispatch+0x4c   |  (9a3bf6d0)   MyDriver!DeviceControlDispatchkd> ln 0x9a3bf687  d:\coding\wdmdrivers\mydriver\handleioctl.c(38)+0x12(9a3bf660)   MyDriver!DeviceControlDispatch+0x27   |  (9a3bf6d0)   MyDriver!DeviceControlDispatchkd> ln 0x9a3bf6ed  d:\coding\wdmdrivers\mydriver\handleioctl.c(72)+0xa(9a3bf6d0)   MyDriver!GetNecessaryObjects+0x1d   |  (9a3bf71c)   MyDriver!GetNecessaryObjects

检查日志以查看内存分配

当池跟踪启用时,驱动程序验证程序还保留在内核空间中进行的所有内存分配的循环日志。 默认情况下,将保留最新的 65,536 (0x10000) 项分配。当做出新的分配时,将覆盖日志中最旧的分配。 如果在崩溃前刚进行了分配,则有可能获取比上面显示的更多的分配信息,尤其是分配时的线程地址和内核堆栈框架。

通过使用命令 !verifier 0x80 AddressOfPoolAllocation 可以访问此日志。 请注意,这将列出日志中此特定地址的所有分配和释放。要取消或停止日志历史记录的显示,则使用键盘快捷键:对于 WinDbg 使用 Ctrl + Break,对于 KD 使用 Ctrl + C

kd> !verifier 0x80 0x982a8fe0Log of recent kernel pool Allocate and Free operations:There are up to 0x10000 entries in the log.Parsing 0x00010000 log entries, searching for address 0x982a8fe0.======================================================================Pool block 982a8fe0, Size 00000020, Thread 9c158bc081b250cd nt!IovAllocateMdl+0x3d8060e41d VerifierExt!IoAllocateMdl_internal_wrapper+0x3581b29388 nt!VerifierIoAllocateMdl+0x229a3bf6ac MyDriver!DeviceControlDispatch+0x4c9a3bf611 MyDriver!NonPNPIRPDispatch0x519a3bf05a MyDriver!AllIRPDispatch+0x1a80611710 VerifierExt!xdv_IRP_MJ_DEVICE_CONTROL_wrapper+0xd081b3b635 nt!ViGenericDispatchHandler+0x2d81b3b784 nt!ViGenericDeviceControl+0x1881b24b4d nt!IovCallDriver+0x2cc81703772 nt!IofCallDriver+0x628191165e nt!IopSynchronousServiceTail+0x16e81915518 nt!IopXxxControlFile+0x3e8kd> !verifier 0x80 0x8645a000Log of recent kernel pool Allocate and Free operations:There are up to 0x10000 entries in the log.Parsing 0x00010000 log entries, searching for address 0x8645a000.======================================================================Pool block 8645a000, Size 00001000, Thread 9c158bc08060ee4f VerifierExt!ExAllocatePoolWithTagPriority_internal_wrapper+0x5b81b2619e nt!VerifierExAllocatePoolWithTag+0x249a3bf687 MyDriver!DeviceControlDispatch+0x279a3bf611 MyDriver!NonPNPIRPDispatch0x519a3bf05a MyDriver!AllIRPDispatch+0x1a80611710 VerifierExt!xdv_IRP_MJ_DEVICE_CONTROL_wrapper+0xd081b3b635 nt!ViGenericDispatchHandler+0x2d81b3b784 nt!ViGenericDeviceControl+0x1881b24b4d nt!IovCallDriver+0x2cc81703772 nt!IofCallDriver+0x628191165e nt!IopSynchronousServiceTail+0x16e81915518 nt!IopXxxControlFile+0x3e881914516 nt!NtDeviceIoControlFile+0x2akd> !verifier 0x80 0x9a836fd0  Log of recent kernel pool Allocate and Free operations:There are up to 0x10000 entries in the log.Parsing 0x00010000 log entries, searching for address 0x9a836fd0.======================================================================Pool block 9a836fd0, Size 00000030, Thread 887587408151713d nt!IovAllocateWorkItem+0x1b84a133d9 VerifierExt!IoAllocateWorkItem_internal_wrapper+0x298151b3a7 nt!VerifierIoAllocateWorkItem+0x169a3bf6ed MyDriver!GetNecessaryObjects+0x1d9a3bf620 MyDriver!NonPNPIRPDispatch0x519a3bf05a MyDriver!AllIRPDispatch+0x1a84a16710 VerifierExt!xdv_IRP_MJ_DEVICE_CONTROL_wrapper+0xd08152d635 nt!ViGenericDispatchHandler+0x2d8152d784 nt!ViGenericDeviceControl+0x1881516b4d nt!IovCallDriver+0x2cc810f5772 nt!IofCallDriver+0x628130365e nt!IopSynchronousServiceTail+0x16e81307518 nt!IopXxxControlFile+0x3e8

修复内存泄露

此驱动程序验证程序错误检查旨在防止驱动程序泄露内核内存。 在每种情况下,正确的修复是识别任何未释放分配对象的现有代码路径,并确保它们正确释放。

静态驱动程序验证程序是一种扫描 Windows 驱动程序源代码的工具,通过模拟各种代码路径的练习来报告可能的问题。 静态驱动程序验证程序是一款在开发时使用的出色实用工具,可帮助识别此类问题。

对于其他可以使用的技术,包括驱动程序验证程序未涉及的方案,请参阅查找内核模式内存泄露。


转与 http://msdn.microsoft.com/ZH-cn/library/dn457995.aspx/css

0 0