Commit Graph

35 Commits

Author SHA1 Message Date
Tamas Vajk
6d409a0050 Fix failing tests 2021-03-09 09:14:24 +01:00
Tom Hvitved
6ffeaf8c2a C#: Adjust flow into phi nodes 2021-01-25 15:44:37 +01:00
Tom Hvitved
38b0f743cb C#: Add test that illustrates problem with flow through phi nodes 2021-01-25 14:20:27 +01:00
Tom Hvitved
8d77f4bac9 C#: Remove ImplicitUntrackedDefinition 2021-01-07 15:16:39 +01:00
Tom Hvitved
94deed39a2 C#: Represent all expressions in post-order in the CFG 2020-11-12 20:04:48 +01:00
Tom Hvitved
795c5784b0 C#: Precise data flow for collections 2020-06-26 13:40:05 +02:00
Tom Hvitved
b8ae4b7f64 C#: Move async data-flow tests from local to global 2020-06-25 10:04:18 +02:00
Tom Hvitved
1959480b78 C#: Field-flow summaries for library code 2020-04-16 15:20:47 +02:00
Tom Hvitved
a9b88b6eaa C#: Update data flow tests 2020-04-14 09:31:10 +02:00
Tom Hvitved
9dde1ce76a C#: No taint-tracking steps for ternary conditionals
Ternary conditionals `b ? x : y` mistakenly had taint-tracking steps from both
`b`, `x`, and `y` to the conditional expression itself. Flow from `b` was not
intented, and flow from `x` and `y` is already part of ordinary data flow.
2019-12-17 13:53:39 +01:00
Calum Grant
4b0a149704 C#: Update qltest output. 2019-12-06 12:41:20 +00:00
Tom Hvitved
af453d081e C#: Only track taint through conversion operators defined in libraries 2019-11-28 15:21:04 +01:00
Tom Hvitved
71e958eabc C#: Add taint-tracking steps through conversion operator calls 2019-11-26 13:53:50 +01:00
Tom Hvitved
acb069f69b C#: Add data flow tests for conversion operators 2019-11-26 13:53:17 +01:00
Tom Hvitved
f9bff172d4 C#: Add missing assignment data flow steps 2019-11-15 11:36:05 +01:00
Tom Hvitved
f8791c884f C#: Add more data flow tests for assignments 2019-11-15 11:30:40 +01:00
Calum Grant
df1e215d98 C#: Add ?? as a local dataflow step. 2019-10-23 21:47:03 +01:00
Calum Grant
48c0d9ecca C#: Add qltests for ?? dataflow. 2019-10-23 15:17:26 +01:00
semmle-qlci
394563de43 Merge pull request #1807 from hvitved/csharp/dataflow/barrier-guard
Approved by calumgrant
2019-08-30 12:40:25 +01:00
Tom Hvitved
6e7ef66642 C#: Revert to using GuardedDataFlowNode in TaintedPath.qll 2019-08-30 09:37:23 +02:00
Tom Hvitved
751985dcf2 C#: Address review comments 2019-08-30 09:37:23 +02:00
Tom Hvitved
ae5fb7f330 C#: Introduce BarrierGuards 2019-08-30 09:37:16 +02:00
Tom Hvitved
c5d9d74c0a C#: Nested field flow 2019-08-23 09:25:05 +02:00
Tom Hvitved
d1755500e4 C#: Data flow through fields
Initial implementation of data flow through fields, using the algorithm of the
shared data flow implementation. Fields (and field-like properties) are covered,
and stores can be either
 - ordinary assignments, `Foo = x`,
 - object initializers, `new C() { Foo = x }`, or
 - field initializers, `int Foo = x`.

For field initializers, we need to synthesize calls (`SynthesizedCall`),
callables (`SynthesizedCallable`), parameters (`InstanceParameterNode`), and
arguments (`SynthesizedThisArgumentNode`), as the C# extractor does not (yet)
extract such entities. For example, in

```
class C
{
    int Field1 = 1;
    int Field2 = 2;

    C() { }
}
```

there is a synthesized call from the constructor `C`, with a synthesized `this`
argument, and the targets of that call are two synthesized callables with bodies
`this.Field1 = 1` and `this.Field2 = 2`, respectively.

A consequence of this is that `DataFlowCallable` is no longer an alias for
`DotNet::Callable`, but instead an IPA type.
2019-08-16 15:49:37 +02:00
Tom Hvitved
946be967f8 C#: Break up a big cached stage into multiple stages
- Add `Caching.qll` for controlling caching across multiple files.
- Move `isUncertainRefCall()` out of cached module in `Assignable.qll` to avoid
  collapsing with CFG stage.
- Remove dependency on `AlwaysNullExpr` in `NullValue::getAnExpr()` to avoid
  collapsing with CFG stage.
