Skip to content

Commit baf8916

Browse files
arthaudfacebook-github-bot
authored andcommitted
Rename the complex feature set into the return access path set
Summary: The complex feature set was probably meant to contain different features, but it ended up containing only return access paths. It currently has custom logic for widening access paths, which wouldn't handle other kind of features. Let's rename it as `ReturnAccessPathSet` to prevent any confusion. Reviewed By: dkgi Differential Revision: D28983928 fbshipit-source-id: b40ed09052840ae0ad685a733323b454674d6e87
1 parent c417a10 commit baf8916

File tree

11 files changed

+73
-107
lines changed

11 files changed

+73
-107
lines changed

source/interprocedural_analyses/taint/backwardAnalysis.ml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,10 @@ module AnalysisInstance (FunctionContext : FUNCTION_CONTEXT) = struct
8888

8989

9090
let transform_non_leaves path taint =
91-
let f feature =
92-
match feature with
93-
| Features.Complex.ReturnAccessPath prefix -> Features.Complex.ReturnAccessPath (prefix @ path)
94-
in
91+
let f prefix = prefix @ path in
9592
match path with
9693
| Abstract.TreeDomain.Label.AnyIndex :: _ -> taint
97-
| _ -> BackwardTaint.transform BackwardTaint.complex_feature Map ~f taint
94+
| _ -> BackwardTaint.transform Features.ReturnAccessPathSet.Element Map ~f taint
9895

9996

