Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
<qhelp>
<overview>
<p>
The argument causes the IRQ Level to be set below the current IRQL, and this function cannot be used for that purpose
</p>
</overview>
<recommendation>
<p>
A function call that lowers the IRQL at which a caller is executing is being used inappropriately. Typically, the function call lowers the IRQL as part of a more general routine or is intended to raise the caller's IRQL.
</p>
</recommendation>
<example>
<p>
The following code example elicits this warning.
</p>
<sample language="c"> <![CDATA[
KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
KeRaiseIrql(PASSIVE_LEVEL, &OldIrql);
}]]>
</sample>
<p>
The following code example avoids this warning.
</p>
<sample language="c"> <![CDATA[
KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
KeLowerIrql(OldIrql);
}]]>
</sample>
</example>
<semmleNotes>
<p>
</p>
</semmleNotes>
<references>
<li>
<a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28141-argument-lowers-irq-level">
C28141
</a>
</li>
</references>
</qhelp>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if this is for more than KeRaiseIrql

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @id cpp/drivers/irql-lowered-improperly
* @kind problem
* @name IRQL Lowered Improperly
* @description A function being called changes the IRQL to below the current IRQL, and the function is not intended for that purpose.
* @platform Desktop
* @feature.area Multiple
* @impact Insecure Coding Practice
* @repro.text
* @owner.email: [email protected]
* @opaqueid CQLD-C28141
* @problem.severity warning
* @precision medium
* @tags correctness
* @scope domainspecific
* @query-version v1
*/

import cpp
import drivers.libraries.Irql

