Skip to content

Commit 267b3e4

Browse files
IrqlFunctionNotAnnotated: codeql port of c28167 (#160)
codeql port of c28167
1 parent a9ed412 commit 267b3e4

File tree

4 files changed

+550
-0
lines changed

4 files changed

+550
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
2+
<qhelp>
3+
<overview>
4+
<p>
5+
The function changes the IRQL and does not restore the IRQL before it exits. It should be annotated to reflect the change or the IRQL should be restored.
6+
</p>
7+
</overview>
8+
<recommendation>
9+
<p>
10+
This warning indicates that the following conditions are true:
11+
1. The function changes the IRQL at which the driver is running.
12+
2. There is at least one path through a function that does not, by function exit, restore the IRQL to the original IRQL that the driver was running at function entry.
13+
</p>
14+
</recommendation>
15+
<example>
16+
<p>
17+
Function which potentially raises the IRQL level but is not annotated to reflect the change.
18+
</p>
19+
<sample language="c"> <![CDATA[
20+
void fail1(PKIRQL oldIrql)
21+
{
22+
23+
if (oldIrql == PASSIVE_LEVEL)
24+
{
25+
KeLowerIrql(*oldIrql);
26+
}
27+
else
28+
{
29+
KeRaiseIrql(DISPATCH_LEVEL, oldIrql); // Function exits at DISPATCH_LEVEL
30+
}
31+
}
32+
}]]>
33+
34+
</example>
35+
<semmleNotes>
36+
<p>
37+
</p>
38+
</semmleNotes>
39+
<references>
40+
<li>
41+
<a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28167-function-changes-irql-without-restore">
42+
C28167
43+
</a>
44+
</li>
45+
</references>
46+
</qhelp>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
/**
4+
* @id cpp/drivers/irql-function-not-annotated
5+
* @kind problem
6+
* @name Irql Function Not Annotated
7+
* @description The function changes the IRQL and does not restore the IRQL before it exits. It should be annotated to reflect the change or the IRQL should be restored.
8+
* @platform Desktop
9+
* @feature.area Multiple
10+
* @impact Insecure Coding Practice
11+
* @repro.text This warning occurs when an IRQL annotation on a function is required, but one doesn't exist.
12+
* @owner.email: [email protected]
13+
* @opaqueid CQLD-C28167
14+
* @problem.severity warning
15+
* @precision medium
16+
* @tags correctness
17+
* @scope domainspecific
18+
* @query-version v1
19+
*/
20+
21+
import cpp
22+
import drivers.libraries.Irql
23+
24+
from
25+
Function f, int irqlLevelEntry, int irqlLevelExit, ControlFlowNode exitCfn,
26+
ControlFlowNode entryCfn
27+
where
28+
not f instanceof IrqlChangesFunction and
29+
exists(FunctionCall fc |
30+
fc.getTarget() instanceof IrqlChangesFunction and fc.getEnclosingFunction() = f
31+
) and
32+
exitCfn = f.getControlFlowScope() and
33+
entryCfn = f.getBlock() and
34+
irqlLevelEntry = getPotentialExitIrqlAtCfn(entryCfn) and
35+
irqlLevelExit = getPotentialExitIrqlAtCfn(exitCfn) and
36+
irqlLevelEntry != irqlLevelExit
37+
select f, "Function potentially changes the IRQL without restoring it to the original level, however, the function is not annotated to reflect such a change."

0 commit comments

Comments
 (0)