10097
let read_tree = BackwardState.Tree.read ~transform_non_leaves
@@ -197,13 +194,10 @@ module AnalysisInstance (FunctionContext : FUNCTION_CONTEXT) = struct
197194
let extra_paths =
198195
match kind with
199196
| Sinks.LocalReturn ->
200-
let gather_paths (Features.Complex.ReturnAccessPath extra_path) paths =
201-
extra_path :: paths
202-
in
203197
BackwardTaint.fold
204-
BackwardTaint.complex_feature
198+
Features.ReturnAccessPathSet.Element
205199
element
206-
~f:gather_paths
200+
~f:List.cons
207201
~init:[]
208202
| _ ->
209203
(* No special path handling for side effect taint *)
@@ -1372,7 +1366,7 @@ let extract_tito_and_sink_models define ~is_constructor ~resolution ~existing_ba
13721366
TaintConfiguration.analysis_model_constraints =
13731367
{
13741368
maximum_model_width;
1375-
maximum_complex_access_path_length;
1369+
maximum_return_access_path_length;
13761370
maximum_trace_length;
13771371
maximum_tito_depth;
13781372
_;
@@ -1405,7 +1399,7 @@ let extract_tito_and_sink_models define ~is_constructor ~resolution ~existing_ba
14051399
|> BackwardState.Tree.limit_to
14061400
~transform:(BackwardTaint.add_features Features.widen_broadening)
14071401
~width:maximum_model_width
1408-
|> BackwardState.Tree.approximate_complex_access_paths ~maximum_complex_access_path_length
1402+
|> BackwardState.Tree.approximate_return_access_paths ~maximum_return_access_path_length
14091403
in
14101404

14111405
let split_and_simplify model (parameter, name, original) =

source/interprocedural_analyses/taint/domains.ml

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ module FlowDetails = struct
187187

188188
type 'a slot =
189189
| SimpleFeature : Features.SimpleSet.t slot
190-
| ComplexFeature : Features.ComplexSet.t slot
190+
| ReturnAccessPath : Features.ReturnAccessPathSet.t slot
191191
| TraceLength : TraceLength.t slot
192192
| TitoPosition : Features.TitoPositionSet.t slot
193193
| LeafName : Features.LeafNameSet.t slot
@@ -200,7 +200,7 @@ module FlowDetails = struct
200200
let slot_name (type a) (slot : a slot) =
201201
match slot with
202202
| SimpleFeature -> "SimpleFeature"
203-
| ComplexFeature -> "ComplexFeature"
203+
| ReturnAccessPath -> "ReturnAccessPath"
204204
| TraceLength -> "TraceLength"
205205
| TitoPosition -> "TitoPosition"
206206
| LeafName -> "LeafName"
@@ -211,7 +211,7 @@ module FlowDetails = struct
211211
let slot_domain (type a) (slot : a slot) =
212212
match slot with
213213
| SimpleFeature -> (module Features.SimpleSet : Abstract.Domain.S with type t = a)
214-
| ComplexFeature -> (module Features.ComplexSet : Abstract.Domain.S with type t = a)
214+
| ReturnAccessPath -> (module Features.ReturnAccessPathSet : Abstract.Domain.S with type t = a)
215215
| TraceLength -> (module TraceLength : Abstract.Domain.S with type t = a)
216216
| TitoPosition -> (module Features.TitoPositionSet : Abstract.Domain.S with type t = a)
217217
| LeafName -> (module Features.LeafNameSet : Abstract.Domain.S with type t = a)
@@ -241,10 +241,6 @@ module FlowDetails = struct
241241

242242
let simple_feature_self = Features.SimpleSet.Self
243243

244-
let complex_feature = Features.ComplexSet.Element
245-
246-
let complex_feature_set = Features.ComplexSet.Self
247-
248244
let tito_position_element = Features.TitoPositionSet.Element
249245

250246
let product_pp = pp (* shadow *)
@@ -287,10 +283,6 @@ module type TAINT_DOMAIN = sig
287283

288284
val simple_feature_self : Features.SimpleSet.t Abstract.Domain.part
289285

290-
val complex_feature : Features.Complex.t Abstract.Domain.part
291-
292-
val complex_feature_set : Features.ComplexSet.t Abstract.Domain.part
293-
294286
val first_indices : Features.FirstIndexSet.t Abstract.Domain.part
295287

296288
val first_fields : Features.FirstFieldSet.t Abstract.Domain.part
@@ -383,10 +375,6 @@ end = struct
383375

384376
let simple_feature_element = FlowDetails.simple_feature_element
385377

386-
let complex_feature = FlowDetails.complex_feature
387-
388-
let complex_feature_set = FlowDetails.complex_feature_set
389-
390378
let first_fields = Features.FirstFieldSet.Self
391379

392380
let first_indices = Features.FirstIndexSet.Self
@@ -411,12 +399,10 @@ end = struct
411399
let breadcrumb_json = Features.Breadcrumb.to_json breadcrumb ~on_all_paths:in_under in
412400
breadcrumb_json :: breadcrumbs
413401
in
414-
let gather_return_access_path feature leaves =
415-
match feature with
416-
| Features.Complex.ReturnAccessPath path ->
417-
let path_name = Abstract.TreeDomain.Label.show_path path in
418-
`Assoc ["kind", leaf_kind_json; "name", `String path_name; "depth", `Int trace_length]
419-
:: leaves
402+
let gather_return_access_path path leaves =
403+
let path_name = Abstract.TreeDomain.Label.show_path path in
404+
`Assoc ["kind", leaf_kind_json; "name", `String path_name; "depth", `Int trace_length]
405+
:: leaves
420406
in
421407
let breadcrumbs =
422408
FlowDetails.(fold simple_feature_element ~f:gather_json ~init:[] features)
@@ -437,7 +423,12 @@ end = struct
437423
|> Features.FirstField.to_json
438424
in
439425
( List.concat [first_index_breadcrumbs; first_field_breadcrumbs; breadcrumbs],
440-
FlowDetails.(fold complex_feature ~f:gather_return_access_path ~init:leaves features) )
426+
FlowDetails.(
427+
fold
428+
Features.ReturnAccessPathSet.Element
429+
~f:gather_return_access_path
430+
~init:leaves
431+
features) )
441432
in
442433
let tito_positions =
443434
FlowDetails.get FlowDetails.Slots.TitoPosition features
@@ -587,39 +578,39 @@ module MakeTaintTree (Taint : TAINT_DOMAIN) () = struct
587578

588579
let is_empty = is_bottom
589580

590-
let compute_essential_features ~essential_complex_features tree =
581+
let compute_essential_features ~essential_return_access_paths tree =
591582
let essential_trace_info = function
592583
| _ -> TraceInfo.Declaration { leaf_name_provided = false }
593584
in
594585
let essential_simple_features _ = Features.SimpleSet.bottom in
595586
let essential_tito_positions _ = Features.TitoPositionSet.bottom in
596587
let essential_leaf_names _ = Features.LeafNameSet.bottom in
597588
transform Taint.trace_info Map ~f:essential_trace_info tree
598-
|> transform Features.ComplexSet.Self Map ~f:essential_complex_features
589+
|> transform Features.ReturnAccessPathSet.Self Map ~f:essential_return_access_paths
599590
|> transform Features.SimpleSet.Self Map ~f:essential_simple_features
600591
|> transform Features.TitoPositionSet.Self Map ~f:essential_tito_positions
601592
|> transform Features.LeafNameSet.Self Map ~f:essential_leaf_names
602593

