记一次驱动在win10 1903 x64下的蓝屏调试过程

背景

我们的产品有个驱动,用于做安全防护的,这个驱动已经稳定运行几年了,分32位和64位,虽然中间也偶有蓝屏,但都是新的os系统或大补丁发布后一些硬编码的偏移的问题,改掉这些问题后就好了。

但这次收到用户反馈在1903的系统上会蓝屏,然后我们搭建了两个测试环境,系统都是 win10 x64 1903,I7 CPU的系统会重现蓝屏,另一台E系列的cpu的系统运行正常。

而蓝屏发生时是挂在系统内部函数,不容易定位,同事已经分析调试这个问题好几个日日夜夜了,为了防止1903补丁的大规模推送导致大规模的蓝屏,我们必须尽快解决这蓝屏,否则整个安全组的饭碗可能不保!所以我也放下其他工作一起去调试这个问题。

过程

由于是在系统函数内部挂的,所以一定是我们的程序影响到了系统的什么内容,排除了系统函数参数个数变化导致的栈异常,排除了我们写坏了系统的内核内存等等可能,后来没办法只能通过屏蔽部分代码来缩小异常问题代码范围。

通过删减代码定位下来只要调用了读取系统注册表函数,并对这个功能进行VM加壳就会蓝屏,不加VM壳就正常,所以把问题定位到是VM壳的问题。

加了VM壳后没法调试了,所以只能把断点下在系统函数入口处,检查通过VM处理后调用的参数是不是有异常,看起来也是一切正常。

然后比较加了VM前后进入系统函数后的执行方式,内部调用分支是不是一样,一层一层跟进去,发现也是一样的,没有差异,只是最后读取一块内存时加了VM的版本蓝屏,不加VM的正常。

然后把焦点放在为什么会读取这块内存异常,两次的内存区域看起来也差不多。通过比较异常和正常时那块内存的页属性,奇怪的竟然是一样的,不存在一次内存有效一次内存无效的情况。那为什么两次读取一次异常一次正常呢?

这时开始怀疑是cpu寄存器状态的问题,比如页寄存器、比如中断位这些。通过比较异常和正常时的寄存器差异,发现正常时eflags寄存器的第19位是1,而异常时是0。通过写测试程序验证,最后定位下来是vm壳对eflags的这个标志位处理有问题,而之前的系统一直是没有使用eflags的高位的,从win10 1903开始才使用,这个问题才暴露。

解决

找到了问题修正vm引擎其实没花多少时间,但还是去值得了解下eflags寄存器的第19位是干嘛的。

在这里插入图片描述
第19位是VIF位,查询intel手册,这个位是否启用受到CR4寄存器PVI (Protected-Mode Virtual Interrupts)位的控制,大概作用是一个保护模式策略。对这个标记位网站的介绍如下:

