Skip to content

Commit b61a439

Browse files
authored
Merge pull request #21020 from hvitved/shared/source-sink-provenance-prio
Shared: Prefer source/sink models with manual provenance over generated
2 parents c5987b4 + 0b00589 commit b61a439

File tree

7 files changed

+187
-217
lines changed

7 files changed

+187
-217
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowDispatch.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private module DispatchImpl {
6060
not (
6161
// Only use summarized callables with generated summaries in case
6262
// the static call target is not in the source code.
63-
// Note that if applyGeneratedModel holds it implies that there doesn't
63+
// Note that if `applyGeneratedModel` holds it implies that there doesn't
6464
// exist a manual model.
6565
exists(Callable staticTarget | staticTarget = call.getCallee().getSourceDeclaration() |
6666
staticTarget.fromSource() and not staticTarget.isStub()

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,15 @@ module RustDataFlow implements InputSig<Location> {
445445
or
446446
exists(SummarizedCallable sc, Function staticTarget |
447447
staticTarget = getStaticTargetExt(c) and
448-
sc = result.asSummarizedCallable()
448+
sc = result.asSummarizedCallable() and
449+
// Only use summarized callables with generated summaries in case
450+
// the static call target is not in the source code.
451+
// Note that if `applyGeneratedModel` holds it implies that there doesn't
452+
// exist a manual model.
453+
not (
454+
staticTarget.fromSource() and
455+
sc.applyGeneratedModel()
456+
)
449457
|
450458
sc = staticTarget
451459
or

rust/ql/test/library-tests/dataflow/sources/file/InlineFlow.expected

Lines changed: 64 additions & 96 deletions
Large diffs are not rendered by default.

rust/ql/test/library-tests/dataflow/sources/file/TaintSources.expected

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
| test.rs:12:31:12:43 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
2-
| test.rs:12:31:12:43 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
3-
| test.rs:17:31:17:38 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
42
| test.rs:17:31:17:38 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
53
| test.rs:22:22:22:39 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
6-
| test.rs:22:22:22:39 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
74
| test.rs:26:18:26:29 | ...::read_dir | Flow source 'FileSource' of type file (DEFAULT). |
85
| test.rs:29:22:29:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
96
| test.rs:43:27:43:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
@@ -15,8 +12,6 @@
1512
| test.rs:79:31:79:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
1613
| test.rs:84:22:84:46 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
1714
| test.rs:90:26:90:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
18-
| test.rs:90:26:90:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
19-
| test.rs:91:31:91:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
2015
| test.rs:91:31:91:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
2116
| test.rs:97:22:97:41 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
2217
| test.rs:107:20:107:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |

rust/ql/test/query-tests/security/CWE-312/CleartextLogging.expected

Lines changed: 85 additions & 101 deletions
Large diffs are not rendered by default.

rust/ql/test/query-tests/security/CWE-825/AccessInvalidPointer.expected

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
| deallocation.rs:95:5:95:31 | ...::write::<...> | deallocation.rs:70:3:70:21 | ...::dealloc | deallocation.rs:95:5:95:31 | ...::write::<...> | This operation dereferences a pointer that may be $@. | deallocation.rs:70:3:70:21 | ...::dealloc | invalid |
1111
| deallocation.rs:115:13:115:18 | my_ptr | deallocation.rs:112:3:112:12 | ...::free | deallocation.rs:115:13:115:18 | my_ptr | This operation dereferences a pointer that may be $@. | deallocation.rs:112:3:112:12 | ...::free | invalid |
1212
| deallocation.rs:130:14:130:15 | p1 | deallocation.rs:123:23:123:40 | ...::dangling | deallocation.rs:130:14:130:15 | p1 | This operation dereferences a pointer that may be $@. | deallocation.rs:123:23:123:40 | ...::dangling | invalid |
13-
| deallocation.rs:130:14:130:15 | p1 | deallocation.rs:123:23:123:40 | ...::dangling | deallocation.rs:130:14:130:15 | p1 | This operation dereferences a pointer that may be $@. | deallocation.rs:123:23:123:40 | ...::dangling | invalid |
1413
| deallocation.rs:131:14:131:15 | p2 | deallocation.rs:124:21:124:42 | ...::dangling_mut | deallocation.rs:131:14:131:15 | p2 | This operation dereferences a pointer that may be $@. | deallocation.rs:124:21:124:42 | ...::dangling_mut | invalid |
1514
| deallocation.rs:132:14:132:15 | p3 | deallocation.rs:125:23:125:36 | ...::null | deallocation.rs:132:14:132:15 | p3 | This operation dereferences a pointer that may be $@. | deallocation.rs:125:23:125:36 | ...::null | invalid |
1615
| deallocation.rs:163:13:163:15 | ptr | deallocation.rs:159:9:159:26 | ...::null_mut | deallocation.rs:163:13:163:15 | ptr | This operation dereferences a pointer that may be $@. | deallocation.rs:159:9:159:26 | ...::null_mut | invalid |
@@ -27,8 +26,6 @@
2726
| deallocation.rs:210:7:210:9 | ptr | deallocation.rs:207:9:207:26 | ...::null_mut | deallocation.rs:210:7:210:9 | ptr | This operation dereferences a pointer that may be $@. | deallocation.rs:207:9:207:26 | ...::null_mut | invalid |
2827
| deallocation.rs:226:13:226:21 | const_ptr | deallocation.rs:219:15:219:32 | ...::null_mut | deallocation.rs:226:13:226:21 | const_ptr | This operation dereferences a pointer that may be $@. | deallocation.rs:219:15:219:32 | ...::null_mut | invalid |
2928
| deallocation.rs:274:15:274:16 | p1 | deallocation.rs:270:3:270:25 | ...::drop_in_place | deallocation.rs:274:15:274:16 | p1 | This operation dereferences a pointer that may be $@. | deallocation.rs:270:3:270:25 | ...::drop_in_place | invalid |
30-
| deallocation.rs:274:15:274:16 | p1 | deallocation.rs:270:3:270:25 | ...::drop_in_place | deallocation.rs:274:15:274:16 | p1 | This operation dereferences a pointer that may be $@. | deallocation.rs:270:3:270:25 | ...::drop_in_place | invalid |
31-
| deallocation.rs:342:18:342:20 | ptr | deallocation.rs:336:3:336:25 | ...::drop_in_place | deallocation.rs:342:18:342:20 | ptr | This operation dereferences a pointer that may be $@. | deallocation.rs:336:3:336:25 | ...::drop_in_place | invalid |
3229
| deallocation.rs:342:18:342:20 | ptr | deallocation.rs:336:3:336:25 | ...::drop_in_place | deallocation.rs:342:18:342:20 | ptr | This operation dereferences a pointer that may be $@. | deallocation.rs:336:3:336:25 | ...::drop_in_place | invalid |
3330
edges
3431
| deallocation.rs:20:3:20:21 | ...::dealloc | deallocation.rs:20:23:20:24 | [post] m1 | provenance | Src:MaD:3 MaD:3 |
@@ -49,7 +46,6 @@ edges
4946
| deallocation.rs:112:14:112:40 | [post] my_ptr as ... | deallocation.rs:115:13:115:18 | my_ptr | provenance | |
5047
| deallocation.rs:123:6:123:7 | p1 | deallocation.rs:130:14:130:15 | p1 | provenance | |
5148
| deallocation.rs:123:23:123:40 | ...::dangling | deallocation.rs:123:23:123:42 | ...::dangling(...) | provenance | Src:MaD:4 MaD:4 |
52-
| deallocation.rs:123:23:123:40 | ...::dangling | deallocation.rs:123:23:123:42 | ...::dangling(...) | provenance | Src:MaD:4 MaD:4 |
5349
| deallocation.rs:123:23:123:42 | ...::dangling(...) | deallocation.rs:123:6:123:7 | p1 | provenance | |
5450
| deallocation.rs:124:6:124:7 | p2 | deallocation.rs:131:14:131:15 | p2 | provenance | |
5551
| deallocation.rs:124:21:124:42 | ...::dangling_mut | deallocation.rs:124:21:124:44 | ...::dangling_mut(...) | provenance | Src:MaD:5 MaD:5 |
@@ -83,10 +79,8 @@ edges
8379
| deallocation.rs:219:15:219:32 | ...::null_mut | deallocation.rs:219:15:219:34 | ...::null_mut(...) | provenance | Src:MaD:8 MaD:8 |
8480
| deallocation.rs:219:15:219:34 | ...::null_mut(...) | deallocation.rs:219:3:219:11 | const_ptr | provenance | |
8581
| deallocation.rs:270:3:270:25 | ...::drop_in_place | deallocation.rs:270:27:270:28 | [post] p1 | provenance | Src:MaD:6 MaD:6 |
86-
| deallocation.rs:270:3:270:25 | ...::drop_in_place | deallocation.rs:270:27:270:28 | [post] p1 | provenance | Src:MaD:6 MaD:6 |
8782
| deallocation.rs:270:27:270:28 | [post] p1 | deallocation.rs:274:15:274:16 | p1 | provenance | |
8883
| deallocation.rs:336:3:336:25 | ...::drop_in_place | deallocation.rs:336:27:336:29 | [post] ptr | provenance | Src:MaD:6 MaD:6 |
89-
| deallocation.rs:336:3:336:25 | ...::drop_in_place | deallocation.rs:336:27:336:29 | [post] ptr | provenance | Src:MaD:6 MaD:6 |
9084
| deallocation.rs:336:27:336:29 | [post] ptr | deallocation.rs:342:18:342:20 | ptr | provenance | |
9185
models
9286
| 1 | Sink: core::ptr::read; Argument[0]; pointer-access |
@@ -120,7 +114,6 @@ nodes
120114
| deallocation.rs:115:13:115:18 | my_ptr | semmle.label | my_ptr |
121115
| deallocation.rs:123:6:123:7 | p1 | semmle.label | p1 |
122116
| deallocation.rs:123:23:123:40 | ...::dangling | semmle.label | ...::dangling |
123-
| deallocation.rs:123:23:123:40 | ...::dangling | semmle.label | ...::dangling |
124117
| deallocation.rs:123:23:123:42 | ...::dangling(...) | semmle.label | ...::dangling(...) |
125118
| deallocation.rs:124:6:124:7 | p2 | semmle.label | p2 |
126119
| deallocation.rs:124:21:124:42 | ...::dangling_mut | semmle.label | ...::dangling_mut |
@@ -160,11 +153,9 @@ nodes
160153
| deallocation.rs:219:15:219:34 | ...::null_mut(...) | semmle.label | ...::null_mut(...) |
161154
| deallocation.rs:226:13:226:21 | const_ptr | semmle.label | const_ptr |
162155
| deallocation.rs:270:3:270:25 | ...::drop_in_place | semmle.label | ...::drop_in_place |
163-
| deallocation.rs:270:3:270:25 | ...::drop_in_place | semmle.label | ...::drop_in_place |
164156
| deallocation.rs:270:27:270:28 | [post] p1 | semmle.label | [post] p1 |
165157
| deallocation.rs:274:15:274:16 | p1 | semmle.label | p1 |
166158
| deallocation.rs:336:3:336:25 | ...::drop_in_place | semmle.label | ...::drop_in_place |
167-
| deallocation.rs:336:3:336:25 | ...::drop_in_place | semmle.label | ...::drop_in_place |
168159
| deallocation.rs:336:27:336:29 | [post] ptr | semmle.label | [post] ptr |
169160
| deallocation.rs:342:18:342:20 | ptr | semmle.label | ptr |
170161
subpaths

shared/dataflow/codeql/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,16 +662,40 @@ module Make<
662662
unsupportedCallable(callable, _, _, _)
663663
}
664664

665+
private predicate isRelevantSource(
666+
SourceElement e, string output, string kind, Provenance provenance, string model
667+
) {
668+
e.isSource(output, kind, provenance, model) and
669+
(
670+
provenance.isManual()
671+
or
672+
provenance.isGenerated() and
673+
not exists(Provenance p | p.isManual() and e.isSource(_, kind, p, _))
674+
)
675+
}
676+
677+
private predicate isRelevantSink(
678+
SinkElement e, string input, string kind, Provenance provenance, string model
679+
) {
680+
e.isSink(input, kind, provenance, model) and
681+
(
682+
provenance.isManual()
683+
or
684+
provenance.isGenerated() and
685+
not exists(Provenance p | p.isManual() and e.isSink(_, kind, p, _))
686+
)
687+
}
688+
665689
private predicate summarySpec(string spec) {
666690
exists(SummarizedCallable c |
667691
c.propagatesFlow(spec, _, _, _)
668692
or
669693
c.propagatesFlow(_, spec, _, _)
670694
)
671695
or
672-
any(SourceElement s).isSource(spec, _, _, _)
696+
isRelevantSource(_, spec, _, _, _)
673697
or
674-
any(SinkElement s).isSink(spec, _, _, _)
698+
isRelevantSink(_, spec, _, _, _)
675699
}
676700

677701
import AccessPathSyntax::AccessPath<summarySpec/1>
@@ -1034,7 +1058,7 @@ module Make<
10341058
SourceElement source, SummaryComponentStack s, string kind, string model
10351059
) {
10361060
exists(string outSpec |
1037-
source.isSource(outSpec, kind, _, model) and
1061+
isRelevantSource(source, outSpec, kind, _, model) and
10381062
External::interpretSpec(outSpec, s)
10391063
)
10401064
}
@@ -1057,7 +1081,7 @@ module Make<
10571081
SinkElement sink, SummaryComponentStack s, string kind, string model
10581082
) {
10591083
exists(string inSpec |
1060-
sink.isSink(inSpec, kind, _, model) and
1084+
isRelevantSink(sink, inSpec, kind, _, model) and
10611085
External::interpretSpec(inSpec, s)
10621086
)
10631087
}

0 commit comments

Comments
 (0)