Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataFlowStack Common Library #14673

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
885d249
merge instead of rebase
Apr 24, 2023
b0e4305
josh zipslip improvements
Apr 24, 2023
fd05c13
allow unrelated histories on merge
Apr 24, 2023
4fb30f3
test predicate
Apr 24, 2023
54716a8
remove allow unrelated histories on git merge
Apr 24, 2023
8ce078e
unshallow fetch
Apr 24, 2023
9c72cba
removing unshallow
Apr 24, 2023
bc51aee
removing debugging git log line
Apr 24, 2023
b3cd535
removing dead code test
Apr 24, 2023
6fbc070
sync with upstream repository
Apr 27, 2023
56b1047
Manual merge + updated test case of C# ZipSlip
ropwareJB May 23, 2023
4e5a095
Merge pull request #9 from microsoft/jb1/zipslip-fix
dilanbhalla May 24, 2023
4b0d2b9
Update sync-main.yml
dilanbhalla May 31, 2023
cb47517
Update sync-main.yml
dilanbhalla May 31, 2023
7976cf8
Merge tag 'codeql-cli/latest'
May 31, 2023
c8f19d6
Microsoft mandatory file
microsoft-github-policy-service[bot] Jun 2, 2023
7b1c964
Auto merge mandatory file pr
microsoft-github-policy-service[bot] Jun 12, 2023
eb7a666
Merge tag 'codeql-cli/latest'
Jun 19, 2023
72471f6
Ben update to iterator.qll
dilanbhalla Jun 26, 2023
acda5fd
Merge tag 'codeql-cli/latest'
Jul 6, 2023
d3e36cb
Merge tag 'codeql-cli/latest'
Jul 13, 2023
08147f0
Merge tag 'codeql-cli/latest'
Jul 28, 2023
7acd76d
temporarily disable sync main until 2.14.3
Aug 22, 2023
8a9fd35
Adding internal C++ dataflow library
Aug 23, 2023
da08e0b
Reverting temp dataflow from 2.14.3 to 2.14.1
Aug 24, 2023
f2994e7
Update DataFlow.qll
dilanbhalla Aug 25, 2023
0a9fc79
Update sync-main.yml
dilanbhalla Aug 25, 2023
019cff2
Merge tag 'codeql-cli/latest'
Aug 25, 2023
6b23eee
Merge branch 'main' of https://github.com/github/codeql
Aug 28, 2023
5ee6742
microsoft dataflow fix for 2.14.3
Aug 28, 2023
d9b45c8
Merge branch 'main' of https://github.com/microsoft/codeql
Aug 28, 2023
eb0e2c4
Merge tag 'codeql-cli/latest'
Aug 28, 2023
7f61bfe
fixing tainttracking module 2.14.3
Aug 28, 2023
76cec33
Microsoft 2.14.3 resolving taintflow warning
Aug 28, 2023
3d7e679
modifying gh libs instead of creating msft copies
Aug 29, 2023
cd16271
Merge branch 'main' of https://github.com/github/codeql
Aug 30, 2023
bc2bb19
Merge tag 'codeql-cli/latest'
Sep 12, 2023
fc00da8
Update README.md
dilanbhalla Sep 13, 2023
4e656de
Update CONTRIBUTING.md
dilanbhalla Sep 14, 2023
d185c94
Update sync-main.yml
dilanbhalla Sep 14, 2023
3a75325
Update README.md
dilanbhalla Sep 14, 2023
c30661e
Update CONTRIBUTING.md
dilanbhalla Sep 14, 2023
c2fee67
Update sync-main.yml
dilanbhalla Sep 14, 2023
73a4cc8
Update sync-main.yml
dilanbhalla Sep 14, 2023
4d77490
Merge tag 'codeql-cli/latest'
Sep 14, 2023
e5f74dd
Update sync-main.yml
dilanbhalla Sep 14, 2023
2bc3e28
Merge tag 'codeql-cli/latest'
Sep 26, 2023
ea63fc0
Merge pull request #14289 from microsoft/jb1/16-cryptography-models-l…
ropwareJB Oct 4, 2023
8555600
Merge tag 'codeql-cli/latest'
Oct 11, 2023
ab827a5
Cherry picking commit bbf9bcde2a92768cb80adb97b815d535f32ce79c
MathiasVP Oct 17, 2023
d4e5b27
Cherry picking commit bbf9bcde2a92768cb80adb97b815d535f32ce79c (#21)
bdrodes Oct 17, 2023
f19919b
Revert "Cherry picking commit bbf9bcde2a92768cb80adb97b815d535f32ce79…
bdrodes Oct 18, 2023
1026d89
Merge branch 'main' into brodes/additional_target_cherry_pick
bdrodes Oct 18, 2023
075e992
Revert "Cherry picking commit bbf9bcde2a92768cb80adb97b815d535f32ce79…
bdrodes Oct 18, 2023
6066e82
Merge pull request #22 from microsoft/brodes/additional_target_cherry…
dilanbhalla Oct 18, 2023
90b7fd5
Update ZipSlipQuery.qll
dilanbhalla Oct 19, 2023
1cdf4aa
manual merge for 2.15.1, resolve zipslip conflict
Oct 19, 2023
d9364c0
Merge pull request #14482 from MathiasVP/additional-call-targets-for-…
bdrodes Oct 23, 2023
c161ed4
dataflowstack init
ropwareJB Nov 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/sync-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Sync Main
on:
schedule:
- cron: '55 * * * *'
workflow_dispatch:
jobs:
sync-main:
name: Sync-main
runs-on: ubuntu-latest
if: github.repository == 'microsoft/codeql'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.WORKFLOW_TOKEN }}
- name: Git config
shell: bash
run: |
git config user.name Dilan Bhalla
git config user.email dilanbhalla@microsoft.com
- name: Fetch
shell: bash
run: |
set -x
git fetch
git remote add upstream https://github.com/github/codeql.git
git fetch upstream --tags --force
- name: Sync Main
shell: bash
run: |
git merge codeql-cli/latest
git push origin main
git push origin --tags --force

