Skip to content

Commit fdbcd13

Browse files
committed
Added work around for the detection of tainted annotations during the analysis of PRIVATE_STATES_IN_OTHER_PRIVATE_STATES
1 parent 7610af4 commit fdbcd13

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed

go-lisa/src/main/java/it/unive/golisa/GoLiSA.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ public static void main(String[] args) throws AnalysisSetupException, IOExceptio
200200
res[3] = satisfyPhaseRequirements(program, PRIVATE_STATES_IN_PUBLIC_STATES);
201201
res[4] = satisfyPhaseRequirements(program, PRIVATE_STATES_IN_OTHER_PRIVATE_STATES);
202202

203-
204203
if(res[0])
205204
runInformationFlowAnalysis(program, entryLoader, outputDir, dumpOpt, PRIVATE_INPUT_IN_PUBLIC_STATES, PrivacySignatures.privateInputs, PrivacySignatures.publicWriteStatesAndResponsesWithCriticalParams);
206205
else
@@ -221,7 +220,7 @@ public static void main(String[] args) throws AnalysisSetupException, IOExceptio
221220
runInformationFlowAnalysis(program, entryLoader, outputDir, dumpOpt, PRIVATE_STATES_IN_PUBLIC_STATES, PrivacySignatures.privateReadStates, PrivacySignatures.publicWriteStatesAndResponsesWithCriticalParams);
222221
else
223222
LOG.info("Program does not contains at least a source and sink for phase " + PRIVATE_STATES_IN_PUBLIC_STATES);
224-
223+
225224
if(res[4])
226225
runAnalysesForPrivateInOtherPrivateStates(program, entryLoader, outputDir, dumpOpt, policyPath);
227226