- Avoid caching pre-SSA library as it should only be used during the CFG construction
  stage.
2019-06-12 16:05:45 +02:00
Tom Hvitved
e1d4166e3c C#: Data flow through this parameter 2019-05-20 13:42:32 +02:00
Tom Hvitved
c6a471e4b6 C#: Adopt shared data flow implementation
- General refactoring to fit with the shared data flow implementation.
- Move CFG splitting logic into `ControlFlowReachability.qll`.
- Replace `isAdditionalFlowStepIntoCall()` with `TaintedParameterNode`.
- Redefine `ReturnNode` to be the actual values that are returned, which should
  yield better path information.
- No longer consider overrides in CIL calls.
2019-05-06 14:54:11 +02:00
Tom Hvitved
26debb846c C#: Change ImplicitCapturedArgumentNode::toString() 2019-05-06 14:54:11 +02:00
Tom Hvitved
b48576d7b9 C#: Address review comments 2019-03-10 15:45:31 +01:00
Tom Hvitved
e6f7632d4c C#: Introduce data flow return nodes
Before this change,

```
flowOutOfCallableStep(CallNode call, ReturnNode ret, OutNode out, CallContext cc)
```

would compute all combinations of call sites `call` and returned expressions `ret`
up front.

Now, we instead introduce explicit return nodes, so each callable has exactly
one return node (as well as one for each `out`/`ref` parameter). There is then
local flow from a returned expression to the relevant return node, and
`flowOutOfCallableStep()` computes combinations of call sites and return nodes.

Not only does this result in better performance, it also makes `flowOutOfCallableStep()`
symmetric to `flowIntoCallableStep()`, where each argument is mapped to a parameter,
and not to all reads of that parameter.
2019-03-07 12:16:06 +01:00
Tom Hvitved
5ce9b25ec9 C#: Improve CFG for assignments
Write accesses in assignments, such as the access to `x` in `x = 0` are not
evaluated, so they should not have entries in the control flow graph. However,
qualifiers (and indexer arguments) should still be evaluated, for example in

```
x.Foo.Bar = 0;
```

the CFG should be `x --> x.Foo --> 0 --> x.Foo.Bar = 0` (as opposed to
`x --> x.Foo --> x.Foo.Bar --> 0 --> x.Foo.Bar = 0`, prior to this change).

A special case is assignments via acessors (properties, indexers, and event
adders), where we do want to include the access in the control flow graph,
as it represents the accessor call:

```
x.Prop = 0;
```

But instead of `x --> x.set_Prop --> 0 --> x.Prop = 0` the CFG should be
`x --> 0 --> x.set_Prop --> x.Prop = 0`, as the setter is called *after* the
assigned value has been evaluated.

An even more special case is tuple assignments via accessors:

```
(x.Prop1, y.Prop2) = (0, 1);
```

Here the CFG should be
`x --> y --> 0 --> 1 --> x.set_Prop1 --> y.set_Prop2 --> (x.Prop1, y.Prop2) = (0, 1)`.
2019-02-16 19:19:24 +01:00
Tom Hvitved
b2f99dbbc7 C#: Teach data flow library about CFG splitting
Data flow nodes for expressions do not take CFG splitting into account. Example:

```
if (b)
    x = tainted;
x = x.ToLower();
if (!b)
    Use(x);
```

Flow is incorrectly reported from `tainted` to `x` in `Use(x)`, because the step
from `tainted` to `x.ToLower()` throws away the information that `b = true`.

The solution is to remember the splitting in data flow expression nodes, that is,
to represent the exact control flow node instead of just the expression. With that
we get flow from `tainted` to `[b = true] x.ToLower()`, but not from `tainted` to
`[b = false] x.ToLower()`.

The data flow API remains unchanged, but in order for analyses to fully benefit from
CFG splitting, sanitizers in particular should be CFG-based instead of expression-based:

```
if (b)
   x = tainted;
   if (IsInvalid(x))
       return;
Use(x);
```

If the call to `IsInvalid()` is a sanitizer, then defining an expression node to be
a sanitizer using `GuardedExpr` will be too conservative (`x` in `Use(x)` is in fact
not guarded). However, `[b = true] x` in `[b = true] Use(x)` is guarded, and to help
defining guard-based sanitizers, the class `GuardedDataFlowNode` has been introduced.
2019-01-16 10:39:27 +01:00
Tom Hvitved
f768abb0e6 C#: Add data flow test with CFG splitting 2019-01-16 10:29:26 +01:00
Tom Hvitved
231465143d C#: Autoformat QL tests 2018-12-20 10:19:59 +01:00
Pavel Avgustinov
b55526aa58 QL code and tests for C#/C++/JavaScript. 2018-08-02 17:53:23 +01:00