Non-zero Code Integrity statistic found: Execute Pool Type Count

這是跑HLK HyperVisor Code Integrity Readiness Test中的錯誤:

問題是Windows在Win8後基於安全性考量,建議將NonPagedPool改為使用NonPagedPoolNx。本篇文章主要分享我的改法。

Note. 我的方法儘以解決問題為目的,可能非最佳解。

由於我的情況不需要使用到Executable nonpaged pool,因此只需要將NonPagedPool改為NonPagedPoolNx即可。此外還有以下幾點要考慮:

  1. WDK是6000,因此某些Macro要自己宣告。
  2. NonPagedPoolNx為win8以後才支援,但我們又要共用同一隻driver,因此code要針對版本做處理。

#define NonPagedPoolNx 512 
#define NTDDI_WIN8 0x06020000
 
int getNonPagePoolNx(){
	// Win8 later
	if( RtlIsNtDdiVersionAvailable(NTDDI_WIN8) ) {
		return NonPagedPoolNx;
	}
	return NonPagedPool;
}
假如系統版本大於等於Win8,我就會使用NonPagedPoolNx;反之則使用NonPagedPool。Client code如下:
pci_bus_interface=(PCI_BUS_INTERFACE)ExAllocatePool(getNonPagePoolNx(),
		sizeof(PCI_BUS_INTERFACE));
使用這個方式後,在Windows 2008與Windows 2016都可以正常使用,且測試會通過。