Skip to content

Commit

Permalink
Updated README, added lint attributes to suppress clippy warns, fixed…
Browse files Browse the repository at this point in the history
… docs, updated buffer length to use const
  • Loading branch information
svasista-ms committed Sep 23, 2024
1 parent 80ecde4 commit 008230d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions tools/dv/samples/kmdf/pool_leak/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Driver Verifier Pool Leak Sample

This KMDF sample contains an intentional error that demonstrates the capabilities and features of Driver Verifier and the Device Fundamental tests.
This KMDF sample contains an intentional error that demonstrates the capabilities and features of Driver Verifier and the Device Fundamentals tests.

The driver uses WDM's ExAllocatePool2 API to allocate memory in its Device Context buffer when a device is added by the PnP manager. However, this buffer is not freed anywhere in the driver, including the driver unload function.

By enabling the Driver Verifier on this driver, the pool leak violation can be caught when the driver is unloaded and with an active KDNET session, the bug can be analyzed further.
By enabling Driver Verifier on this driver, the pool leak violation can be caught when the driver is unloaded and with an active KDNET session, the bug can be analyzed further.

## Steps to Reproduce the issue

Expand Down Expand Up @@ -48,7 +48,7 @@ By enabling the Driver Verifier on this driver, the pool leak violation can be c
pnputil.exe /add-driver .\pool_leak.inf /install
```
7. Enable Driver Verifier for 'pool_leak.sys' driver package
1. Open run command promt (Start + R) or cmd as administator and run "verifier"
1. Open run command prompt (Start + R) or cmd as administator and run "verifier"
2. In the verifier manager,
- Create Standard Settings
- Select driver names from list
Expand Down
5 changes: 3 additions & 2 deletions tools/dv/samples/kmdf/pool_leak/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ extern "C" fn evt_driver_device_add(

println!("Enter: EchoEvtDeviceAdd");

#[allow(clippy::cast_possible_truncation)]
let mut attributes = WDF_OBJECT_ATTRIBUTES {
Size: core::mem::size_of::<WDF_OBJECT_ATTRIBUTES>() as ULONG,
ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent,
Expand Down Expand Up @@ -153,9 +154,9 @@ extern "C" fn evt_driver_device_add(
// it will return NULL and assert if run under framework verifier mode.
let device_context = unsafe { wdf_object_get_device_context(device as WDFOBJECT) };
unsafe {
let length: usize = 64;
const LENGTH: usize = 64;
(*device_context).buffer =
ExAllocatePool2(POOL_FLAG_NON_PAGED, length as SIZE_T, 's' as u32);
ExAllocatePool2(POOL_FLAG_NON_PAGED, LENGTH as SIZE_T, 's' as u32);
}

nt_status = unsafe {
Expand Down
7 changes: 4 additions & 3 deletions tools/dv/samples/kmdf/pool_leak/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

//! # Abstract
//!
//! This KMDF sample contains an intentional error that is designed to
//! This KMDF sample contains an intentional error that is designed to
//! demonstrate the capabilities and features of Driver Verifier and the Device
//! Fundamental tests.
//!
//! The driver is desgined to allocate memory using ExAllocatePool2 to its
//! The driver is designed to allocate memory using ExAllocatePool2 to its
//! Device Context buffer when a device is added by the PnP manager. However,
//! this buffer is not freed anywhere in the driver, including the driver unload
//! function.
//!
//! By enabling the Driver Verifier on this driver, the pool leak
//! By enabling Driver Verifier on this driver, the pool leak
//! violation can be caught when the driver is unloaded and with an active KDNET
//! session, the bug can be analyzed further.
Expand All @@ -23,6 +23,7 @@
#![warn(clippy::nursery)]
#![warn(clippy::cargo)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::doc_markdown)]

#[cfg(not(test))]
extern crate wdk_panic;
Expand Down
3 changes: 3 additions & 0 deletions tools/dv/samples/kmdf/pool_leak/src/wdf_object_context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// License: MIT OR Apache-2.0

#![allow(clippy::ref_as_ptr)]
use wdk_sys::{PCWDF_OBJECT_CONTEXT_TYPE_INFO, WDF_OBJECT_CONTEXT_TYPE_INFO};

#[repr(transparent)]
Expand Down Expand Up @@ -38,6 +39,8 @@ macro_rules! wdf_declare_context_type_with_name {
type [<WDFPointerType$context_type>] = *mut $context_type;

#[link_section = ".data"]
#[allow(clippy::ptr_as_ptr)]
#[allow(clippy::cast_possible_truncation)]
pub static [<WDF_ $context_type:snake:upper _TYPE_INFO>]: crate::wdf_object_context::WDFObjectContextTypeInfo = crate::wdf_object_context::WDFObjectContextTypeInfo::new(WDF_OBJECT_CONTEXT_TYPE_INFO {
Size: core::mem::size_of::<WDF_OBJECT_CONTEXT_TYPE_INFO>() as ULONG,
ContextName: concat!(stringify!($context_type),'\0').as_bytes().as_ptr().cast(),
Expand Down

0 comments on commit 008230d

Please sign in to comment.