20.4 PROTECTED-MODE VIRTUAL INTERRUPTSThe IA-32 processors (beginning with the Pentium processor) also support the VIF and VIP flags in the EFLAGS
register in protected mode by setting the PVI (protected-mode virtual interrupt) flag in the CR4 register. Setting
the PVI flag allows applications running at privilege level 3 to execute the CLI and STI instructions without causing
a general-protection exception (#GP) or affecting hardware interrupts.
When the PVI flag is set to 1, the CPL is 3, and the IOPL is less than 3, the STI and CLI instructions set and clear
the VIF flag in the EFLAGS register, leaving IF unaffected. In this mode of operation, an application running in
protected mode and at a CPL of 3 can inhibit interrupts in the same manner as is described in Section 20.3.2, “Class
2—Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanism”, for a
virtual-8086 mode task. When the application executes the CLI instruction, the processor clears the VIF flag. If the
processor receives a maskable hardware interrupt, the processor invokes the protected-mode interrupt handler.
This handler checks the state of the VIF flag in the EFLAGS register. If the VIF flag is clear (indicating that the active
task does not want to have interrupts handled now), the handler sets the VIP flag in the EFLAGS image on the stack
and returns to the privilege-level 3 application, which continues program execution. When the application executes
a STI instruction to set the VIF flag, the processor automatically invokes the general-protection exception handler,
which can then handle the pending interrupt. After handing the pending interrupt, the handler typically sets the VIF
flag and clears the VIP flag in the EFLAGS image on the stack and executes a return to the application program. The
next time the processor receives a maskable hardware interrupt, the processor will handle it in the normal manner
for interrupts received while the processor is operating at a CPL of 3.
As with the virtual mode extension (enabled with the VME flag in the CR4 register), the protected-mode virtual
interrupt extension only affects maskable hardware interrupts (interrupt vectors 32 through 255). NMI interrupts
and exceptions are handled in the normal manner.
When protected-mode virtual interrupts are disabled (that is, when the PVI flag in control register CR4 is set to 0,
the CPL is less than 3, or the IOPL value is 3), then the CLI and STI instructions execute in a manner compatible
with the Intel486 processor. That is, if the CPL is greater (less privileged) than the I/O privilege level (IOPL), a
general-protection exception occurs. If the IOPL value is 3, CLI and STI clear or set the IF flag, respectively.
PUSHF, POPF, IRET and INT are executed like in the Intel486 processor, regardless of whether protected-mode
virtual interrupts are enabled.
It is only possible to enter virtual-8086 mode through a task switch or the execution of an IRET instruction, and it
is only possible to leave virtual-8086 mode by faulting to a protected-mode interrupt handler (typically the general-
protection exception handler, which in turn calls the virtual 8086-mode monitor). In both cases, the EFLAGS
register is saved and restored. This is not true, however, in protected mode when the PVI flag is set and the
processor is not in virtual-8086 mode. Here, it is possible to call a procedure at a different privilege level, in which
case the EFLAGS register is not saved or modified. However, the states of VIF and VIP flags are never examined by
the processor when the CPL is not 3.
参考文献: https://xem.github.io/minix86/manual/intel-x86-and-64-manual-vol3/o_fe12b1e2a880e0ce-996.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: Win10x64LTSB2016极限精简版by双心是一款基于Windows 10企业版LTSB 2016版本的极限精简系统。该系统的最大特点就是极限精简,删除了大量的Windows自带软件及服务,只保留了核心的系统功能和必要的功能软件。 该系统的好处是能够提高系统的性能和稳定性,减少系统崩溃和蓝屏的情况,降低系统资源的占用率。同时也加快了系统的启动和关闭速度,提高了系统的运行速度和响应速度。 Win10x64LTSB2016极限精简版by双心还带有一些实用的软件和工具,如CCleaner、WinRAR、PotPlayer、Bandizip等,方便用户的使用。 不过需要注意的是,由于该系统进行了极限精简,可能会对一些软件的兼容性产生影响,需要提前检查系统的兼容性后再安装软件使用。此外,该系统也没有自带语言包,需要手动安装语言包后才能进行中文使用。 总的来说,Win10x64LTSB2016极限精简版by双心是一款适合对系统要求高的用户使用的系统,具有较高的性能和稳定性,同时也提供了一些实用的软件和工具方便用户的使用。 ### 回答2: win10x64ltsb2016极限精简版by双心是一款基于Windows 10企业版LTSB 2016的操作系统精简版。此版本保留了Windows 10的核心功能,同时剔除了一些不必要的预装应用程序和服务,从而提高了系统的稳定性和性能。 此版本的双心是一个知名的系统优化大师,对系统的优化和升级有丰富的经验。他在原版Windows 10企业版LTSB 2016的基础上,加入了一些优化和升级的操作,使得系统更加流畅和快速。此版本去掉了较多预装的应用程序和服务,如OneDrive、Edge浏览器、语音识别、Windows Defender、Windows Store等,从而缩小系统的体积,节省了硬盘空间。 此版本由于去掉了许多与多媒体和游戏有关的组件,更加适合专业人士和企业用户使用。它支持 DirectX12,可以满足 CAD、影视制作等专业应用的需求。并且,此版本的系统自带了Office 2016企业版,大大方便了用户的工作和学习。 总之,win10x64ltsb2016极限精简版by双心是一款优化精细、功能完备的精简版操作系统,适合需要高性能、快速应用的专业人士和企业用户使用。 ### 回答3: win10x64ltsb2016极限精简版by双心是一款经过极限精简处理的Windows 10操作系统,该操作系统采用了微软的LTSB(长期服务分支)版本,是一款具有稳定性和安全性的操作系统。这款操作系统经过双心压缩技术的处理,其压缩比可以达到45%以上,大大降低了系统占用的硬盘空间,同时还具有一定的优化性能。 该系统在精简的基础上增加了许多实用的工具和软件,例如CCleaner、解压缩软件、虚拟光驱等,方便用户使用。与此同时,该系统还支持中文语言,并且采用了极简的启动画面和桌面界面,非常清新简洁。该系统还增加了各种驱动程序和系统补丁,使得系统更加稳定高效。 总之,win10x64ltsb2016极限精简版by双心是一款优秀的Windows 10操作系统,其对系统进行了极限精简处理,大大提高了系统的运行效率和稳定性。与此同时,其增加了许多实用的工具和软件,让用户的使用更加方便。该系统极简的外观设计也非常适合那些追求简洁、高效、稳定的用户。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值