You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/analyzing-data-flow-in-rust.rst
+13-16Lines changed: 13 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ For a more general introduction to modeling data flow, see ":ref:`About data flo
17
17
Local data flow
18
18
---------------
19
19
20
-
Local data flow tracks the flow of data within a single method or callable. Local data flow is easier, faster, and more precise than global data flow. Before looking at more complex tracking, you should always consider local tracking because it is sufficient for many queries.
20
+
Local data flow tracks the flow of data within a single method or callable. Local data flow is easier, faster, and more precise than global data flow. Before using more complex tracking, consider local tracking, as it is sufficient for many queries.
21
21
22
22
Using local data flow
23
23
~~~~~~~~~~~~~~~~~~~~~
@@ -43,13 +43,11 @@ Similarly, you can map a data flow ``ParameterNode`` to its corresponding ``Para
43
43
...
44
44
}
45
45
46
-
47
-
Note that since ``asExpr`` maps from data-flow to control-flow nodes, you then need to call the ``getExpr`` member predicate on the control-flow node to map to the corresponding AST node,
48
-
for example by writing ``node.asExpr().getExpr()``.
46
+
Note that because ``asExpr`` maps from data-flow to control-flow nodes, you need to call the ``getExpr`` member predicate on the control-flow node to map to the corresponding AST node. For example, you can write ``node.asExpr().getExpr()``.
49
47
A control-flow graph considers every way control can flow through code, consequently, there can be multiple data-flow and control-flow nodes associated with a single expression node in the AST.
50
48
51
49
The predicate ``localFlowStep(Node nodeFrom, Node nodeTo)`` holds if there is an immediate data flow edge from the node ``nodeFrom`` to the node ``nodeTo``.
52
-
You can apply the predicate recursively, by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localFlow``.
50
+
You can apply the predicate recursively by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localFlow``.
53
51
54
52
For example, you can find flow from an expression ``source`` to an expression ``sink`` in zero or more local steps:
55
53
@@ -71,7 +69,7 @@ If ``x`` is a tainted string then ``y`` is also tainted.
71
69
72
70
The local taint tracking library is in the module ``TaintTracking``.
73
71
Like local data flow, a predicate ``localTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo)`` holds if there is an immediate taint propagation edge from the node ``nodeFrom`` to the node ``nodeTo``.
74
-
You can apply the predicate recursively, by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localTaint``.
72
+
You can apply the predicate recursively by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localTaint``.
75
73
76
74
For example, you can find taint propagation from an expression ``source`` to an expression ``sink`` in zero or more local steps:
77
75
@@ -83,14 +81,14 @@ For example, you can find taint propagation from an expression ``source`` to an
83
81
Using local sources
84
82
~~~~~~~~~~~~~~~~~~~
85
83
86
-
When exploring local data flow or taint propagation between two expressionsas above, you would normally constrain the expressions to be relevant to your investigation.
87
-
The next section gives some concrete examples, but first it's helpful to introduce the concept of a local source.
84
+
When exploring local data flow or taint propagation between two expressions, such as in the previous example, you typically constrain the expressions to those relevant to your investigation.
85
+
The next section provides concrete examples, but first introduces the concept of a local source.
88
86
89
87
A local source is a data-flow node with no local data flow into it.
90
-
As such, it is a local origin of data flow, a place where a new value is created.
88
+
It is a local origin of data flow, a place where a new value is created.
91
89
This includes parameters (which only receive values from global data flow) and most expressions (because they are not value-preserving).
92
90
The class ``LocalSourceNode`` represents data-flow nodes that are also local sources.
93
-
It comes with a useful member predicate ``flowsTo(DataFlow::Node node)``, which holds if there is local data flow from the local source to ``node``.
91
+
It includes a useful member predicate ``flowsTo(DataFlow::Node node)``, which holds if there is local data flow from the local source to ``node``.
94
92
95
93
Examples of local data flow
96
94
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -105,8 +103,7 @@ This query finds the argument passed in each call to ``File::create``:
105
103
where call.getStaticTarget().(Function).getCanonicalPath() = "<std::fs::File>::create"
106
104
select call.getArg(0)
107
105
108
-
Unfortunately this will only give the expression in the argument, not the values which could be passed to it.
109
-
So we use local data flow to find all expressions that flow into the argument:
106
+
Unfortunately, this only returns the expression used as the argument, not the possible values that could be passed to it. To address this, you can use local data flow to find all expressions that flow into the argument.
110
107
111
108
.. code-block:: ql
112
109
@@ -120,7 +117,7 @@ So we use local data flow to find all expressions that flow into the argument:
120
117
DataFlow::localFlow(source, sink)
121
118
select source, sink
122
119
123
-
We can vary the source, for example, making the source the parameter of a function rather than an expression. The following query finds where a parameter is used for the file creation:
120
+
You can vary the source by making the source the parameter of a function instead of an expression. The following query finds where a parameter is used in file creation:
124
121
125
122
.. code-block:: ql
126
123
@@ -183,8 +180,8 @@ The last line (``module MyDataFlow = ...``) instantiates the parameterized modul
183
180
Using global taint tracking
184
181
~~~~~~~~~~~~~~~~~~~~~~~~~~~
185
182
186
-
Global taint tracking is to global data flow what local taint tracking is to local data flow.
187
-
That is, global taint tracking extends global data flow with additional non-value-preserving steps.
183
+
Global taint tracking relates to global data flow in the same way that local taint tracking relates to local data flow.
184
+
In other words, global taint tracking extends global data flow with additional non-value-preserving steps.
188
185
The global taint tracking library uses the same configuration module as the global data flow library. You can perform taint flow analysis using ``TaintTracking::Global``:
189
186
190
187
.. code-block:: ql
@@ -207,7 +204,7 @@ The following global taint-tracking query finds places where a string literal is
207
204
- Since this is a taint-tracking query, the ``TaintTracking::Global`` module is used.
208
205
- The ``isSource`` predicate defines sources as any ``StringLiteralExpr``.
209
206
- The ``isSink`` predicate defines sinks as arguments to a ``CallExpr`` called "password".
210
-
- The sources and sinks may need tuning to a particular use, for example, if passwords are represented by a type other than ``String`` or passed in arguments of a different name than "password".
207
+
- The sources and sinks may need to be adjusted for a particular use. For example, passwords might be represented by a type other than ``String`` or passed in arguments with a different name than "password".
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/codeql-for-rust.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,5 +12,5 @@ Experiment and learn how to write effective and efficient queries for CodeQL dat
12
12
codeql-library-for-rust
13
13
analyzing-data-flow-in-rust
14
14
15
-
- :doc:`CodeQL library for Rust <codeql-library-for-rust>`: When you're analyzing Rust code, you can make use of the large collection of classes in the CodeQL library for Rust.
15
+
- :doc:`CodeQL library for Rust <codeql-library-for-rust>`: When analyzing Rust code, you can make use of the large collection of classes in the CodeQL library for Rust.
16
16
- :doc:`Analyzing data flow in Rust <analyzing-data-flow-in-rust>`: You can use CodeQL to track the flow of data through a Rust program to places where the data is used.
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/codeql-library-for-rust.rst
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,15 @@
3
3
CodeQL library for Rust
4
4
=================================
5
5
6
-
When you're analyzing Rust code, you can make use of the large collection of classes in the CodeQL library for Rust.
6
+
When analyzing Rust code, you can make use of the large collection of classes in the CodeQL library for Rust.
7
7
8
8
Overview
9
9
--------
10
10
11
11
CodeQL ships with a library for analyzing Rust code. The classes in this library present the data from a CodeQL database in an object-oriented form and provide
12
12
abstractions and predicates to help you with common analysis tasks.
13
13
14
-
The library is implemented as a set of CodeQL modules, that is, files with the extension ``.qll``. The
14
+
The library is implemented as a set of CodeQL modules, which are files with the extension ``.qll``. The
15
15
module `rust.qll <https://github.com/github/codeql/blob/main/rust/ql/lib/rust.qll>`__ imports most other standard library modules, so you can include them
16
16
by beginning your query with:
17
17
@@ -20,27 +20,27 @@ by beginning your query with:
20
20
import rust
21
21
22
22
The CodeQL libraries model various aspects of Rust code. The above import includes the abstract syntax tree (AST) library, which is used for locating program elements
23
-
to match syntactic elements in the source code. This can be used for example to find values, patterns and structures.
23
+
to match syntactic elements in the source code. This can be used to find values, patterns, and structures.
24
24
25
-
The control flow graph (CFG) is imported using
25
+
The control flow graph (CFG) is imported using:
26
26
27
27
.. code-block:: ql
28
28
29
29
import codeql.rust.controlflow.ControlFlowGraph
30
30
31
-
The CFG models the control flow between statements and expressions, for example whether one expression can
31
+
The CFG models the control flow between statements and expressions. For example, it can determine whether one expression can
32
32
be evaluated before another expression, or whether an expression "dominates" another one, meaning that all paths to an
33
33
expression must flow through another expression first.
34
34
35
-
The data flow library is imported using
35
+
The data flow library is imported using:
36
36
37
37
.. code-block:: ql
38
38
39
39
import codeql.rust.dataflow.DataFlow
40
40
41
-
Data flow tracks the flow of data through the program, including through function calls (interprocedural data flow) and between steps in a job or workflow.
42
-
Data flow is particularly useful for security queries, where untrusted data flows to vulnerable parts of the program. Related to data flow is the taint-tracking library,
43
-
which finds how data can *influence* other values in a program, even when it is not copied exactly.
41
+
Data flow tracks the flow of data through the program, including across function calls (interprocedural data flow) and between steps in a job or workflow.
42
+
Data flow is particularly useful for security queries, where untrusted data flows to vulnerable parts of the program. The taint-tracking library is related to data flow,
43
+
and helps you find how data can *influence* other values in a program, even when it is not copied exactly.
0 commit comments