-
Notifications
You must be signed in to change notification settings - Fork 2k
Rust: Add support for defining barriers and barrier guards using models-as-data #21475
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
Changes from 13 commits
bceab0b
f342bae
f9521e9
f455054
d3177b9
e86ce8f
93c6560
2f0d328
c5457d3
77cb353
7d65bac
769b3a6
bde9378
093c279
d82fc67
97ebc0e
8d16a2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * Provides classes and predicates for defining barriers. | ||
| * | ||
| * Flow barriers defined here feed into data flow configurations as follows: | ||
| * | ||
| * ```text | ||
| * data from *.model.yml | QL extensions of FlowBarrier::Range | ||
| * v v | ||
| * FlowBarrier (associated with a models-as-data kind string) | ||
| * v | ||
| * barrierNode predicate | other QL defined barriers, for example using concepts | ||
| * v v | ||
| * various Barrier classes for specific data flow configurations <- extending QueryBarrier | ||
| * ``` | ||
| * | ||
| * New barriers should be defined using models-as-data, QL extensions of | ||
| * `FlowBarrier::Range`, or concepts. Data flow configurations should use the | ||
| * `barrierNode` predicate and/or concepts to define their barriers. | ||
owen-mc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
|
|
||
| private import rust | ||
| private import internal.FlowSummaryImpl as Impl | ||
| private import internal.DataFlowImpl as DataFlowImpl | ||
|
|
||
| // import all instances below | ||
| private module Barriers { | ||
| private import codeql.rust.Frameworks | ||
| private import codeql.rust.dataflow.internal.ModelsAsData | ||
| } | ||
|
|
||
| /** Provides the `Range` class used to define the extent of `FlowBarrier`. */ | ||
| module FlowBarrier { | ||
| /** A flow barrier. */ | ||
| abstract class Range extends Impl::Public::BarrierElement { | ||
| bindingset[this] | ||
| Range() { any() } | ||
|
|
||
| override predicate isBarrier( | ||
| string output, string kind, Impl::Public::Provenance provenance, string model | ||
| ) { | ||
| this.isBarrier(output, kind) and provenance = "manual" and model = "" | ||
| } | ||
|
|
||
| /** | ||
| * Holds if this element is a flow barrier of kind `kind`, where data | ||
| * flows out as described by `output`. | ||
| */ | ||
| predicate isBarrier(string output, string kind) { none() } | ||
| } | ||
| } | ||
|
|
||
| final class FlowBarrier = FlowBarrier::Range; | ||
|
|
||
| /** Provides the `Range` class used to define the extent of `FlowBarrierGuard`. */ | ||
| module FlowBarrierGuard { | ||
| /** A flow barrier guard. */ | ||
| abstract class Range extends Impl::Public::BarrierGuardElement { | ||
| bindingset[this] | ||
| Range() { any() } | ||
|
|
||
| override predicate isBarrierGuard( | ||
| string input, string branch, string kind, Impl::Public::Provenance provenance, string model | ||
| ) { | ||
| this.isBarrierGuard(input, branch, kind) and provenance = "manual" and model = "" | ||
| } | ||
|
|
||
| /** | ||
| * Holds if this element is a flow barrier guard of kind `kind`, for data | ||
| * flowing in as described by `input`, when `this` evaluates to `branch`. | ||
| */ | ||
| predicate isBarrierGuard(string input, string branch, string kind) { none() } | ||
| } | ||
| } | ||
|
|
||
| final class FlowBarrierGuard = FlowBarrierGuard::Range; | ||
|
|
||
| predicate barrierNode = DataFlowImpl::barrierNode/2; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |||||||||||||||||
| */ | ||||||||||||||||||
|
|
||||||||||||||||||
| private import rust | ||||||||||||||||||
| private import codeql.rust.dataflow.FlowBarrier | ||||||||||||||||||
| private import codeql.rust.dataflow.FlowSummary | ||||||||||||||||||
| private import codeql.rust.dataflow.FlowSource | ||||||||||||||||||
| private import codeql.rust.dataflow.FlowSink | ||||||||||||||||||
|
|
@@ -98,6 +99,29 @@ | |||||||||||||||||
| string path, string kind, string provenance, QlBuiltins::ExtensionId madId | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Holds if in a call to the function with canonical path `path`, the value referred | ||||||||||||||||||
| * to by `output` is a barrier of the given `kind` and `madId` is the data | ||||||||||||||||||
| * extension row number. | ||||||||||||||||||
| */ | ||||||||||||||||||
| extensible predicate barrierModel( | ||||||||||||||||||
| string path, string output, string kind, string provenance, QlBuiltins::ExtensionId madId | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Holds if in a call to the function with canonical path `path`, the value referred | ||||||||||||||||||
| * to by `input` is a barrier guard of the given `kind` and `madId` is the data | ||||||||||||||||||
| * extension row number. | ||||||||||||||||||
| * the value referred to by `input` is assumed to lead to a parameter of a call | ||||||||||||||||||
owen-mc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
| * (possibly `self`), and the call is guarding the parameter. | ||||||||||||||||||
| * `branch` is either `true` or `false`, indicating which branch of the guard | ||||||||||||||||||
| * is protecting the parameter. | ||||||||||||||||||
|
||||||||||||||||||
| * the value referred to by `input` is assumed to lead to a parameter of a call | |
| * (possibly `self`), and the call is guarding the parameter. | |
| * `branch` is either `true` or `false`, indicating which branch of the guard | |
| * is protecting the parameter. | |
| * The value referred to by `input` is assumed to lead to a parameter of a call | |
| * (possibly `self`), and the call is guarding the parameter. | |
| * `branch` is either `"true"` or `"false"` (as a string literal), indicating which | |
| * branch of the guard is protecting the parameter. |
Check warning
Code scanning / CodeQL
Missing QLDoc for parameter Warning
Uh oh!
There was an error while loading. Please reload this page.