Skip to content

Commit cc7c4ba

Browse files
authored
Merge branch 'development' into user/nated-msft/pack-requirement-updates
2 parents d6083b4 + a303afd commit cc7c4ba

114 files changed

Lines changed: 3324 additions & 217 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
# Windows Driver Developer Supplemental Tools
2-
32
This repository contains open-source components for supplemental use in developing device drivers for Windows, as well as driver specific [CodeQL](https://codeql.github.com/) query suites used for the [Windows Hardware Compatibility Program](https://learn.microsoft.com/en-us/windows-hardware/design/compatibility/). The quickstart below will get you set up to build your database and analyze your driver using CodeQL. For the full documentation, troubleshooting, and more details about the Static Tools Logo test within the WHCP Program, please visit [CodeQL and the Static Tools Logo Test](https://docs.microsoft.com/windows-hardware/drivers/devtest/static-tools-and-codeql).
43

5-
### For General Use or Windows Hardware Compatibility Program Use
6-
4+
### For General Use
75
| CodeQL CLI Version | microsoft/windows-drivers CodeQL Pack Version | microsoft/cpp-queries CodeQL Pack Version | Associated Repo Branch|
86
|--------------------------|------------------------------------------|-------------------------------|-----------------------------|
9-
| 2.15.4 or greater* | [Latest Stable Version](https://github.com/microsoft/Windows-Driver-Developer-Supplemental-Tools/pkgs/container/windows-drivers) | 0.0.4 | Main |
7+
| 2.24.1 or greater* | [Latest Stable Version](https://github.com/microsoft/Windows-Driver-Developer-Supplemental-Tools/pkgs/container/windows-drivers) | 0.0.4 | Main |
108

11-
#### Validated CodeQL Versions For Use with WHCP
12-
| CodeQL CLI Version |
13-
|--------------------------|
14-
| 2.23.3 |
15-
| 2.21.4 |
16-
| 2.21.2 |
17-
| 2.20.1 |
18-
| 2.15.4 |
199

2010
When using the precompiled pack, please use the most recent CodeQL CLI version listed above.
2111

22-
*See appendix for more information
12+
### For WHCP Use (26H1)
13+
| CodeQL CLI Version | microsoft/windows-drivers CodeQL Pack Version | microsoft/cpp-queries CodeQL Pack Version | Associated Repo Branch|
14+
|--------------------------|------------------------------------------|-------------------------------|-----------------------------|
15+
| 2.24.1 | [1.8.2](https://github.com/microsoft/Windows-Driver-Developer-Supplemental-Tools/pkgs/container/windows-drivers/655126590?tag=1.8.2) | 0.0.4 | Main |
16+
17+
See appendix for information on CLI+query version combinations for previous Windows releases and WHCP programs.
2318

24-
### For Testing the Latest in Development
2519

20+
### For Testing the Latest in Development
2621
| CodeQL CLI Version | microsoft/windows-drivers CodeQL Pack Version | microsoft/cpp-queries CodeQL Pack Version | Associated Repo Branch|
2722
|--------------------------|------------------------------------------|-------------------------------|-----------------------------|
2823
| [Latest](https://github.com/github/codeql-cli-binaries/releases/latest) | [Latest Beta Version](https://github.com/microsoft/Windows-Driver-Developer-Supplemental-Tools/pkgs/container/windows-drivers) | [Latest](https://github.com/orgs/microsoft/packages/container/package/cpp-queries) | Development |
2924

3025
## Quickstart
31-
3226
1. Create a directory where you can place the CodeQL CLI and the queries you want to use:
3327
```
3428
mkdir codeql-home
@@ -98,9 +92,7 @@ Windows drivers queries are in the `src/drivers` directory.
9892
9993
Non-driver Microsoft-specific queries provided by Microsoft are in the `src/microsoft` directory.
10094
101-
Query suites are located in the `windows-driver-suites` directory and contain the Must-Fix and Recommended suites used by the WHCP Program.
102-
103-
95+
Query suites are located in the `windows-driver-suites` directory and contain the Must-Fix, Must-Run, and Recommended suites used by the WHCP Program.
10496
10597
## Contributing
10698
This project welcomes contributions, feedback, and suggestions!
@@ -114,6 +106,7 @@ We are in the process of setting up pull request checks, but to ensure our requi
114106
1. Add a .qhelp file for any new queries or update the existing one if there is new functionality for the end user.
115107
116108
#### Note
109+
117110
All "Must-Fix" suite queries must have been run on the Windows Drivers Samples, and any bugs found as a result must be filed prior to being merged into the suite.
118111
119112
Most contributions require you to agree to a
@@ -150,7 +143,16 @@ The versions below are the minumum required versions for WHCP certification. New
150143
| Windows 11, version 24H2 | [2.15.4](https://github.com/github/codeql-cli-binaries/releases/tag/v2.15.4) | 1.1.0 | N/A |0.9.0 | WHCP_24H2 |
151144
| Windows Server 2025 | [2.20.1](https://github.com/github/codeql-cli-binaries/releases/tag/v2.20.1) | 1.8.0 | 0.0.4 | N/A | WHCP_25H2 |
152145
| Windows 11, version 25H2 | [2.20.1](https://github.com/github/codeql-cli-binaries/releases/tag/v2.20.1) | 1.8.0 | 0.0.4 | N/A | WHCP_25H2 |
146+
| Windows 11, version 26H1 | [2.24.1](https://github.com/github/codeql-cli-binaries/releases/tag/v2.24.1) | 1.8.2 | 0.0.4 | N/A | WHCP_26H1 |
153147
148+
#### Previously validated CodeQL Versions For Use with WHCP
149+
| CodeQL CLI Version |
150+
|--------------------------|
151+
| 2.23.3 |
152+
| 2.21.4 |
153+
| 2.21.2 |
154+
| 2.20.1 |
155+
| 2.15.4 |
154156
155157
### Special instructions for for WHCP_21H2 and WHCP_22H2 branches:
156158
Visual Studio 17.8 broke compatibility with the older versions of CodeQL used in the WHCP_21H2 and WHCP_22H2 branches. [CodeQL CLI version 2.15.4](https://github.com/github/codeql-cli-binaries/releases/tag/v2.15.4) has been validated for use with WHCP 21H2 and WHCP 22H2 when using Visual Studio 17.8 or greater.
@@ -165,11 +167,8 @@ Visual Studio 17.8 broke compatibility with the older versions of CodeQL used in
165167
Follow special instructions for WHCP_21H2 and WHCP_22H2 using VS17.7 at the end of this readme
166168
167169
### Special instructions for WHCP_21H2 and WHCP_22H2 using VS17.7 or below
168-
169-
170170
These instructions only apply when using both Visual Studio 17.7 or below along with CodeQL 2.6.3 or 2.4.6
171171
172-
173172
1. Install CodeQL version as indicated in above steps.
174173
175174
1.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# UnsafeCallInGlobalInit
2+
When using a DLL, it is frequently the case that any static construtors are called from DllMain. There are a number of constraints that apply to calling other functions from DllMain. In particular, it is possible to create memory leaks if the DLL is loaded and unloaded dynamically. SysAllocString is an example of a function that, in this case, could cause a memory leak.
3+
4+
5+
## Recommendation
6+
The ideal DllMain would be just an empty stub. However, given the complexity of many applications, this is generally too restrictive. A good rule of thumb for DllMain is to postpone as much initialization as possible. Lazy initialization increases robustness of the application because this initialization is not performed while the loader lock is held. Also, lazy initialization enables you to safely use much more of the Windows API.
7+
8+
9+
## Example
10+
DLLMain function
11+
12+
```c
13+
14+
BOOL WINAPI DllMain(
15+
HINSTANCE hinstDLL, // handle to DLL module
16+
DWORD fdwReason, // reason for calling function
17+
LPVOID lpvReserved ) // reserved
18+
{
19+
// Perform actions based on the reason for calling.
20+
switch( fdwReason )
21+
{
22+
case DLL_PROCESS_ATTACH:
23+
// Initialize once for each new process.
24+
// Return FALSE to fail DLL load.
25+
break;
26+
27+
case DLL_THREAD_ATTACH:
28+
// Do thread-specific initialization.
29+
break;
30+
31+
case DLL_THREAD_DETACH:
32+
// Do thread-specific cleanup.
33+
break;
34+
35+
case DLL_PROCESS_DETACH:
36+
37+
if (lpvReserved != nullptr)
38+
{
39+
break; // do not do cleanup if process termination scenario
40+
}
41+
42+
// Perform any necessary cleanup.
43+
break;
44+
}
45+
return TRUE; // Successful DLL_PROCESS_ATTACH.
46+
}
47+
48+
```
49+
50+
## References
51+
* [ C28637 ](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28637-calling-function-in-a-global-initializer-is-unsafe)

src/drivers/apps/queries/experimental/UnsafeCallInGlobalInit/UnsafeCallInGlobalInit.qhelp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,9 @@
4747
break;
4848
}
4949
return TRUE; // Successful DLL_PROCESS_ATTACH.
50-
}
5150
}]]>
52-
51+
</sample>
5352
</example>
54-
<semmleNotes>
55-
<p>
56-
57-
</p>
58-
</semmleNotes>
5953
<references>
6054
<li>
6155
<a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28637-calling-function-in-a-global-initializer-is-unsafe">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Driver alert suppression
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Annotation syntax error
2+
A syntax error in the annotations was found for the property in the function.
3+
4+
5+
## Recommendation
6+
This warning indicates an error in the annotations, not in the code that is being analyzed.
7+
8+
9+
## Example
10+
_IRQL_saves_global_ not applied to entire function
11+
12+
```c
13+
14+
// FAIL
15+
VOID test1(
16+
_IRQL_saves_global_(OldIrql, *Irql) PKIRQL Irql)
17+
{
18+
// ...
19+
;
20+
}
21+
22+
```
23+
_Kernel_clear_do_init_ not used with either "yes" or "no"
24+
25+
```c
26+
27+
// FAIL
28+
_Function_class_(DRIVER_ADD_DEVICE)
29+
_IRQL_requires_(PASSIVE_LEVEL)
30+
_IRQL_requires_same_
31+
_Kernel_clear_do_init_(IRP_MJ_CREATE)
32+
NTSTATUS
33+
test4(
34+
_In_ PDRIVER_OBJECT DriverObject,
35+
_In_ PDEVICE_OBJECT PhysicalDeviceObject)
36+
37+
{
38+
; // do nothing
39+
}
40+
41+
```
42+
43+
## References
44+
* [ C28266 ](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28266-function-property-syntax-error)

src/drivers/general/queries/AnnotationSyntax/AnnotationSyntax.qhelp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
{
2222
// ...
2323
;
24-
}
2524
}]]>
2625
</sample>
2726
<p>
@@ -40,14 +39,9 @@
4039
4140
{
4241
; // do nothing
43-
}
4442
}]]>
4543
</sample>
4644
</example>
47-
<semmleNotes>
48-
<p>
49-
</p>
50-
</semmleNotes>
5145
<references>
5246
<li>
5347
<a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28266-function-property-syntax-error">
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Current function type not correct (C28101)
2+
This function appears to be an unannotated DriverEntry function
3+
4+
5+
## Recommendation
6+
DriverEntry functions should be declared using the DRIVER_INITIALIZE function typedef.
7+
8+
9+
## References
10+
* [ C28101 ](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28101-wrong-function-type)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Use of default pool tag in memory allocation (C28147)
2+
Memory should not be allocated with the default tags of ' mdW' or ' kdD'.
3+
4+
5+
## Recommendation
6+
The driver is specifying a default pool tag. Because the system tracks pool use by pool tag, only those drivers that use a unique pool tag can identify and distinguish their pool use.
7+
8+
9+
## Example
10+
In this example, the driver allocates memory with the default tag:
11+
12+
```c
13+
14+
PVOID InternalNonPagedAllocator(SIZE_T size) {
15+
return ExAllocatePool3(POOL_FLAG_NON_PAGED, size, ' mdW');
16+
}
17+
18+
```
19+
The driver should use a custom tag instead:
20+
21+
```c
22+
23+
PVOID InternalNonPagedAllocator(SIZE_T size) {
24+
return ExAllocatePool3(POOL_FLAG_NON_PAGED, size, 'vdxE');
25+
}
26+
27+
```
28+
29+
## References
30+
* [ C28147 warning - Windows Drivers ](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28147-improper-use-of-default-pool-tag)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Driver Entry Save Buffer
2+
The DriverEntry routine should save a copy of the argument, not the pointer, because the I/O Manager frees the buffer
3+
4+
5+
## Recommendation
6+
The driver's DriverEntry routine is saving a copy of the pointer to the buffer instead of saving a copy of the buffer. Because the buffer is freed when the DriverEntry routine returns, the pointer to the buffer will soon be invalid.
7+
8+
9+
## Example
10+
11+
```c
12+
// Copyright (c) Microsoft Corporation.
13+
// Licensed under the MIT license.
14+
//
15+
// driver_snippet.c
16+
//
17+
#include "ntstrsafe.h"
18+
19+
#define SET_DISPATCH 1
20+
// Template. Not called in this test.
21+
void top_level_call() {}
22+
23+
PUNICODE_STRING g_RP1;
24+
25+
NTSTATUS
26+
DriverEntryBad(
27+
PDRIVER_OBJECT DriverObject,
28+
PUNICODE_STRING RegistryPath
29+
)
30+
{
31+
g_RP1 = RegistryPath;
32+
return 0;
33+
}
34+
35+
36+
UNICODE_STRING g_RP2;
37+
38+
NTSTATUS
39+
DriverEntryGood(
40+
PDRIVER_OBJECT DriverObject,
41+
PUNICODE_STRING RegistryPath
42+
)
43+
{
44+
return RtlUnicodeStringCopy(&g_RP2,RegistryPath);
45+
}
46+
47+
48+
UNICODE_STRING g_RP3;
49+
50+
NTSTATUS
51+
DriverEntryGood2(
52+
PDRIVER_OBJECT DriverObject,
53+
PUNICODE_STRING RegistryPath
54+
)
55+
{
56+
g_RP3 = *RegistryPath;
57+
return 0;
58+
}
59+
60+
typedef struct _test_struct {
61+
int a;
62+
PUNICODE_STRING g_RP4;
63+
char b;
64+
} test_struct;
65+
66+
test_struct g_test_struct;
67+
68+
NTSTATUS
69+
DriverEntryBad2(
70+
PDRIVER_OBJECT DriverObject,
71+
PUNICODE_STRING RegistryPath
72+
)
73+
{
74+
test_struct* localPtr = &g_test_struct;
75+
localPtr->g_RP4 = RegistryPath;
76+
return 0;
77+
}
78+
```
79+
80+
## References
81+
* [ C28131 ](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28131-driverentry-saving-pointer-to-buffer)
82+
83+
## Semmle-specific notes
84+
This rule reports a false positive when the registry path pointer is saved for use in functions such as HidRegisterMinidriver
85+

0 commit comments

Comments
 (0)