re-optimize without being unsound

This commit is contained in:
Esben Sparre Andreasen
2022-03-17 10:55:55 +01:00
parent e16470a2ae
commit e94e1bb65b
2 changed files with 29 additions and 2 deletions

View File

@@ -34,6 +34,7 @@ module ATM {
*/
pragma[inline]
float getScoreForFlow(DataFlow::Node source, DataFlow::Node sink) {
Optimizations::hasFlow(source, sink) and
shouldResultBeIncluded(source, sink) and
result = unique(float s | s = any(ScoringResults results).getScoreForFlow(source, sink))
}
@@ -120,4 +121,26 @@ module ATM {
)
}
}
/**
* Predicates for performance improvements that should not affect the semantics.
*/
module Optimizations {
/**
* EXPERIMENTAL. This API may change in the future.
*
* Holds if data may flow from `source` to `sink` for *some* configuration.
*
* This is a variant of `Configuration::hasFlow`, that does not require the precense of a source and a sink.
*/
predicate hasFlow(DataFlow::Node source, DataFlow::Node sink) {
exists(DataFlow::Configuration cfg |
exists(DataFlow::SourcePathNode flowsource, DataFlow::SinkPathNode flowsink |
cfg.hasFlowPath(flowsource, flowsink) and
source = flowsource.getNode() and
sink = flowsink.getNode()
)
)
}
}
}

View File

@@ -9,6 +9,7 @@ private import BaseScoring
private import EndpointFeatures as EndpointFeatures
private import FeaturizationConfig
private import EndpointTypes
private import AdaptiveThreatModeling
private string getACompatibleModelChecksum() {
availableMlModels(result, "javascript", _, "atm-endpoint-scoring")
@@ -23,9 +24,11 @@ module ModelScoring {
RelevantFeaturizationConfig() { this = "RelevantFeaturization" }
override DataFlow::Node getAnEndpointToFeaturize() {
getCfg().isEffectiveSource(result)
getCfg().isEffectiveSource(result) and
ATM::Optimizations::hasFlow(result, _)
or
getCfg().isEffectiveSink(result)
getCfg().isEffectiveSink(result) and
ATM::Optimizations::hasFlow(_, result)
}
}
@@ -146,6 +149,7 @@ module Debugging {
query predicate endpointScores = ModelScoring::endpointScores/3;
query predicate shouldResultBeIncluded(DataFlow::Node source, DataFlow::Node sink) {
ATM::Optimizations::hasFlow(source, sink) and
any(ScoringResults scoringResults).shouldResultBeIncluded(source, sink)
}
}