41 changes: 41 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.8 BLOCK -->

## Security

Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).

If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.

## Reporting Security Issues

**Please do not report security vulnerabilities through public GitHub issues.**

Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).

If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.

## Preferred Languages

We prefer all communications to be in English.

## Policy

Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).

<!-- END MICROSOFT SECURITY.MD BLOCK -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: feature
---
* Added a new class `AdditionalCallTarget` for specifying additional call targets.
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/dataflow/DataFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import cpp
* Provides classes for performing local (intra-procedural) and
* global (inter-procedural) data flow analyses.
*/
deprecated module DataFlow {
module DataFlow {
private import semmle.code.cpp.dataflow.internal.DataFlowImplSpecific
private import codeql.dataflow.DataFlow
import DataFlowMake<CppOldDataFlow>
Expand Down
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/dataflow/DataFlow2.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ import cpp
* Provides classes for performing local (intra-procedural) and
* global (inter-procedural) data flow analyses.
*/
deprecated module DataFlow2 {
module DataFlow2 {
import semmle.code.cpp.dataflow.internal.DataFlowImpl2
}
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/dataflow/DataFlow3.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ import cpp
* Provides classes for performing local (intra-procedural) and
* global (inter-procedural) data flow analyses.
*/
deprecated module DataFlow3 {
module DataFlow3 {
import semmle.code.cpp.dataflow.internal.DataFlowImpl3
}
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/dataflow/DataFlow4.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ import cpp
* Provides classes for performing local (intra-procedural) and
* global (inter-procedural) data flow analyses.
*/
deprecated module DataFlow4 {
module DataFlow4 {
import semmle.code.cpp.dataflow.internal.DataFlowImpl4
}
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/dataflow/TaintTracking.qll
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import semmle.code.cpp.dataflow.DataFlow2
* Provides classes for performing local (intra-procedural) and
* global (inter-procedural) taint-tracking analyses.
*/
deprecated module TaintTracking {
module TaintTracking {
import semmle.code.cpp.dataflow.internal.tainttracking1.TaintTrackingParameter::Public
private import semmle.code.cpp.dataflow.internal.DataFlowImplSpecific
private import semmle.code.cpp.dataflow.internal.TaintTrackingImplSpecific
Expand Down
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/dataflow/TaintTracking2.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* Provides classes for performing local (intra-procedural) and
* global (inter-procedural) taint-tracking analyses.
*/
deprecated module TaintTracking2 {
module TaintTracking2 {
import semmle.code.cpp.dataflow.internal.tainttracking2.TaintTrackingImpl
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ private import DataFlowImplCommon as DataFlowImplCommon

/**
* Gets a function that might be called by `call`.
*
* This predicate does not take additional call targets
* from `AdditionalCallTarget` into account.
*/
cached
DataFlowCallable viableCallable(DataFlowCall call) {
DataFlowCallable defaultViableCallable(DataFlowCall call) {
DataFlowImplCommon::forceCachingInSameStage() and
result = call.getStaticCallTarget()
or
Expand All @@ -29,6 +32,17 @@ DataFlowCallable viableCallable(DataFlowCall call) {
result = call.(VirtualDispatch::DataSensitiveCall).resolve()
}

/**
* Gets a function that might be called by `call`.
*/
cached
DataFlowCallable viableCallable(DataFlowCall call) {
result = defaultViableCallable(call)
or
// Additional call targets
result = any(AdditionalCallTarget additional).viableTarget(call.getUnconvertedResultExpression())
}

/**
* Provides virtual dispatch support compatible with the original
* implementation of `semmle.code.cpp.security.TaintTracking`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private import DataFlowPrivate
private import ModelUtil
private import SsaInternals as Ssa
private import DataFlowImplCommon as DataFlowImplCommon
private import codeql.util.Unit

/**
* The IR dataflow graph consists of the following nodes:
Expand Down Expand Up @@ -2237,3 +2238,43 @@ module InstructionBarrierGuard<instructionGuardChecksSig/3 instructionGuardCheck
)
}
}

/**
* A unit class for adding additional call steps.
*
* Extend this class to add additional call steps to the data flow graph.
*
* For example, if the following subclass is added:
* ```ql
* class MyAdditionalCallTarget extends DataFlow::AdditionalCallTarget {
* override Function viableTarget(Call call) {
* call.getTarget().hasName("f") and
* result.hasName("g")
* }
* }
* ```
* then flow from `source()` to `x` in `sink(x)` is reported in the following example:
* ```cpp
* void sink(int);
* int source();
* void f(int);
*
* void g(int x) {
* sink(x);
* }
*
* void test() {
* int x = source();
* f(x);
* }
* ```
*
* Note: To prevent reevaluation of cached dataflow-related predicates any
* subclass of `AdditionalCallTarget` must be imported in all dataflow queries.
*/
class AdditionalCallTarget extends Unit {
/**
* Gets a viable target for `call`.
*/
abstract DataFlowCallable viableTarget(Call call);
}
21 changes: 13 additions & 8 deletions cpp/ql/lib/semmle/code/cpp/models/implementations/Iterator.qll
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ private class IteratorTraits extends Class {
}

Type getIteratorType() { result = this.getTemplateArgument(0) }

Type getValueType() {
exists(TypedefType t |
this.getAMember() = t and
t.getName() = "value_type" and
result = t.getUnderlyingType()
)
}
}

/**
Expand All @@ -32,16 +40,13 @@ private class IteratorTraits extends Class {
*/
private class IteratorByTraits extends Iterator {
IteratorTraits trait;
IteratorByTraits() {
trait.getIteratorType() = this and
not trait.getValueType() = this
}

IteratorByTraits() { trait.getIteratorType() = this }
override Type getValueType() { result = trait.getValueType() }

override Type getValueType() {
exists(TypedefType t |
trait.getAMember() = t and
t.getName() = "value_type" and
result = t.getUnderlyingType()
)
}
}

/**
Expand Down
13 changes: 13 additions & 0 deletions cpp/ql/test/library-tests/dataflow/fields/IRConfiguration.qll
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
private import semmle.code.cpp.ir.dataflow.DataFlow
private import DataFlow

private class TestAdditionalCallTarget extends AdditionalCallTarget {
override Function viableTarget(Call call) {
// To test that call targets specified by `AdditionalCallTarget` are
// resolved correctly this subclass resolves all calls to
// `call_template_argument<f>(x)` as if the user had written `f(x)`.
exists(FunctionTemplateInstantiation inst |
inst.getTemplate().hasName("call_template_argument") and
call.getTarget() = inst and
result = inst.getTemplateArgument(0).(FunctionAccess).getTarget()
)
}
}

module IRConfig implements ConfigSig {
predicate isSource(Node src) {
src.asExpr() instanceof NewExpr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,9 @@ edges
| simple.cpp:92:7:92:7 | a indirection [post update] [i] | simple.cpp:94:10:94:11 | a2 indirection [i] |
| simple.cpp:92:11:92:20 | call to user_input | simple.cpp:92:5:92:22 | ... = ... |
| simple.cpp:94:10:94:11 | a2 indirection [i] | simple.cpp:94:13:94:13 | i |
| simple.cpp:103:24:103:24 | x | simple.cpp:104:14:104:14 | x |
| simple.cpp:108:17:108:26 | call to user_input | simple.cpp:109:43:109:43 | x |
| simple.cpp:109:43:109:43 | x | simple.cpp:103:24:103:24 | x |
| struct_init.c:14:24:14:25 | ab indirection [a] | struct_init.c:15:8:15:9 | ab indirection [a] |
| struct_init.c:15:8:15:9 | ab indirection [a] | struct_init.c:15:12:15:12 | a |
| struct_init.c:20:13:20:14 | definition of ab indirection [a] | struct_init.c:22:8:22:9 | ab indirection [a] |
Expand Down Expand Up @@ -1576,6 +1579,10 @@ nodes
| simple.cpp:92:11:92:20 | call to user_input | semmle.label | call to user_input |
| simple.cpp:94:10:94:11 | a2 indirection [i] | semmle.label | a2 indirection [i] |
| simple.cpp:94:13:94:13 | i | semmle.label | i |
| simple.cpp:103:24:103:24 | x | semmle.label | x |
| simple.cpp:104:14:104:14 | x | semmle.label | x |
| simple.cpp:108:17:108:26 | call to user_input | semmle.label | call to user_input |
| simple.cpp:109:43:109:43 | x | semmle.label | x |
| struct_init.c:14:24:14:25 | ab indirection [a] | semmle.label | ab indirection [a] |
| struct_init.c:15:8:15:9 | ab indirection [a] | semmle.label | ab indirection [a] |
| struct_init.c:15:12:15:12 | a | semmle.label | a |
Expand Down Expand Up @@ -1782,6 +1789,7 @@ subpaths
| simple.cpp:67:13:67:13 | i | simple.cpp:65:11:65:20 | call to user_input | simple.cpp:67:13:67:13 | i | i flows from $@ | simple.cpp:65:11:65:20 | call to user_input | call to user_input |
| simple.cpp:84:14:84:20 | call to getf2f1 | simple.cpp:83:17:83:26 | call to user_input | simple.cpp:84:14:84:20 | call to getf2f1 | call to getf2f1 flows from $@ | simple.cpp:83:17:83:26 | call to user_input | call to user_input |
| simple.cpp:94:13:94:13 | i | simple.cpp:92:11:92:20 | call to user_input | simple.cpp:94:13:94:13 | i | i flows from $@ | simple.cpp:92:11:92:20 | call to user_input | call to user_input |
| simple.cpp:104:14:104:14 | x | simple.cpp:108:17:108:26 | call to user_input | simple.cpp:104:14:104:14 | x | x flows from $@ | simple.cpp:108:17:108:26 | call to user_input | call to user_input |
| struct_init.c:15:12:15:12 | a | struct_init.c:20:20:20:29 | call to user_input | struct_init.c:15:12:15:12 | a | a flows from $@ | struct_init.c:20:20:20:29 | call to user_input | call to user_input |
| struct_init.c:15:12:15:12 | a | struct_init.c:27:7:27:16 | call to user_input | struct_init.c:15:12:15:12 | a | a flows from $@ | struct_init.c:27:7:27:16 | call to user_input | call to user_input |
| struct_init.c:15:12:15:12 | a | struct_init.c:40:20:40:29 | call to user_input | struct_init.c:15:12:15:12 | a | a flows from $@ | struct_init.c:40:20:40:29 | call to user_input | call to user_input |
Expand Down
17 changes: 17 additions & 0 deletions cpp/ql/test/library-tests/dataflow/fields/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,21 @@ void single_field_test_typedef(A_typedef a)
sink(a2.i); //$ ast,ir
}

namespace TestAdditionalCallTargets {

using TakesIntReturnsVoid = void(*)(int);
template<TakesIntReturnsVoid F>
void call_template_argument(int);

void call_sink(int x) {
sink(x); // $ ir
}

void test_additional_call_targets() {
int x = user_input();
call_template_argument<call_sink>(x);
}

}

} // namespace Simple
1 change: 1 addition & 0 deletions csharp/ql/lib/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ upgrades: upgrades
dependencies:
codeql/controlflow: ${workspace}
codeql/dataflow: ${workspace}
codeql/dataflowstack: ${workspace}
codeql/mad: ${workspace}
codeql/ssa: ${workspace}
codeql/tutorial: ${workspace}
Expand Down
10 changes: 10 additions & 0 deletions csharp/ql/lib/semmle/code/csharp/dataflow/DataFlowStack.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

private import codeql.dataflow.DataFlow
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific

private import codeql.dataflowstack.DataFlowStack as DFS
private import DFS::DataFlowStackMake<CsharpDataFlow> as DataFlowStackFactory

module DataFlowStackMake<DataFlowStackFactory::DataFlow::GlobalFlowSig Flow>{
import DataFlowStackFactory::FlowStack<Flow>
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ abstract class DataFlowCall extends TDataFlowCall {
/** Gets the argument at position `pos` of this call. */
final ArgumentNode getArgument(ArgumentPosition pos) { result.argumentOf(this, pos) }

/** Gets an argument of this call. */
final ArgumentNode getAnArgument() { result.argumentOf(this, _) }

/** Gets a textual representation of this call. */
abstract string toString();

Expand Down
Loading