from KeRaiseIrqlCall call, ControlFlowNode prior, int irqlRequirement
where
prior = call.getAPredecessor() and
irqlRequirement = call.getIrqlLevel() and
irqlRequirement != -1 and
irqlRequirement < min(getPotentialExitIrqlAtCfn(prior))
select call,"$@: The function being called changes the IRQL to below the current IRQL, and the function is not intended for that purpose.",
call, call.toString()
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
{
"$schema" : "https://json.schemastore.org/sarif-2.1.0.json",
"version" : "2.1.0",
"runs" : [ {
"tool" : {
"driver" : {
"name" : "CodeQL",
"organization" : "GitHub",
"semanticVersion" : "2.15.4",
"notifications" : [ {
"id" : "cpp/baseline/expected-extracted-files",
"name" : "cpp/baseline/expected-extracted-files",
"shortDescription" : {
"text" : "Expected extracted files"
},
"fullDescription" : {
"text" : "Files appearing in the source archive that are expected to be extracted."
},
"defaultConfiguration" : {
"enabled" : true
},
"properties" : {
"tags" : [ "expected-extracted-files", "telemetry" ]
}
} ],
"rules" : [ {
"id" : "cpp/drivers/TODO",
"name" : "cpp/drivers/TODO",
"shortDescription" : {
"text" : "TODO"
},
"fullDescription" : {
"text" : "TODO"
},
"defaultConfiguration" : {
"enabled" : true,
"level" : "warning"
},
"properties" : {
"tags" : [ "correctness" ],
"description" : "TODO",
"feature.area" : "Multiple",
"id" : "cpp/drivers/TODO",
"impact" : "Insecure Coding Practice",
"kind" : "problem",
"name" : "TODO",
"opaqueid" : "CQLD-TODO",
"owner.email:" : "[email protected]",
"platform" : "Desktop",
"precision" : "medium",
"problem.severity" : "warning",
"query-version" : "v1",
"repro.text" : "",
"scope" : "domainspecific"
}
} ]
},
"extensions" : [ {
"name" : "microsoft/windows-drivers",
"semanticVersion" : "1.0.13+4cf80ade609037becb8999823de45e08bd818a20",
"locations" : [ {
"uri" : "file:///C:/codeql-home/WDDST/src/",
"description" : {
"text" : "The QL pack root directory."
}
}, {
"uri" : "file:///C:/codeql-home/WDDST/src/qlpack.yml",
"description" : {
"text" : "The QL pack definition file."
}
} ]
} ]
},
"invocations" : [ {
"toolExecutionNotifications" : [ {
"locations" : [ {
"physicalLocation" : {
"artifactLocation" : {
"uri" : "driver/driver_snippet.c",
"uriBaseId" : "%SRCROOT%",
"index" : 1
}
}
} ],
"message" : {
"text" : ""
},
"level" : "none",
"descriptor" : {
"id" : "cpp/baseline/expected-extracted-files",
"index" : 0
},
"properties" : {
"formattedMessage" : {
"text" : ""
}
}
}, {
"locations" : [ {
"physicalLocation" : {
"artifactLocation" : {
"uri" : "driver/fail_driver1.c",
"uriBaseId" : "%SRCROOT%",
"index" : 0
}
}
} ],
"message" : {
"text" : ""
},
"level" : "none",
"descriptor" : {
"id" : "cpp/baseline/expected-extracted-files",
"index" : 0
},
"properties" : {
"formattedMessage" : {
"text" : ""
}
}
}, {
"locations" : [ {
"physicalLocation" : {
"artifactLocation" : {
"uri" : "driver/fail_driver1.h",
"uriBaseId" : "%SRCROOT%",
"index" : 2
}
}
} ],
"message" : {
"text" : ""
},
"level" : "none",
"descriptor" : {
"id" : "cpp/baseline/expected-extracted-files",
"index" : 0
},
"properties" : {
"formattedMessage" : {
"text" : ""
}
}
} ],
"executionSuccessful" : true
} ],
"artifacts" : [ {
"location" : {
"uri" : "driver/fail_driver1.c",
"uriBaseId" : "%SRCROOT%",
"index" : 0
}
}, {
"location" : {
"uri" : "driver/driver_snippet.c",
"uriBaseId" : "%SRCROOT%",
"index" : 1
}
}, {
"location" : {
"uri" : "driver/fail_driver1.h",
"uriBaseId" : "%SRCROOT%",
"index" : 2
}
} ],
"results" : [ {
"ruleId" : "cpp/drivers/TODO",
"ruleIndex" : 0,
"rule" : {
"id" : "cpp/drivers/TODO",
"index" : 0
},
"message" : {
"text" : "TODO"
},
"locations" : [ {
"physicalLocation" : {
"artifactLocation" : {
"uri" : "driver/fail_driver1.c",
"uriBaseId" : "%SRCROOT%",
"index" : 0
},
"region" : {
"startLine" : 56,
"endColumn" : 12
}
}
} ],
"partialFingerprints" : {
"primaryLocationLineHash" : "60c6386a5ee58eb6:1",
"primaryLocationStartColumnFingerprint" : "0"
}
} ],
"columnKind" : "utf16CodeUnits",
"properties" : {
"semmle.formatSpecifier" : "sarifv2.1.0"
}
} ]
}
32 changes: 32 additions & 0 deletions src/drivers/general/queries/IrqlLoweredImproperly/driver_snippet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
// driver_snippet.c
//

#define SET_DISPATCH 1

// Template. Not called in this test.
void top_level_call() {}

#include <wdm.h>

/*
*/
_IRQL_raises_(DISPATCH_LEVEL)
VOID IrqlRaiseLevelExplicit_fail(void)
{
KIRQL oldIRQL;
KeRaiseIrql(DISPATCH_LEVEL, &oldIRQL);
KeRaiseIrql(PASSIVE_LEVEL, &oldIRQL); // raise the IRQL to PASSIVE_LEVEL, which is lower than DISPATCH_LEVEL
}
/*
Function can be called to raise the IRQL but needs to exit at DISPATCH_LEVEL.
*/
_IRQL_raises_(DISPATCH_LEVEL)
VOID IrqlRaiseLevelExplicit_pass(void)
{
KIRQL oldIRQL;
KeRaiseIrql(DISPATCH_LEVEL, &oldIRQL);
KeLowerIrql(oldIRQL);
}
Loading