From 008230d2781bc00cc77129161a7056ee2f999ed2 Mon Sep 17 00:00:00 2001 From: Shravan Vasista Date: Sun, 22 Sep 2024 23:11:07 -0700 Subject: [PATCH] Updated README, added lint attributes to suppress clippy warns, fixed docs, updated buffer length to use const --- tools/dv/samples/kmdf/pool_leak/README.md | 6 +++--- tools/dv/samples/kmdf/pool_leak/src/driver.rs | 5 +++-- tools/dv/samples/kmdf/pool_leak/src/lib.rs | 7 ++++--- tools/dv/samples/kmdf/pool_leak/src/wdf_object_context.rs | 3 +++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/dv/samples/kmdf/pool_leak/README.md b/tools/dv/samples/kmdf/pool_leak/README.md index d26c1c0..057d396 100644 --- a/tools/dv/samples/kmdf/pool_leak/README.md +++ b/tools/dv/samples/kmdf/pool_leak/README.md @@ -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 @@ -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 diff --git a/tools/dv/samples/kmdf/pool_leak/src/driver.rs b/tools/dv/samples/kmdf/pool_leak/src/driver.rs index 1c6f069..02abfbb 100644 --- a/tools/dv/samples/kmdf/pool_leak/src/driver.rs +++ b/tools/dv/samples/kmdf/pool_leak/src/driver.rs @@ -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::() as ULONG, ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent, @@ -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 { diff --git a/tools/dv/samples/kmdf/pool_leak/src/lib.rs b/tools/dv/samples/kmdf/pool_leak/src/lib.rs index e24de01..d42df0c 100644 --- a/tools/dv/samples/kmdf/pool_leak/src/lib.rs +++ b/tools/dv/samples/kmdf/pool_leak/src/lib.rs @@ -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. @@ -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; diff --git a/tools/dv/samples/kmdf/pool_leak/src/wdf_object_context.rs b/tools/dv/samples/kmdf/pool_leak/src/wdf_object_context.rs index ba91e54..90f8ad2 100644 --- a/tools/dv/samples/kmdf/pool_leak/src/wdf_object_context.rs +++ b/tools/dv/samples/kmdf/pool_leak/src/wdf_object_context.rs @@ -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)] @@ -38,6 +39,8 @@ macro_rules! wdf_declare_context_type_with_name { type [] = *mut $context_type; #[link_section = ".data"] + #[allow(clippy::ptr_as_ptr)] + #[allow(clippy::cast_possible_truncation)] pub static []: crate::wdf_object_context::WDFObjectContextTypeInfo = crate::wdf_object_context::WDFObjectContextTypeInfo::new(WDF_OBJECT_CONTEXT_TYPE_INFO { Size: core::mem::size_of::() as ULONG, ContextName: concat!(stringify!($context_type),'\0').as_bytes().as_ptr().cast(),