-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IrqlInconsistentWithRequired: CodeQL port of C28166 (#159)
* CodeQL port of C28156 * updates from review
- Loading branch information
1 parent
3fb0ff0
commit fa6d266
Showing
4 changed files
with
429 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/drivers/general/queries/IrqlInconsistentWithRequired/IrqlInconsistentWithRequired.qhelp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd"> | ||
<qhelp> | ||
<overview> | ||
<p> | ||
The actual IRQL is inconsistent with the required IRQL | ||
</p> | ||
</overview> | ||
<recommendation> | ||
<p> | ||
An _IRQL_requires_same_ annotation specifies that the driver should be executing at a particular IRQL when the function completes, but there is at least one path in which the driver is executing at a different IRQL when the function completes. | ||
</p> | ||
</recommendation> | ||
<example> | ||
<p> | ||
Function annotated with _IRQL_requires_same_ but can possibly exit at a different IRQL level. | ||
</p> | ||
<sample language="c"> <![CDATA[ | ||
_IRQL_requires_same_ void fail1(PKIRQL oldIrql) | ||
{ | ||
if (oldIrql == PASSIVE_LEVEL) | ||
{ | ||
KeLowerIrql(*oldIrql); | ||
} | ||
else | ||
{ | ||
KeRaiseIrql(DISPATCH_LEVEL, oldIrql); // Function exits at DISPATCH_LEVEL | ||
} | ||
} | ||
}]]> | ||
|
||
</example> | ||
<semmleNotes> | ||
<p> | ||
</p> | ||
</semmleNotes> | ||
<references> | ||
<li> | ||
<a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28166-function-does-not-restore-irql-value"> | ||
C28166 | ||
</a> | ||
</li> | ||
</references> | ||
</qhelp> |
36 changes: 36 additions & 0 deletions
36
src/drivers/general/queries/IrqlInconsistentWithRequired/IrqlInconsistentWithRequired.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
/** | ||
* @id cpp/drivers/irql-inconsistent-with-required | ||
* @kind problem | ||
* @name Irql Inconsistent With Required | ||
* @description The actual IRQL is inconsistent with the required IRQL | ||
* @platform Desktop | ||
* @feature.area Multiple | ||
* @impact Insecure Coding Practice | ||
* @repro.text An _IRQL_requires_same_ annotation specifies that the driver should be executing at a particular IRQL when the function completes, but there is at least one path in which the driver is executing at a different IRQL when the function completes. | ||
* @owner.email: [email protected] | ||
* @opaqueid CQLD-C28166 | ||
* @problem.severity warning | ||
* @precision medium | ||
* @tags correctness | ||
* @scope domainspecific | ||
* @query-version v1 | ||
*/ | ||
|
||
import cpp | ||
import drivers.libraries.Irql | ||
|
||
from | ||
IrqlRequiresSameAnnotatedFunction f, int irqlLevelEntry, int irqlLevelExit, | ||
ControlFlowNode exitCfn, ControlFlowNode entryCfn | ||
where | ||
exitCfn = f.getControlFlowScope() and | ||
entryCfn = f.getBlock() and | ||
irqlLevelEntry = getPotentialExitIrqlAtCfn(entryCfn) and | ||
irqlLevelExit = getPotentialExitIrqlAtCfn(exitCfn) and | ||
irqlLevelEntry != irqlLevelExit | ||
select f, | ||
"Possible IRQL level at function completion inconsistent with the required IRQL level for some path. Irql level expected: " | ||
+ irqlLevelEntry + ". Irql level found: " + irqlLevelExit + | ||
". Review the IRQL level of the function." |
Oops, something went wrong.