@@ -129,7 +129,9 @@ module ModelValidation {
129129 summaryModel(_, _, _, _, _, _, path, _, _, _, _) or
130130 summaryModel(_, _, _, _, _, _, _, path, _, _, _) or
131131 sinkModel(_, _, _, _, _, _, path, _, _, _) or
132- sourceModel(_, _, _, _, _, _, path, _, _, _)
132+ sourceModel(_, _, _, _, _, _, path, _, _, _) or
133+ barrierModel(_, _, _, _, _, _, path, _, _, _) or
134+ barrierGuardModel(_, _, _, _, _, _, path, _, _, _, _)
133135 }
134136
135137 private module MkAccessPath = AccessPathSyntax::AccessPath<getRelevantAccessPath/1>;
@@ -142,6 +144,8 @@ module ModelValidation {
142144 exists(string pred, AccessPath input, AccessPathToken part |
143145 sinkModel(_, _, _, _, _, _, input, _, _, _) and pred = "sink"
144146 or
147+ barrierGuardModel(_, _, _, _, _, _, input, _, _, _, _) and pred = "barrier guard"
148+ or
145149 summaryModel(_, _, _, _, _, _, input, _, _, _, _) and pred = "summary"
146150 |
147151 (
@@ -164,6 +168,8 @@ module ModelValidation {
164168 exists(string pred, AccessPath output, AccessPathToken part |
165169 sourceModel(_, _, _, _, _, _, output, _, _, _) and pred = "source"
166170 or
171+ barrierModel(_, _, _, _, _, _, output, _, _, _) and pred = "barrier"
172+ or
167173 summaryModel(_, _, _, _, _, _, _, output, _, _, _) and pred = "summary"
168174 |
169175 (
@@ -181,7 +187,13 @@ module ModelValidation {
181187 private module KindValConfig implements SharedModelVal::KindValidationConfigSig {
182188 predicate summaryKind(string kind) { summaryModel(_, _, _, _, _, _, _, _, kind, _, _) }
183189
184- predicate sinkKind(string kind) { sinkModel(_, _, _, _, _, _, _, kind, _, _) }
190+ predicate sinkKind(string kind) {
191+ sinkModel(_, _, _, _, _, _, _, kind, _, _)
192+ or
193+ barrierModel(_, _, _, _, _, _, _, kind, _, _)
194+ or
195+ barrierGuardModel(_, _, _, _, _, _, _, _, kind, _, _)
196+ }
185197
186198 predicate sourceKind(string kind) { sourceModel(_, _, _, _, _, _, _, kind, _, _) }
187199
@@ -199,6 +211,11 @@ module ModelValidation {
199211 or
200212 sinkModel(package, type, _, name, signature, ext, _, _, provenance, _) and pred = "sink"
201213 or
214+ barrierModel(package, type, _, name, signature, ext, _, _, provenance, _) and pred = "barrier"
215+ or
216+ barrierGuardModel(package, type, _, name, signature, ext, _, _, _, provenance, _) and
217+ pred = "barrier guard"
218+ or
202219 summaryModel(package, type, _, name, signature, ext, _, _, _, provenance, _) and
203220 pred = "summary"
204221 or
@@ -224,6 +241,14 @@ module ModelValidation {
224241 invalidProvenance(provenance) and
225242 result = "Unrecognized provenance description \"" + provenance + "\" in " + pred + " model."
226243 )
244+ or
245+ exists(string acceptingvalue |
246+ barrierGuardModel(_, _, _, _, _, _, _, acceptingvalue, _, _, _) and
247+ invalidAcceptingValue(acceptingvalue) and
248+ result =
249+ "Unrecognized accepting value description \"" + acceptingvalue +
250+ "\" in barrier guard model."
251+ )
227252 }
228253
229254 private string getInvalidPackageGroup() {
@@ -232,6 +257,11 @@ module ModelValidation {
232257 or
233258 FlowExtensions::sinkModel(package, _, _, _, _, _, _, _, _, _) and pred = "sink"
234259 or
260+ FlowExtensions::barrierModel(package, _, _, _, _, _, _, _, _, _) and pred = "barrier"
261+ or
262+ FlowExtensions::barrierGuardModel(package, _, _, _, _, _, _, _, _, _, _) and
263+ pred = "barrier guard"
264+ or
235265 FlowExtensions::summaryModel(package, _, _, _, _, _, _, _, _, _, _) and
236266 pred = "summary"
237267 or
@@ -262,6 +292,10 @@ private predicate elementSpec(
262292 or
263293 sinkModel(package, type, subtypes, name, signature, ext, _, _, _, _)
264294 or
295+ barrierModel(package, type, subtypes, name, signature, ext, _, _, _, _)
296+ or
297+ barrierGuardModel(package, type, subtypes, name, signature, ext, _, _, _, _, _)
298+ or
265299 summaryModel(package, type, subtypes, name, signature, ext, _, _, _, _, _)
266300 or
267301 neutralModel(package, type, name, signature, _, _) and ext = "" and subtypes = false
@@ -397,6 +431,54 @@ private module Cached {
397431 isSinkNode(n, kind, model) and n.asNode() = node
398432 )
399433 }
434+
435+ private newtype TKindModelPair =
436+ TMkPair(string kind, string model) { isBarrierGuardNode(_, _, kind, model) }
437+
438+ private boolean convertAcceptingValue(Public::AcceptingValue av) {
439+ av.isTrue() and result = true
440+ or
441+ av.isFalse() and result = false
442+ // Remaining cases are not supported yet, they depend on the shared Guards library.
443+ // or
444+ // av.isNoException() and result.getDualValue().isThrowsException()
445+ // or
446+ // av.isZero() and result.asIntValue() = 0
447+ // or
448+ // av.isNotZero() and result.getDualValue().asIntValue() = 0
449+ // or
450+ // av.isNull() and result.isNullValue()
451+ // or
452+ // av.isNotNull() and result.isNonNullValue()
453+ }
454+
455+ private predicate barrierGuardChecks(DataFlow::Node g, Expr e, boolean gv, TKindModelPair kmp) {
456+ exists(
457+ SourceSinkInterpretationInput::InterpretNode n, Public::AcceptingValue acceptingvalue,
458+ string kind, string model
459+ |
460+ isBarrierGuardNode(n, acceptingvalue, kind, model) and
461+ n.asNode().asExpr() = e and
462+ kmp = TMkPair(kind, model) and
463+ gv = convertAcceptingValue(acceptingvalue)
464+ |
465+ g.asExpr().(CallExpr).getAnArgument() = e // TODO: qualifier?
466+ )
467+ }
468+
469+ /**
470+ * Holds if `node` is specified as a barrier with the given kind in a MaD flow
471+ * model.
472+ */
473+ cached
474+ predicate barrierNode(DataFlow::Node node, string kind, string model) {
475+ exists(SourceSinkInterpretationInput::InterpretNode n |
476+ isBarrierNode(n, kind, model) and n.asNode() = node
477+ )
478+ or
479+ DataFlow::ParameterizedBarrierGuard<TKindModelPair, barrierGuardChecks/4>::getABarrierNode(TMkPair(kind,
480+ model)) = node
481+ }
400482}
401483
402484import Cached
@@ -413,6 +495,12 @@ predicate sourceNode(DataFlow::Node node, string kind) { sourceNode(node, kind,
413495 */
414496predicate sinkNode(DataFlow::Node node, string kind) { sinkNode(node, kind, _) }
415497
498+ /**
499+ * Holds if `node` is specified as a barrier with the given kind in a MaD flow
500+ * model.
501+ */
502+ predicate barrierNode(DataFlow::Node node, string kind) { barrierNode(node, kind, _) }
503+
416504// adapter class for converting Mad summaries to `SummarizedCallable`s
417505private class SummarizedCallableAdapter extends Public::SummarizedCallable {
418506 SummarizedCallableAdapter() { summaryElement(this, _, _, _, _, _) }
0 commit comments