4444 */
4545
4646private import rust
47+ private import codeql.rust.dataflow.FlowBarrier
4748private import codeql.rust.dataflow.FlowSummary
4849private import codeql.rust.dataflow.FlowSource
4950private import codeql.rust.dataflow.FlowSink
@@ -98,6 +99,29 @@ extensible predicate neutralModel(
9899 string path , string kind , string provenance , QlBuiltins:: ExtensionId madId
99100) ;
100101
102+ /**
103+ * Holds if in a call to the function with canonical path `path`, the value referred
104+ * to by `output` is a barrier of the given `kind` and `madId` is the data
105+ * extension row number.
106+ */
107+ extensible predicate barrierModel (
108+ string path , string output , string kind , string provenance , QlBuiltins:: ExtensionId madId
109+ ) ;
110+
111+ /**
112+ * Holds if in a call to the function with canonical path `path`, the value referred
113+ * to by `input` is a barrier guard of the given `kind` and `madId` is the data
114+ * extension row number.
115+ *
116+ * The value referred to by `input` is assumed to lead to an argument of a call
117+ * (possibly `self`), and the call is guarding the argument. `branch` is either `true`
118+ * or `false`, indicating which branch of the guard is protecting the argument.
119+ */
120+ extensible predicate barrierGuardModel (
121+ string path , string input , string branch , string kind , string provenance ,
122+ QlBuiltins:: ExtensionId madId
123+ ) ;
124+
101125/**
102126 * Holds if the given extension tuple `madId` should pretty-print as `model`.
103127 *
@@ -123,6 +147,16 @@ predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
123147 neutralModel ( path , kind , _, madId ) and
124148 model = "Neutral: " + path + "; " + kind
125149 )
150+ or
151+ exists ( string path , string output , string kind |
152+ barrierModel ( path , output , kind , _, madId ) and
153+ model = "Barrier: " + path + "; " + output + "; " + kind
154+ )
155+ or
156+ exists ( string path , string input , string branch , string kind |
157+ barrierGuardModel ( path , input , branch , kind , _, madId ) and
158+ model = "Barrier guard: " + path + "; " + input + "; " + branch + "; " + kind
159+ )
126160}
127161
128162private class SummarizedCallableFromModel extends SummarizedCallable:: Range {
@@ -206,6 +240,40 @@ private class FlowSinkFromModel extends FlowSink::Range {
206240 }
207241}
208242
243+ private class FlowBarrierFromModel extends FlowBarrier:: Range {
244+ private string path ;
245+
246+ FlowBarrierFromModel ( ) {
247+ barrierModel ( path , _, _, _, _) and
248+ this .callResolvesTo ( path )
249+ }
250+
251+ override predicate isBarrier ( string output , string kind , Provenance provenance , string model ) {
252+ exists ( QlBuiltins:: ExtensionId madId |
253+ barrierModel ( path , output , kind , provenance , madId ) and
254+ model = "MaD:" + madId .toString ( )
255+ )
256+ }
257+ }
258+
259+ private class FlowBarrierGuardFromModel extends FlowBarrierGuard:: Range {
260+ private string path ;
261+
262+ FlowBarrierGuardFromModel ( ) {
263+ barrierGuardModel ( path , _, _, _, _, _) and
264+ this .callResolvesTo ( path )
265+ }
266+
267+ override predicate isBarrierGuard (
268+ string input , string branch , string kind , Provenance provenance , string model
269+ ) {
270+ exists ( QlBuiltins:: ExtensionId madId |
271+ barrierGuardModel ( path , input , branch , kind , provenance , madId ) and
272+ model = "MaD:" + madId .toString ( )
273+ )
274+ }
275+ }
276+
209277private module Debug {
210278 private import FlowSummaryImpl
211279 private import Private
0 commit comments