603594

604595
(* Keep only non-essential structure. *)
605596
let essential tree =
606-
let essential_complex_features _ = Features.ComplexSet.bottom in
607-
compute_essential_features ~essential_complex_features tree
597+
let essential_return_access_paths _ = Features.ReturnAccessPathSet.bottom in
598+
compute_essential_features ~essential_return_access_paths tree
608599

609600

610601
let essential_for_constructor tree =
611-
let essential_complex_features set = set in
612-
compute_essential_features ~essential_complex_features tree
602+
let essential_return_access_paths set = set in
603+
compute_essential_features ~essential_return_access_paths tree
613604

614605

615-
let approximate_complex_access_paths ~maximum_complex_access_path_length tree =
606+
let approximate_return_access_paths ~maximum_return_access_path_length tree =
616607
let cut_off features =
617-
if Features.ComplexSet.count features > maximum_complex_access_path_length then
618-
Features.ComplexSet.singleton (Features.Complex.ReturnAccessPath [])
608+
if Features.ReturnAccessPathSet.count features > maximum_return_access_path_length then
609+
Features.ReturnAccessPathSet.singleton []
619610
else
620611
features
621612
in
622-
transform Taint.complex_feature_set Map ~f:cut_off tree
613+
transform Features.ReturnAccessPathSet.Self Map ~f:cut_off tree
623614

624615

625616
let prune_maximum_length maximum_length =
@@ -742,6 +733,6 @@ let local_return_taint =
742733
Part (BackwardTaint.trace_info, TraceInfo.Declaration { leaf_name_provided = false });
743734
Part (BackwardTaint.leaf, Sinks.LocalReturn);
744735
Part (TraceLength.Self, 0);
745-
Part (BackwardTaint.complex_feature, Features.Complex.ReturnAccessPath []);
736+
Part (Features.ReturnAccessPathSet.Element, []);
746737
Part (Features.SimpleSet.Self, Features.SimpleSet.empty);
747738
]

source/interprocedural_analyses/taint/features.ml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,34 +179,26 @@ end
179179

180180
module SimpleSet = Abstract.OverUnderSetDomain.Make (Simple)
181181

182-
(* Set of complex features, where element can be abstracted and joins are expensive. Should only be
183-
used for elements that need this kind of joining. *)
184-
module Complex = struct
185-
let name = "complex features"
182+
module ReturnAccessPath = struct
183+
let name = "return access paths"
186184

187-
type t = ReturnAccessPath of Abstract.TreeDomain.Label.path
188-
[@@deriving show { with_path = false }, compare]
189-
190-
let less_or_equal ~left ~right =
191-
match left, right with
192-
| ReturnAccessPath left_path, ReturnAccessPath right_path ->
193-
Abstract.TreeDomain.Label.is_prefix ~prefix:right_path left_path
185+
type t = Abstract.TreeDomain.Label.path [@@deriving show { with_path = false }, compare]
194186

187+
let less_or_equal ~left ~right = Abstract.TreeDomain.Label.is_prefix ~prefix:right left
195188

196189
let widen set =
197190
let truncate = function
198-
| ReturnAccessPath p when List.length p > TaintConfiguration.maximum_return_access_path_depth
199-
->
200-
ReturnAccessPath (List.take p TaintConfiguration.maximum_return_access_path_depth)
191+
| p when List.length p > TaintConfiguration.maximum_return_access_path_depth ->
192+
List.take p TaintConfiguration.maximum_return_access_path_depth
201193
| x -> x
202194
in
203195
if List.length set > TaintConfiguration.maximum_return_access_path_width then
204-
[ReturnAccessPath []]
196+
[[]]
205197
else
206198
List.map ~f:truncate set
207199
end
208200

209-
module ComplexSet = Abstract.ElementSetDomain.Make (Complex)
201+
module ReturnAccessPathSet = Abstract.ElementSetDomain.Make (ReturnAccessPath)
210202

