Skip to content

Commit b9aa8bb

Browse files
authored
fix: update Fail_Driver_Pool_Leak's device class and use --sample flag (#33)
2 parents 0a3a3cd + 5b1c070 commit b9aa8bb

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,4 @@ jobs:
9292
run: cargo +${{ matrix.rust_toolchain }} install --git https://github.com/microsoft/windows-drivers-rs.git cargo-wdk --branch main --rev 5b9aa0a14e385daf5217c0f5232bcd4d3f4780a6 --locked --force
9393

9494
- name: Build and Package Sample Drivers with cargo-wdk
95-
run: cargo +${{ matrix.rust_toolchain }} wdk build --profile ${{ matrix.cargo_profile }} --target-arch ${{ matrix.target_triple.arch }}
96-
continue-on-error: true # cargo-wdk build fails for a known reason
95+
run: cargo +${{ matrix.rust_toolchain }} wdk build --sample --profile ${{ matrix.cargo_profile }} --target-arch ${{ matrix.target_triple.arch }}
Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
# Fail_Driver_Pool_Leak Sample
1+
# Fail_Driver_Pool_Leak Sample Driver
22

3-
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.
44

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
136

147
1. Clone the repository and navigate to the project root.
158

16-
2. Build the driver project using the following command in a WDK environment (or EWDK prompt) -
9+
2. Install [Clang](https://clang.llvm.org/get_started.html)
10+
* Easy install option:
11+
```
12+
winget install LLVM.LLVM
13+
```
14+
15+
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) -
1716
```
1817
cargo make
1918
```
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
2120
2221
Follow the below steps to setup the test system -
2322
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
3736
shutdown -r -t 0
3837
```
3938
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.
4140
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.
4342
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 -
4544
```
4645
cd "fail_driver_pool_leak_package"
4746
devgen.exe /add /bus ROOT /hardwareid "fail_driver_pool_leak"
@@ -50,7 +49,7 @@ NOTE: The driver uses WDM's ExAllocatePool2 API directly to allocate memory for
5049
5150
pnputil.exe /add-driver .\fail_driver_pool_leak.inf /install
5251
```
53-
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
5453
1. Open run command prompt (Start + R) or cmd as administator and run "verifier"
5554
2. In the verifier manager,
5655
- Create Standard Settings
@@ -59,23 +58,23 @@ NOTE: The driver uses WDM's ExAllocatePool2 API directly to allocate memory for
5958
- Finish
6059
- Restart the system
6160
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
6362
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 -
6564
```
6665
cd "C:\Program Files (x86)\Windows Kits\10\Testing\Tests\Additional Tests\x64\DevFund"
6766
TE.exe .\Devfund_PnPDTest_WLK_Certification.dll /P:"DQ=DeviceID='ROOT\DEVGEN\{PASTE-DEVICE-ID-HERE}'" --rebootResumeOption:Manual
6867
```
6968
70-
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 -
7170
```
7271
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.
7776
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.
7978
You may use pnputil/devcon to enumerate and remove the devices -
8079
```
8180
# To enumerate the devices
@@ -86,9 +85,8 @@ NOTE: The driver uses WDM's ExAllocatePool2 API directly to allocate memory for
8685
8786
### References
8887
89-
- [Driver Verifier](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/driver-verifier)
90-
- [Device Fundamentals Tests](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/device-fundamentals-tests)
9188
- [TAEF](https://learn.microsoft.com/en-us/windows-hardware/drivers/taef/getting-started)
9289
- [WDTF](https://learn.microsoft.com/en-us/windows-hardware/drivers/wdtf/wdtf-runtime-library)
9390
- [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)
9491
- [Using WDF to Develop a Driver](https://learn.microsoft.com/en-us/windows-hardware/drivers/wdf/using-the-framework-to-develop-a-driver)
92+
- [wdfmemory](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdfmemory/)

tools/dv/kmdf/fail_driver_pool_leak/fail_driver_pool_leak.inx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
[Version]
99
Signature = "$WINDOWS NT$"
10-
Class = SoftwareComponent
11-
ClassGuid = {5c4c3332-344d-483c-8739-259e934c9cc8}
10+
Class = Sample
11+
ClassGuid = {78A1C341-4539-11d3-B88D-00C04FAD5171}
1212
Provider = %ProviderString%
1313
PnpLockDown = 1
1414

0 commit comments

Comments
 (0)