-
Notifications
You must be signed in to change notification settings - Fork 37
IrqlLoweredImproperly: Codeql port of c28141 #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/drivers/general/queries/IrqlLoweredImproperly/IrqlLoweredImproperly.qhelp
This file contains hidden or 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,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> |
31 changes: 31 additions & 0 deletions
31
src/drivers/general/queries/IrqlLoweredImproperly/IrqlLoweredImproperly.ql
This file contains hidden or 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,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() |
199 changes: 199 additions & 0 deletions
199
src/drivers/general/queries/IrqlLoweredImproperly/IrqlLoweredImproperly.sarif
This file contains hidden or 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,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" : { | ||
jacob-ronstadt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "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
32
src/drivers/general/queries/IrqlLoweredImproperly/driver_snippet.c
This file contains hidden or 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,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); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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