211203
let obscure = Simple.Breadcrumb Breadcrumb.Obscure
212204

source/interprocedural_analyses/taint/forwardAnalysis.ml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,10 @@ module AnalysisInstance (FunctionContext : FUNCTION_CONTEXT) = struct
232232
let return_paths =
233233
match kind with
234234
| Sinks.LocalReturn ->
235-
let gather_paths (Features.Complex.ReturnAccessPath extra_path) paths =
236-
extra_path :: paths
237-
in
238235
BackwardTaint.fold
239-
BackwardTaint.complex_feature
236+
Features.ReturnAccessPathSet.Element
240237
return_taint
241-
~f:gather_paths
238+
~f:List.cons
242239
~init:[]
243240
| _ ->
244241
(* No special handling of paths for side effects *)
@@ -1574,7 +1571,7 @@ let extract_source_model ~define ~resolution ~features_to_attach exit_taint =
15741571
let return_type_breadcrumbs = Features.type_breadcrumbs ~resolution return_annotation in
15751572
let {
15761573
TaintConfiguration.analysis_model_constraints =
1577-
{ maximum_model_width; maximum_complex_access_path_length; maximum_trace_length; _ };
1574+
{ maximum_model_width; maximum_return_access_path_length; maximum_trace_length; _ };
15781575
_;
15791576
}
15801577
=
@@ -1600,7 +1597,7 @@ let extract_source_model ~define ~resolution ~features_to_attach exit_taint =
16001597
|> ForwardState.Tree.limit_to
16011598
~transform:(ForwardTaint.add_features Features.widen_broadening)
16021599
~width:maximum_model_width
1603-
|> ForwardState.Tree.approximate_complex_access_paths ~maximum_complex_access_path_length
1600+
|> ForwardState.Tree.approximate_return_access_paths ~maximum_return_access_path_length
16041601
in
16051602
let attach_features taint =
16061603
if not (Features.SimpleSet.is_bottom features_to_attach) then

source/interprocedural_analyses/taint/model.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,9 @@ let infer_class_models ~environment =
336336
let fold_taint position existing_state attribute =
337337
let leaf =
338338
BackwardState.Tree.create_leaf (BackwardTaint.singleton Sinks.LocalReturn)
339-
|> BackwardState.Tree.transform BackwardTaint.complex_feature_set Map ~f:(fun _ ->
340-
Features.ComplexSet.singleton
341-
(Features.Complex.ReturnAccessPath
342-
[Abstract.TreeDomain.Label.create_name_index attribute]))
339+
|> BackwardState.Tree.transform Features.ReturnAccessPathSet.Self Map ~f:(fun _ ->
340+
Features.ReturnAccessPathSet.singleton
341+
[Abstract.TreeDomain.Label.create_name_index attribute])
343342
in
344343
BackwardState.assign
345344
~root:

source/interprocedural_analyses/taint/taintConfiguration.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let empty_implicit_sources = { literal_strings = [] }
4444

