-
Notifications
You must be signed in to change notification settings - Fork 37
IrqlCancelRoutine: CodeQL port of c28144 #162
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
40 changes: 40 additions & 0 deletions
40
src/drivers/general/queries/IrqlCancelRoutine/IrqlCancelRoutine.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,40 @@ | ||
| <!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd"> | ||
| <qhelp> | ||
| <overview> | ||
| <p> | ||
| TODO overview | ||
| </p> | ||
| </overview> | ||
| <recommendation> | ||
| <p> | ||
| TODO recommendation | ||
| </p> | ||
| </recommendation> | ||
| <example> | ||
| <p> | ||
| The following example shows an incorrect use of IoReleaseCncelSpinLock within a cancel routine | ||
| </p> | ||
| <sample language="c"> <![CDATA[ | ||
| IoReleaseCancelSpinLock(PASSIVE_LEVEL); | ||
| }]]> | ||
| </sample> | ||
| <p> | ||
| Correct use of IoReleaseCncelSpinLock within a cancel routine | ||
| </p> | ||
| <sample language="c"> <![CDATA[ | ||
| IoReleaseCancelSpinLock(Irp->CancelIrql); | ||
| }]]> | ||
| </sample> | ||
| </example> | ||
| <semmleNotes> | ||
| <p> | ||
| </p> | ||
| </semmleNotes> | ||
| <references> | ||
| <li> | ||
| <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28144-cancelirql-should-be-current-irql"> | ||
| C28144 | ||
| </a> | ||
| </li> | ||
| </references> | ||
| </qhelp> | ||
38 changes: 38 additions & 0 deletions
38
src/drivers/general/queries/IrqlCancelRoutine/IrqlCancelRoutine.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,38 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| /** | ||
| * @id cpp/drivers/irql-cancel-routine | ||
| * @kind problem | ||
| * @name Irql Cancel Routine | ||
| * @description Within a cancel routine, at the point of exit, the IRQL in Irp->CancelIrql should be the current IRQL. | ||
| * @platform Desktop | ||
| * @feature.area Multiple | ||
| * @impact Insecure Coding Practice | ||
| * @repro.text When the driver's Cancel routine exits, the value of the Irp->CancelIrql member is not the current IRQL. | ||
| * Typically, this error occurs when the driver does not call IoReleaseCancelSpinLock with the IRQL that was supplied by | ||
| * the most recent call to IoAcquireCancelSpinLock. | ||
| * @owner.email: [email protected] | ||
| * @opaqueid CQLD-C28144 | ||
| * @problem.severity warning | ||
| * @precision medium | ||
| * @tags correctness | ||
| * @scope domainspecific | ||
| * @query-version v1 | ||
| */ | ||
|
|
||
| import cpp | ||
| import drivers.libraries.Irql | ||
|
|
||
| from Function f, FunctionCall fc | ||
| where | ||
| ( | ||
| f.(RoleTypeFunction).getRoleTypeString().matches("DRIVER_CANCEL") or | ||
| f.(ImplicitRoleTypeFunction).getExpectedRoleTypeString().matches("DRIVER_CANCEL") | ||
| ) and | ||
| fc.getEnclosingFunction() = f and | ||
| fc.getTarget().getName() = "IoReleaseCancelSpinLock" and | ||
| ( | ||
| not fc.getArgument(0).(PointerFieldAccess).getQualifier() = f.getParameter(1).getAnAccess() or | ||
| not fc.getArgument(0).(PointerFieldAccess).getTarget().getName() = "CancelIrql" | ||
| ) | ||
| select fc, "IoReleaseCancelSpinLock inside a cancel routine needs to be called with Irp->CancelIrql" |
312 changes: 312 additions & 0 deletions
312
src/drivers/general/queries/IrqlCancelRoutine/IrqlCancelRoutine.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,312 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/sarif-2.1.0.json", | ||
| "version": "2.1.0", | ||
| "runs": [ | ||
| { | ||
| "tool": { | ||
| "driver": { | ||
| "name": "CodeQL", | ||
| "organization": "GitHub", | ||
| "semanticVersion": "2.19.3", | ||
| "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" | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "id": "cpp/extractor/summary", | ||
| "name": "cpp/extractor/summary", | ||
| "shortDescription": { | ||
| "text": "C++ extractor telemetry" | ||
| }, | ||
| "fullDescription": { | ||
| "text": "C++ extractor telemetry" | ||
| }, | ||
| "defaultConfiguration": { | ||
| "enabled": true | ||
| } | ||
| } | ||
| ], | ||
| "rules": [ | ||
| { | ||
| "id": "cpp/drivers/irql-cancel-routine", | ||
| "name": "cpp/drivers/irql-cancel-routine", | ||
| "shortDescription": { | ||
| "text": "Irql Cancel Routine" | ||
| }, | ||
| "fullDescription": { | ||
| "text": "Within a cancel routine, at the point of exit, the IRQL in Irp->CancelIrql should be the current IRQL." | ||
| }, | ||
| "defaultConfiguration": { | ||
| "enabled": true, | ||
| "level": "warning" | ||
| }, | ||
| "properties": { | ||
| "tags": [ | ||
| "correctness" | ||
| ], | ||
| "description": "Within a cancel routine, at the point of exit, the IRQL in Irp->CancelIrql should be the current IRQL.", | ||
| "feature.area": "Multiple", | ||
| "id": "cpp/drivers/irql-cancel-routine", | ||
| "impact": "Insecure Coding Practice", | ||
| "kind": "problem", | ||
| "name": "Irql Cancel Routine", | ||
| "opaqueid": "CQLD-C28144", | ||
| "owner.email:": "[email protected]", | ||
| "platform": "Desktop", | ||
| "precision": "medium", | ||
| "problem.severity": "warning", | ||
| "query-version": "v1", | ||
| "repro.text": "When the driver's Cancel routine exits, the value of the Irp->CancelIrql member is not the current IRQL. \n Typically, this error occurs when the driver does not call IoReleaseCancelSpinLock with the IRQL that was supplied by \n the most recent call to IoAcquireCancelSpinLock.", | ||
| "scope": "domainspecific" | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "extensions": [ | ||
| { | ||
| "name": "microsoft/windows-drivers", | ||
| "semanticVersion": "1.3.0+2a7c167ba9555b452f626258191b4709647a936f", | ||
| "locations": [ | ||
| { | ||
| "uri": "file:///C:/codeql-home/WDDST/src/", | ||
| "description": { | ||
| "text": "The QL pack root directory." | ||
| }, | ||
| "properties": { | ||
| "tags": [ | ||
| "CodeQL/LocalPackRoot" | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "uri": "file:///C:/codeql-home/WDDST/src/qlpack.yml", | ||
| "description": { | ||
| "text": "The QL pack definition file." | ||
| }, | ||
| "properties": { | ||
| "tags": [ | ||
| "CodeQL/LocalPackDefinitionFile" | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "codeql/cpp-all", | ||
| "semanticVersion": "3.1.0+d42788844f7ec0a6b9832140313cc2318e513987", | ||
| "locations": [ | ||
| { | ||
| "uri": "file:///C:/Users/jronstadt/.codeql/packages/codeql/cpp-all/3.1.0/", | ||
| "description": { | ||
| "text": "The QL pack root directory." | ||
| }, | ||
| "properties": { | ||
| "tags": [ | ||
| "CodeQL/LocalPackRoot" | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "uri": "file:///C:/Users/jronstadt/.codeql/packages/codeql/cpp-all/3.1.0/qlpack.yml", | ||
| "description": { | ||
| "text": "The QL pack definition file." | ||
| }, | ||
| "properties": { | ||
| "tags": [ | ||
| "CodeQL/LocalPackDefinitionFile" | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| "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.h", | ||
| "uriBaseId": "%SRCROOT%", | ||
| "index": 2 | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "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": "" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "message": { | ||
| "text": "Internal telemetry for the C++ extractor.\n\nNo action needed.", | ||
| "markdown": "Internal telemetry for the C++ extractor.\n\nNo action needed." | ||
| }, | ||
| "level": "note", | ||
| "timeUtc": "2025-01-17T07:55:40.432830800Z", | ||
| "descriptor": { | ||
| "id": "cpp/extractor/summary", | ||
| "index": 1 | ||
| }, | ||
| "properties": { | ||
| "attributes": { | ||
| "cache-hits": 0, | ||
| "cache-misses": 1, | ||
| "extractor-failures": 1, | ||
| "extractor-successes": 0, | ||
| "trap-caching": "disabled" | ||
| }, | ||
| "visibility": { | ||
| "statusPage": false, | ||
| "telemetry": true | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "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/irql-cancel-routine", | ||
| "ruleIndex": 0, | ||
| "rule": { | ||
| "id": "cpp/drivers/irql-cancel-routine", | ||
| "index": 0 | ||
| }, | ||
| "message": { | ||
| "text": "IoReleaseCancelSpinLock inside a cancel routine needs to be called with Irp->CancelIrql" | ||
| }, | ||
| "locations": [ | ||
| { | ||
| "physicalLocation": { | ||
| "artifactLocation": { | ||
| "uri": "driver/fail_driver1.c", | ||
| "uriBaseId": "%SRCROOT%", | ||
| "index": 0 | ||
| }, | ||
| "region": { | ||
| "startLine": 207, | ||
| "startColumn": 5, | ||
| "endColumn": 28 | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "partialFingerprints": { | ||
| "primaryLocationLineHash": "cb9584c3c973d221:1", | ||
| "primaryLocationStartColumnFingerprint": "0" | ||
| } | ||
| } | ||
| ], | ||
| "columnKind": "utf16CodeUnits", | ||
| "properties": { | ||
| "semmle.formatSpecifier": "sarifv2.1.0" | ||
| } | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.