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
Copy file name to clipboardExpand all lines: tools/dv/kmdf/fail_driver_pool_leak/README.md
+24-19Lines changed: 24 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,28 @@
1
-
# Fail_Driver_Pool_Leak Sample
1
+
# Fail_Driver_Pool_Leak Sample Driver
2
2
3
-
This sample KMDF Fail Driver demonstrates the capabilities and features of **Driver Verifier** and the **Device Fundamentals Tests**.
3
+
This sample KMDF Fail Driver is designed to demonstrate the capabilities and features of **Driver Verifier** and the **Device Fundamentals Tests** for a driver written in Rust.
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.
5
+
The driver allocates a pool of memory to a global buffer in its `evt_driver_device_add` function when a supported device is added by the PnP Manager. The driver intentionally does not free it anywhere, even in the `evt_driver_unload` callback, which get called before the driver is unloaded. This memory leak fault is a system vulnerability that could lead to security and performance issues and ultimately a bad user experience.
6
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.
7
+
By enabling Driver Verifier on a driver, such violations can be caught and mitigated early in the development cycle. With an active KDNET session, the bugcheck can be analyzed further using WinDbg. The steps listed below demonstrate how to build, deploy, enable Driver Verifier, run Device Fundamentals Tests and debug the driver.
8
8
9
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
10
11
-
12
11
## Steps to reproduce the issue
13
12
14
13
1. Clone the repository and navigate to the project root.
15
14
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
22
```
18
23
cargo make
19
24
```
20
-
3. Prepare a target system (a Hyper-V VM can be used) for testing
25
+
4. Prepare a target system (a Hyper-V VM can be used) for testing
21
26
22
27
Follow the below steps to setup the test system -
23
28
1. Disable Secure boot and start the system
@@ -37,11 +42,11 @@ NOTE: The driver uses WDM's ExAllocatePool2 API directly to allocate memory for
37
42
shutdown -r -t 0
38
43
```
39
44
40
-
4. Copy the driver package, available under ".\target\debug\fail_driver_pool_leak_package" to the target system.
45
+
5. Copy the driver package, available under ".\target\debug\fail_driver_pool_leak_package" to the target system.
41
46
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.
47
+
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
48
44
-
6. Install the driver package and create the device in the target system using the below commands -
49
+
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
58
+
8. Enable Driver Verifier for 'fail_driver_pool_leak.sys' driver package
54
59
1. Open run command prompt (Start + R) or cmd as administator and run "verifier"
55
60
2. In the verifier manager,
56
61
- Create Standard Settings
@@ -59,23 +64,23 @@ NOTE: The driver uses WDM's ExAllocatePool2 API directly to allocate memory for
59
64
- Finish
60
65
- Restart the system
61
66
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
67
+
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
68
64
-
9. Install TAEF and WDTF on the test computer and run the following test -
69
+
10. Install TAEF and WDTF on the test computer and run the following test -
65
70
```
66
71
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 -
75
+
11. The test will lead to a Bugcheck and a BlueScreen on the target system with the following error -
71
76
```
72
77
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.
78
+
```
79
+
Run ```!analyze -v``` for detailed bugcheck report
80
+
81
+
Run ```!verifier 3 fail_driver_pool_leak.sys``` for info on the allocations that were leaked that caused the bugcheck.
77
82
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.
83
+
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
84
You may use pnputil/devcon to enumerate and remove the devices -
0 commit comments