4545
type analysis_model_constraints = {
4646
maximum_model_width: int;
47-
maximum_complex_access_path_length: int;
47+
maximum_return_access_path_length: int;
4848
maximum_overrides_to_analyze: int option;
4949
maximum_trace_length: int option;
5050
maximum_tito_depth: int option;
@@ -53,7 +53,7 @@ type analysis_model_constraints = {
5353
let default_analysis_model_constraints =
5454
{
5555
maximum_model_width = 25;
56-
maximum_complex_access_path_length = 10;
56+
maximum_return_access_path_length = 10;
5757
maximum_overrides_to_analyze = None;
5858
maximum_trace_length = None;
5959
maximum_tito_depth = None;

source/interprocedural_analyses/taint/taintConfiguration.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type implicit_sources = { literal_strings: literal_string_source list }
3838

3939
type analysis_model_constraints = {
4040
maximum_model_width: int;
41-
maximum_complex_access_path_length: int;
41+
maximum_return_access_path_length: int;
4242
maximum_overrides_to_analyze: int option;
4343
maximum_trace_length: int option;
4444
maximum_tito_depth: int option;

source/interprocedural_analyses/taint/test/domainTest.ml

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ let test_partition_call_map _ =
5959
assert_equal ~msg:"matches must be equal to original" ~printer:ForwardTaint.show matches joined
6060

6161

62-
let test_approximate_complex_access_paths _ =
63-
let assert_approximate_complex_access_paths ~expected ~cutoff_at tree =
62+
let test_approximate_return_access_paths _ =
63+
let assert_approximate_return_access_paths ~expected ~cutoff_at tree =
6464
let compare left right =
6565
ForwardState.Tree.less_or_equal ~left ~right
6666
&& ForwardState.Tree.less_or_equal ~left:right ~right:left
@@ -69,51 +69,44 @@ let test_approximate_complex_access_paths _ =
6969
~cmp:compare
7070
~printer:ForwardState.Tree.show
7171
expected
72-
(ForwardState.Tree.approximate_complex_access_paths
73-
~maximum_complex_access_path_length:cutoff_at
72+
(ForwardState.Tree.approximate_return_access_paths
73+
~maximum_return_access_path_length:cutoff_at
7474
tree)
7575
in
76-
let create ~features =
76+
let create ~return_access_paths =
7777
ForwardState.Tree.create_leaf (ForwardTaint.singleton (Sources.NamedSource "Demo"))
78-
|> ForwardState.Tree.transform ForwardTaint.complex_feature_set Map ~f:(fun _ ->
79-
Features.ComplexSet.of_list features)
78+
|> ForwardState.Tree.transform Features.ReturnAccessPathSet.Self Map ~f:(fun _ ->
79+
Features.ReturnAccessPathSet.of_list return_access_paths)
8080
in
81-
assert_approximate_complex_access_paths
82-
~expected:
83-
(create ~features:[Features.Complex.ReturnAccessPath [Abstract.TreeDomain.Label.Index "a"]])
81+
assert_approximate_return_access_paths
82+
~expected:(create ~return_access_paths:[[Abstract.TreeDomain.Label.Index "a"]])
8483
~cutoff_at:2
85-
(create ~features:[Features.Complex.ReturnAccessPath [Abstract.TreeDomain.Label.Index "a"]]);
86-
assert_approximate_complex_access_paths
84+
(create ~return_access_paths:[[Abstract.TreeDomain.Label.Index "a"]]);
85+
assert_approximate_return_access_paths
8786
~expected:
8887
(create
89-
~features:
90-
[
91-
Features.Complex.ReturnAccessPath [Abstract.TreeDomain.Label.Index "a"];
92-
Features.Complex.ReturnAccessPath [Abstract.TreeDomain.Label.Index "b"];
93-
])
88+
~return_access_paths:
89+
[[Abstract.TreeDomain.Label.Index "a"]; [Abstract.TreeDomain.Label.Index "b"]])
9490
~cutoff_at:2
9591
(create
96-
~features:
97-
[
98-
Features.Complex.ReturnAccessPath [Abstract.TreeDomain.Label.Index "a"];
99-
Features.Complex.ReturnAccessPath [Abstract.TreeDomain.Label.Index "b"];
100-
]);
101-
assert_approximate_complex_access_paths
102-
~expected:(create ~features:[Features.Complex.ReturnAccessPath []])
92+
~return_access_paths:
93+
[[Abstract.TreeDomain.Label.Index "a"]; [Abstract.TreeDomain.Label.Index "b"]]);
94+
assert_approximate_return_access_paths
95+
~expected:(create ~return_access_paths:[[]])
10396
~cutoff_at:2
10497
(create
105-
~features:
98+
~return_access_paths:
10699
[
107-
Features.Complex.ReturnAccessPath [Abstract.TreeDomain.Label.Index "a"];
108-
Features.Complex.ReturnAccessPath [Abstract.TreeDomain.Label.Index "b"];
109-
Features.Complex.ReturnAccessPath [Abstract.TreeDomain.Label.Index "c"];
100+
[Abstract.TreeDomain.Label.Index "a"];
101+
[Abstract.TreeDomain.Label.Index "b"];
102+
[Abstract.TreeDomain.Label.Index "c"];
110103
])
111104

112105

113106
let () =
114107
"taint_domain"
115108
>::: [
116109
"partition_call_map" >:: test_partition_call_map;
117-
"approximate_complex_access_paths" >:: test_approximate_complex_access_paths;
110+
"approximate_return_access_paths" >:: test_approximate_return_access_paths;
118111
]
119112
|> Test.run

0 commit comments

Comments
 (0)