Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
a378744
Github actions updates (#139)
jacob-ronstadt May 24, 2024
468e003
Update build-codeql.yaml to allow publish step to fail for outside PRs
jacob-ronstadt Jun 13, 2024
ac8f77f
Update build-codeql.yaml (#141)
jacob-ronstadt Jun 14, 2024
94b8ca8
Update build-codeql.yaml (#142)
jacob-ronstadt Jun 27, 2024
2034189
Initial Batch of Windows Filtering Platform Queries for Static Contra…
houha2 Jun 27, 2024
c282407
codeql port of C28648. TODO needs tests
jacob-ronstadt Aug 16, 2024
ce7d70c
Revert "codeql port of C28648. TODO needs tests"
jacob-ronstadt Aug 16, 2024
c15579b
OperandAssignment: CodeQL Port of C28129 (#121)
jacob-ronstadt Aug 23, 2024
540f0d4
IoInitializeTimerCall: CodeQL port of C28133 (#123)
jacob-ronstadt Aug 23, 2024
c2febb9
IrqlIllegalValue: CodeQL port of c28151 (#144)
jacob-ronstadt Aug 23, 2024
c8369c9
NullPointerCharacterAssignment: CodeQL port of C28730 (#146)
jacob-ronstadt Aug 23, 2024
786fda0
FloatSafeExit: CodeQL port of C28162 (#147)
jacob-ronstadt Aug 23, 2024
9dc8063
FloatUnsafeExit: CodeQL port of C28161 (#148)
jacob-ronstadt Aug 23, 2024
f227ac0
PointerVariableSize: CodeQL port of C28132 (#143)
jacob-ronstadt Aug 23, 2024
735f49f
NtstatusExplicitCast3: CodeQL port of C28716 (#151)
jacob-ronstadt Aug 23, 2024
d71fb93
NtstatusExplicitCast2: CodeQL port of C29715 (#150)
jacob-ronstadt Aug 23, 2024
3165575
NtstatusExplicitCast: CodeQL port of C28714 (#149)
jacob-ronstadt Aug 23, 2024
7edf413
CurrentFunctionTypeNotCorrect: CodeQL port of C28101 (#124)
jacob-ronstadt Aug 23, 2024
4eab8e3
InvalidFunctionPointerAnnotation: CodeQL port of C28165 (#145)
jacob-ronstadt Aug 23, 2024
ef48413
FloatHardwareStateProtection: CodeQL port of c28110 (#130)
jacob-ronstadt Aug 23, 2024
53bb6fe
DriverEntrySaveBuffer: Port of c28131 (#122)
jacob-ronstadt Aug 23, 2024
0488826
IRPStackEntryCopy: CodeQL port of c28114 (#120)
jacob-ronstadt Aug 23, 2024
e5c16d7
update ported_driver_ca_checks.qls with new queries
jacob-ronstadt Aug 23, 2024
713331e
fix typo
jacob-ronstadt Aug 23, 2024
60874fd
updates to test script
jacob-ronstadt Aug 26, 2024
f47586b
Driver isolation queries (#152)
jacob-ronstadt Sep 25, 2024
129bcb5
update config file to include other isolation queries
jacob-ronstadt Sep 26, 2024
39f0f5d
update build script
jacob-ronstadt Sep 26, 2024
0c54c94
update sarif files for isolation queries
jacob-ronstadt Sep 26, 2024
9c1627b
Update codeql-config.yml
jacob-ronstadt Sep 27, 2024
e49efef
github action updates to get latest codeql version (#154)
jacob-ronstadt Nov 11, 2024
d623cf8
minor updates
jacob-ronstadt Nov 12, 2024
ece9421
fix compare issue with backslashes in latest codeql version
jacob-ronstadt Nov 12, 2024
3ef295d
Irql.qll updates to expand ability to detect function IRQL requiremen…
jacob-ronstadt Jan 6, 2025
2a7c167
update uses of dataflow to use latest library (#155)
jacob-ronstadt Jan 10, 2025
c7f9de9
StaticInitializer: CodeQL port of C28651 (#156)
jacob-ronstadt Jan 30, 2025
fa33730
Add APIs to ExtendedDeprecatedApis for Codeql port of c28727 (#163)
jacob-ronstadt Jan 30, 2025
a9ed412
Driver apps framework (#165)
jacob-ronstadt Jan 30, 2025
267b3e4
IrqlFunctionNotAnnotated: codeql port of c28167 (#160)
jacob-ronstadt Jan 30, 2025
9d62d31
IrqlLoweredImproperly: Codeql port of c28141 (#157)
jacob-ronstadt Jan 30, 2025
528c675
IrqlFloatStateMismatch: CodeQL port of C28111 (#161)
jacob-ronstadt Jan 30, 2025
9eb68b3
IrqlCancelRoutine: CodeQL port of c28144 (#162)
jacob-ronstadt Jan 30, 2025
3fb0ff0
IrqlAnnotationIssue: CodeQL port of c28153 (#158)
jacob-ronstadt Jan 30, 2025
fa6d266
IrqlInconsistentWithRequired: CodeQL port of C28166 (#159)
jacob-ronstadt Jan 30, 2025
8ce22c1
AnnotationSyntax: CodeQL port of c28266 (#164)
jacob-ronstadt Jan 30, 2025
aa5a9fc
CodeQL port of C28650
jacob-ronstadt Feb 7, 2025
798514b
add build_database_only option to build script
jacob-ronstadt Feb 7, 2025
c997c83
update gitignore
jacob-ronstadt Feb 7, 2025
87c7a9d
ImportantFunctionCallOptimizedOut: port of c28625 (#167)
jacob-ronstadt Feb 7, 2025
bba37ab
InvalidFunctionClassTypedef: Codeql port of c28268 (#170)
jacob-ronstadt Feb 7, 2025
eeaf255
StrictTypeMatch: Codeql port of c28139 (#169)
jacob-ronstadt Feb 7, 2025
77fb9a1
MultipleFunctionClassAnnotations: Port of C28177 (#168)
jacob-ronstadt Feb 8, 2025
aeb1987
UnsafeCallInGlobalinit: CodeQL port of C28637 (#166)
jacob-ronstadt Feb 10, 2025
5066a0e
Update opaqueid in ImproperNotOperatorOnZero.ql
jacob-ronstadt Feb 10, 2025
6aefd5c
update build script and repo structure
jacob-ronstadt Feb 11, 2025
01eb74d
ported_driver_ca_checks.qls to use tag ca_ported and update ported ca…
jacob-ronstadt Feb 11, 2025
da3535a
update dvl_tests.ps1
jacob-ronstadt Feb 11, 2025
0724fc5
update qlpack version and fix path error
jacob-ronstadt Feb 11, 2025
6b424ee
bug fix in AnnotationSyntax.ql
jacob-ronstadt Feb 20, 2025
6748f70
update DriverEntrySaveBuffer.ql to only look at registrypath and not …
jacob-ronstadt Feb 20, 2025
78b7b70
remove false positives
jacob-ronstadt Feb 21, 2025
9629358
remove false positives
jacob-ronstadt Feb 21, 2025
8edf3f1
remove false positives
jacob-ronstadt Feb 21, 2025
335b284
Add possible false positive note to DriverEntrySaveBuffer.qhelp
jacob-ronstadt Feb 21, 2025
880c39a
remove non-SAL parameters due to false positives
jacob-ronstadt Feb 21, 2025
8455a12
update message
jacob-ronstadt Feb 21, 2025
d99af75
update test results to match query update
jacob-ronstadt Feb 24, 2025
1bde64e
fix query id
jacob-ronstadt Feb 27, 2025
0ba716b
Update codeql-config.yml
jacob-ronstadt Mar 21, 2025
c88a2a1
Update codeql-config.yml
jacob-ronstadt Mar 21, 2025
f1d346f
Query suite updates (#172)
jacob-ronstadt Mar 21, 2025
4f04d8c
Update codeql-config.yml
jacob-ronstadt Mar 21, 2025
06ef37d
Update codeql-config.yml
jacob-ronstadt Mar 21, 2025
4246e2a
Update codeql-config.yml
jacob-ronstadt Mar 21, 2025
b62be55
Must run query update (#173)
jacob-ronstadt May 9, 2025
0bb0146
Jacob ronstadt/mustrun (#174)
jacob-ronstadt May 28, 2025
03de642
Update README.md
jacob-ronstadt Jun 10, 2025
35b9f55
Actions azure file storage fix (#176)
jacob-ronstadt Jun 10, 2025
35d8ba7
Fix query health action (#177)
jacob-ronstadt Jun 23, 2025
df3da19
Improve recommendations in ExtendedDeprecatedApis for strlen (#179)
NateD-MSFT Jun 27, 2025
4700593
Merge branch 'main' into development
NateD-MSFT Jun 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
318 changes: 268 additions & 50 deletions .github/workflows/build-codeql.yaml

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

name: Build and Publish Windows CodeQL queries
on:
workflow_dispatch:
input:
version:
description: 'CodeQL version to use'
required: true
type: string
jobs:
publish:
runs-on: windows-latest
permissions:
contents: read
packages: write
steps:
- name: Enable long git paths
shell: cmd
run: git config --global core.longpaths true

- name: Clone self (windows-driver-developer-supplemental-tools)
uses: actions/checkout@v4
with:
path: .
fetch-depth: 0

- name: CodeQL Download
run:
Invoke-WebRequest -Uri "https://github.com/github/codeql-cli-binaries/releases/download/v${{ github.event.inputs.version }}/codeql-win64.zip" -OutFile codeql-win64.zip;
Expand-Archive -Path codeql-win64.zip -DestinationPath .\codeql-zip -Force;
Move-Item -Path .\codeql-zip\codeql -Destination .\codeql-cli\

- name: Install CodeQL pack dependencies
shell: cmd
run: |
pushd .\src
..\codeql-cli\codeql.cmd pack install
popd
- name: Publish New CodeQL Pack
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run:
.\codeql-cli\codeql.cmd pack publish ./src;
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# query compilation caches
**/*.cache

**/*.codeql/

# IDE folders
.vscode/*
**/.vs/*
Expand All @@ -13,6 +15,11 @@ src/drivers/test/**/Debug/*
src/drivers/test/TestDB/*
src/drivers/test/working/*
src/drivers/test/AnalysisFiles/*

AnalysisFiles/*
TestDB/*
working/*
#excel files
**/*.xlsx
**/*.xlsx

# Log files
**/*.log
156 changes: 71 additions & 85 deletions README.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions config/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "CodeQL config"
disable-default-queries: true

packs:
- microsoft/cpp-queries@0.0.2:codeql-suites/cpp-code-scanning.qls
- microsoft/windows-drivers@1.5.0-beta+5:windows-driver-suites/recommended.qls
- microsoft/windows-drivers@1.5.0-beta+5:drivers\general\queries\experimental\DriverIsolationZwViolation1\DriverIsolationZwViolation1.ql
- microsoft/windows-drivers@1.5.0-beta+5:drivers\general\queries\experimental\DriverIsolationZwViolation2\DriverIsolationZwViolation2.ql
- microsoft/windows-drivers@1.5.0-beta+5:drivers\general\queries\experimental\DriverIsolationRtlViolation\DriverIsolationRtlViolation.ql
24 changes: 17 additions & 7 deletions src/codeql-pack.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@
lockVersion: 1.0.0
dependencies:
codeql/cpp-all:
version: 0.12.1
version: 4.2.0
codeql/dataflow:
version: 0.1.4
version: 2.0.5
codeql/mad:
version: 1.0.21
codeql/rangeanalysis:
version: 0.0.3
version: 1.0.21
codeql/ssa:
version: 0.2.4
version: 1.1.0
codeql/suite-helpers:
version: 1.0.21
codeql/tutorial:
version: 0.2.4
version: 1.0.21
codeql/typeflow:
version: 1.0.21
codeql/typetracking:
version: 0.2.4
version: 2.0.5
codeql/util:
version: 0.2.4
version: 2.0.8
codeql/xml:
version: 1.0.21
microsoft/cpp-queries:
version: 0.0.4
compiled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
<qhelp>
<overview>
<p>
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.
</p>
</overview>
<recommendation>
<p>
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.
</p>
</recommendation>
<example>
<p>
DLLMain function
</p>
<sample language="c"> <![CDATA[
BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpvReserved ) // reserved
{
// Perform actions based on the reason for calling.
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
// Initialize once for each new process.
// Return FALSE to fail DLL load.
break;

case DLL_THREAD_ATTACH:
// Do thread-specific initialization.
break;

case DLL_THREAD_DETACH:
// Do thread-specific cleanup.
break;

case DLL_PROCESS_DETACH:

if (lpvReserved != nullptr)
{
break; // do not do cleanup if process termination scenario
}

// Perform any necessary cleanup.
break;
}
return TRUE; // Successful DLL_PROCESS_ATTACH.
}
}]]>

</example>
<semmleNotes>
<p>

</p>
</semmleNotes>
<references>
<li>
<a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28637-calling-function-in-a-global-initializer-is-unsafe">
C28637
</a>
</li>
</references>
</qhelp>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @id cpp/drivers/unsafe-call-in-global-init
* @kind problem
* @name UnsafeCallInGlobalInit
* @description 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.
* @platform Desktop
* @feature.area Multiple
* @impact Insecure Coding Practice
* @repro.text
* @owner.email: sdat@microsoft.com
* @opaqueid CQLD-C28637
* @problem.severity warning
* @precision medium
* @tags correctness
* ca_ported
* @scope domainspecific
* @query-version v1
*/

import cpp
import drivers.libraries.DriverIsolation

from Function f, string msg
where
f.getName().matches("DllMain") and
exists(FunctionCall fc |
fc.getEnclosingFunction() = f
and
(
fc.getTarget()
.getName()
.matches([
"LoadLibrary%", "LoadLibraryEx", "GetStringTypeA", "GetStringTypeEx", "GetStringTypeW",
"CoInitializeEx", "CreateProcess%", "ExitThread%", "CreateThread%", "ShGetFolderPathW"
]) or
fc instanceof RegistryIsolationFunctionCall
)
and
msg = "Unsafe call in DllMain: " + fc.getTarget().getName() + ". "
)
or
exists(Initializer i |
f.getName().matches("DllMain") and
i.getExpr().getEnclosingFunction() = f and
not i.getDeclaration().isStatic() and
i.getExpr().toString().toLowerCase().matches("null") and
msg = "Potential unsafe initialization in DllMain. "
)
select f, msg + " Review Dynamic-Link Library Best Practices."
Loading
Loading