@@ -499,13 +498,16 @@ private static void runInformationFlowAnalysis(Program program, EntryPointLoader
499498

500499
Set<Triple<CallType, ? extends CodeAnnotation, CodeMemberDescriptor>> specificCodeMemberAnnotations = new HashSet<>() ;
501500

501+
TaintDomainForPrivacyHF.TAINTED_ANNOTATION.cleanSources();
502+
502503
Set<Call> sourcesTocheckRawData = new HashSet<>();
503504
for(Call source : sources) {
504505
Set<CodeMemberDescriptor> descriptors = getCodeMemberDescriptors(source);
505506
if(descriptors.isEmpty())
506507
sourcesTocheckRawData.add(source);
507508
else
508509
for(CodeMemberDescriptor d : descriptors) {
510+
TaintDomainForPrivacyHF.TAINTED_ANNOTATION.addSource(source);
509511
specificCodeMemberAnnotations.add(Triple.of(source.getCallType(), new MethodAnnotation(TaintDomainForPrivacyHF.TAINTED_ANNOTATION, d.getUnit().getName(), d.getName()), d));
510512
}
511513
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package it.unive.golisa.analysis.taint;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
import it.unive.lisa.program.annotations.Annotation;
7+
8+
import it.unive.lisa.program.cfg.statement.Statement;
9+
10+
public class SourceTrackTaintAnnotation extends Annotation {
11+
12+
private final Set<Statement> sources;
13+
14+
public SourceTrackTaintAnnotation(String annotationName) {
15+
super(annotationName);
16+
sources = new HashSet<>();
17+
}
18+
19+
public Set<Statement> getSources() {
20+
return new HashSet<>(sources);
21+
}
22+
23+
public void addSources(Set<Statement> sources) {
24+
this.sources.addAll(sources);
25+
}
26+
27+
public void addSource(Statement source) {
28+
this.sources.add(source);
29+
}
30+
31+
public void cleanSources() {
32+
sources.clear();
33+
}
34+
35+
}

go-lisa/src/main/java/it/unive/golisa/analysis/taint/TaintDomainForPrivacyHF.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import it.unive.lisa.program.annotations.matcher.AnnotationMatcher;
1717
import it.unive.lisa.program.annotations.matcher.BasicAnnotationMatcher;
1818
import it.unive.lisa.program.cfg.ProgramPoint;
19+
import it.unive.lisa.program.cfg.statement.Statement;
1920
import it.unive.lisa.symbolic.SymbolicExpression;
2021
import it.unive.lisa.symbolic.value.Constant;
2122
import it.unive.lisa.symbolic.value.Identifier;
@@ -42,7 +43,7 @@ public TaintDomainForPrivacyHF evalPushAny(PushAny pushAny, ProgramPoint pp, Sem
4243
/**
4344
* The annotation Tainted.
4445
*/
45-
public static final Annotation TAINTED_ANNOTATION = new Annotation("lisa.taint.Tainted");
46+
public static final SourceTrackTaintAnnotation TAINTED_ANNOTATION = new SourceTrackTaintAnnotation("lisa.taint.Tainted");
4647

4748
/**
4849
* The matcher for the Tainted annotation.
@@ -105,8 +106,17 @@ public TaintDomainForPrivacyHF fixedVariable(Identifier id, ProgramPoint pp, Sem
105106
if (annots.isEmpty())
106107
return BaseNonRelationalValueDomain.super.fixedVariable(id, pp, oracle);
107108

108-
if (annots.contains(TAINTED_MATCHER))
109-
return TAINTED;
109+
for(Annotation a : annots)
110+
if (TAINTED_MATCHER.matches(a)) {
111+
if(a instanceof SourceTrackTaintAnnotation) {
112+
SourceTrackTaintAnnotation stta = (SourceTrackTaintAnnotation) a;
113+
for(Statement src : stta.getSources())
114+
if(src.getLocation().equals(pp.getLocation()))
115+
return TAINTED;
116+
} else
117+
return TAINTED;
118+
}
119+
110120

111121
if (annots.contains(CLEAN_MATCHER))
112122
return CLEAN;

go-lisa/src/main/java/it/unive/golisa/checker/ComputePrivateCollectionFromStatementsChecker.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package it.unive.golisa.checker;
22

3+
import java.util.Collection;
34
import java.util.HashMap;
45
import java.util.HashSet;
56
import java.util.List;
67
import java.util.Map;
78
import java.util.Set;
89

10+
import it.unive.golisa.analysis.taint.TaintDomainForPrivacyHF;
911
import it.unive.golisa.analysis.utilities.PrivacySignatures;
1012
import it.unive.golisa.cfg.utils.CFGUtils;
1113
import it.unive.lisa.analysis.AnalysisState;
@@ -25,6 +27,7 @@
2527
import it.unive.lisa.program.cfg.edge.Edge;
2628
import it.unive.lisa.program.cfg.statement.Statement;
2729
import it.unive.lisa.program.cfg.statement.call.Call;
30+
import it.unive.lisa.program.cfg.statement.call.UnresolvedCall;
2831
import it.unive.lisa.symbolic.SymbolicExpression;
2932
import it.unive.lisa.symbolic.value.ValueExpression;
3033
import it.unive.lisa.type.Type;
@@ -84,9 +87,17 @@ public boolean visit(CheckToolWithAnalysisResults<SimpleAbstractState<PointBased
8487
}
8588

8689
if(PrivacySignatures.isReadPrivateState(call)) {
87-
readers.put(call,collectionValue);
90+
Collection<AnalyzedCFG<SimpleAbstractState<PointBasedHeap, ValueEnvironment<Tarsis>, TypeEnvironment<InferredTypes>>>> result = tool.getResultOf(call.getCFG());
91+
for (AnalyzedCFG<SimpleAbstractState<PointBasedHeap, ValueEnvironment<Tarsis>, TypeEnvironment<InferredTypes>>> analyzedCFG : result) {
92+
Call resolved = (Call) tool.getResolvedVersion((UnresolvedCall) call, analyzedCFG);
93+
readers.put(resolved,collectionValue);
94+
}
8895
} else {
89-
writers.put(call,collectionValue);
96+
Collection<AnalyzedCFG<SimpleAbstractState<PointBasedHeap, ValueEnvironment<Tarsis>, TypeEnvironment<InferredTypes>>>> result = tool.getResultOf(call.getCFG());
97+
for (AnalyzedCFG<SimpleAbstractState<PointBasedHeap, ValueEnvironment<Tarsis>, TypeEnvironment<InferredTypes>>> analyzedCFG : result) {
98+
Call resolved = (Call) tool.getResolvedVersion((UnresolvedCall) call, analyzedCFG);
99+
writers.put(resolved,collectionValue);
100+
}
90101
}
91102

92103
} catch (SemanticException e) {

0 commit comments

Comments
 (0)