Skip to content

Commit e37aab5

Browse files
committed
C++: Suppress FieldAddressInstruction taint
See code comment. This fixes false positives on openjdk/jdk.
1 parent 3b76509 commit e37aab5

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/dataflow/DefaultTaintTracking.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,15 @@ private predicate instructionTaintStep(Instruction i1, Instruction i2) {
187187
// Flow through pointer dereference
188188
i2.(LoadInstruction).getSourceAddress() = i1
189189
or
190-
i2.(UnaryInstruction).getUnary() = i1
190+
// Unary instructions tend to preserve enough information in practice that we
191+
// want taint to flow through.
192+
// The exception is `FieldAddressInstruction`. Together with the rule for
193+
// `LoadInstruction` above and for `ChiInstruction` below, flow through
194+
// `FieldAddressInstruction` could cause flow into one field to come out an
195+
// unrelated field. This would happen across function boundaries, where the IR
196+
// would not be able to match loads to stores.
197+
i2.(UnaryInstruction).getUnary() = i1 and
198+
not i2 instanceof FieldAddressInstruction
191199
or
192200
i2.(ChiInstruction).getPartial() = i1 and
193201
not i2.isResultConflated()

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/defaulttainttracking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ struct Point {
9393
int y;
9494

9595
void callSink() {
96-
sink(this->x); // tainted
97-
sink(this->y); // not tainted [FALSE POSITIVE]
96+
sink(this->x); // tainted [NOT DETECTED]
97+
sink(this->y); // not tainted
9898
}
9999
};
100100

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/tainted.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@
103103
| defaulttainttracking.cpp:88:18:88:23 | call to getenv | test_diff.cpp:1:11:1:20 | p#0 |
104104
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:10:11:10:13 | p#0 |
105105
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:96:10:96:13 | this |
106-
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:96:16:96:16 | x |
107106
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:97:10:97:13 | this |
108-
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:97:16:97:16 | y |
109107
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:103:9:103:14 | call to getenv |
110108
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:103:9:103:24 | (int)... |
111109
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:103:9:103:24 | access to array |

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/test_diff.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
| defaulttainttracking.cpp:88:18:88:23 | call to getenv | test_diff.cpp:1:11:1:20 | p#0 | IR only |
1818
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:10:11:10:13 | p#0 | IR only |
1919
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:96:10:96:13 | this | IR only |
20-
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:96:16:96:16 | x | IR only |
2120
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:97:10:97:13 | this | IR only |
22-
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:97:16:97:16 | y | IR only |
2321
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:103:5:103:5 | x | AST only |
2422
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:104:10:104:10 | x | IR only |
2523
| defaulttainttracking.cpp:103:9:103:14 | call to getenv | defaulttainttracking.cpp:106:3:106:3 | p | IR only |

0 commit comments

Comments
 (0)