You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This sample KMDF Fail Driver demonstrates the capabilities and features of **Driver Verifier**and the **Device Fundamentals Tests**.
3
+
The `fail_driver_pool_leak`sample demonstrates running the [Device Fundamentals Tests](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/device-fundamentals-tests) and enabling the [Driver Verifier](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/driver-verifier) for a Rust driver. We have intentionally injected a pool leak fault in the driver by allocating a global buffer using WDM's `ExAllocatePool2` function and not freeing this buffer (using `ExFreePool`) anywhere in the driver. This fault, which is not caught at compile time, can be detected by running the Device Fundamentals Tests and also by enabling the Driver Verifier on the driver.
4
4
5
-
It allocates a pool of memory to a global buffer when a supported device is added by the PnP Manager and intentionally does not free it before the driver is unloaded. This memory leak fault is a system vulnerability that could lead to security and performance issues and bad user experience.
6
-
7
-
By enabling Driver Verifier on this driver, this pool leak violation can be caught before the driver is unloaded and with an active KDNET session, the bug can be analyzed further.
8
-
9
-
NOTE: The driver uses WDM's ExAllocatePool2 API directly to allocate memory for its buffer. Ideally, such allocations should be freed by using ExFreePool API. A cleaner way to manage memory in a WDF Driver is to use [wdfmemory](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdfmemory/)
10
-
11
-
12
-
## Steps to reproduce the issue
5
+
## Steps
13
6
14
7
1. Clone the repository and navigate to the project root.
15
8
16
-
2. Build the driver project using the following command in a WDK environment (or EWDK prompt) -
3. Build the driver project using the following command in an [EWDK environment](https://learn.microsoft.com/en-us/legal/windows/hardware/enterprise-wdk-license-2022) -
17
16
```
18
17
cargo make
19
18
```
20
-
3. Prepare a target system (a Hyper-V VM can be used) for testing
19
+
4. Prepare a target system (a Hyper-V VM can be used) for testing
21
20
22
21
Follow the below steps to setup the test system -
23
22
1. Disable Secure boot and start the system
@@ -37,11 +36,11 @@ NOTE: The driver uses WDM's ExAllocatePool2 API directly to allocate memory for
37
36
shutdown -r -t 0
38
37
```
39
38
40
-
4. Copy the driver package, available under ".\target\debug\fail_driver_pool_leak_package" to the target system.
39
+
5. Copy the driver package, available under ".\target\debug\fail_driver_pool_leak_package" to the target system.
41
40
42
-
5. Copy "devgen.exe" from host to the target system. Alternatively you may install WDK on the target system and add the directory that contains "devgen.exe" to PATH variable.
41
+
6. Copy "devgen.exe" from host to the target system. Alternatively you may install WDK on the target system and add the directory that contains "devgen.exe" to PATH variable.
43
42
44
-
6. Install the driver package and create the device in the target system using the below commands -
43
+
7. Install the driver package and create the device in the target system using the below commands -
7. Enable Driver Verifier for 'fail_driver_pool_leak.sys' driver package
52
+
8. Enable Driver Verifier for 'fail_driver_pool_leak.sys' driver package
54
53
1. Open run command prompt (Start + R) or cmd as administator and run "verifier"
55
54
2. In the verifier manager,
56
55
- Create Standard Settings
@@ -59,23 +58,23 @@ NOTE: The driver uses WDM's ExAllocatePool2 API directly to allocate memory for
59
58
- Finish
60
59
- Restart the system
61
60
62
-
8. Follow the steps in https://learn.microsoft.com/en-us/windows-hardware/drivers/develop/how-to-test-a-driver-at-runtime-from-a-command-prompt to run tests against the device managed by this driver
61
+
9. Follow the steps in https://learn.microsoft.com/en-us/windows-hardware/drivers/develop/how-to-test-a-driver-at-runtime-from-a-command-prompt to run tests against the device managed by this driver
63
62
64
-
9. Install TAEF and WDTF on the test computer and run the following test -
63
+
10. Install TAEF and WDTF on the test computer and run the following test -
65
64
```
66
65
cd "C:\Program Files (x86)\Windows Kits\10\Testing\Tests\Additional Tests\x64\DevFund"
10. The test will lead to a Bugcheck and a BlueScreen on the target system with the following error -
69
+
11. The test will lead to a Bugcheck and a BlueScreen on the target system with the following error -
71
70
```
72
71
DRIVER_VERIFIER_DETECTED_VIOLATION (c4)
73
-
```
74
-
The logs will be available in WinDbg
75
-
run ```!analyze -v``` for detailed bugcheck report
76
-
run ```!verifier 3 fail_driver_pool_leak.sys``` for info on the allocations that were leaked that caused the bugcheck.
72
+
```
73
+
Run ```!analyze -v``` for detailed bugcheck report
74
+
75
+
Run ```!verifier 3 fail_driver_pool_leak.sys``` for info on the allocations that were leaked that caused the bugcheck.
77
76
78
-
11. (Alternatively), the bugcheck can be observed when all the devices managed by this driver are removed, i.e, when the driver is unloaded from the system.
77
+
12. (Alternatively), the bugcheck can be observed when all the devices managed by this driver are removed, i.e, when the driver is unloaded from the system.
79
78
You may use pnputil/devcon to enumerate and remove the devices -
80
79
```
81
80
# To enumerate the devices
@@ -86,9 +85,8 @@ NOTE: The driver uses WDM's ExAllocatePool2 API directly to allocate memory for
- [Testing a driver at runtime](https://learn.microsoft.com/en-us/windows-hardware/drivers/develop/how-to-test-a-driver-at-runtime-from-a-command-prompt)
94
91
- [Using WDF to Develop a Driver](https://learn.microsoft.com/en-us/windows-hardware/drivers/wdf/using-the-framework-to-develop-a-driver)
0 commit comments