Skip to content

DataFlow: Support stateless isSink in StateConfigSigs - #13851

Merged
MathiasVP merged 8 commits into
github:mainfrom
MathiasVP:sink-without-states
Aug 4, 2023
Merged

DataFlow: Support stateless isSink in StateConfigSigs#13851
MathiasVP merged 8 commits into
github:mainfrom
MathiasVP:sink-without-states

Conversation

@MathiasVP

@MathiasVPMathiasVP commented Jul 31, 2023

Copy link
Copy Markdown
Contributor

Sometimes it's necessary to have a state-based configuration to define the correct isBarrier, but if data then does manage to reach a sink, any state should be accepted. Prior to this PR, the only way to prevent a cartesian product would be to do something like:

module PruningConfig implementsConfigSig{predicateisSource(Nodesource){exists(MyStatestate|isSourceImpl(source,state))}predicateisSink(Nodesink){ ... }}modulePruningFlow=Global<PruningConfig>;
FlowStateviableStateForSink(Nodesink){exists(PruningFlow::PathNodepSource, PruningFlow::PathNodepSink|
PruningFlow::flowPath(pSource,pSink)andpSink.getNode()=sinkandisSourceImpl(pSource.getNode(),result))}module RealConfig implementsStateConfigSig{classFlowState=MyStatepredicateisSource(Nodesource,FlowStatestate){isSourceImpl(source,state)}predicateisSink(Nodesink,FlowStatestate){
... andstate=viableStateForSink(sink)// <-- to prevent CP with all flow states.}predicateisBarrier(Nodebarrier,FlowStatestate){ ... }}

because there was no isSink/1 on StateConfigSig. With this PR we can now do:

module RealConfig implementsStateConfigSig{predicateisSource(Nodesource,FlowStatestate){ ... }predicateisSink(Nodesink){ ... }predicateisBarrier(Nodebarrier,FlowStatestate){ ... }}

with no PruningFlow mess.

cc @aschackmull I hope this isn't too controversial?

Comment threadcpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll Outdated
Comment threadcpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlow.qll Outdated
Comment threadcpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlow.qll Outdated
Comment threadcpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll Outdated
Comment threadcpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll Outdated

@aschackmullaschackmull left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to need some changes.

@MathiasVP
MathiasVPforce-pushed the sink-without-states branch from f3e3dac to 8399d4fCompareJuly 31, 2023 13:17
@MathiasVPMathiasVP removed their assignment Jul 31, 2023
@MathiasVP

Copy link
Copy Markdown
ContributorAuthor

@aschackmull I've rebased the PR now that #13863 has been merged (🎉).

@MathiasVP
MathiasVP marked this pull request as ready for review August 2, 2023 12:41
@MathiasVP
MathiasVP requested review from a team as code ownersAugust 2, 2023 12:41
@MathiasVP
MathiasVP requested review from a team as code ownersAugust 2, 2023 12:41
@MathiasVP

MathiasVP commented Aug 2, 2023

Copy link
Copy Markdown
ContributorAuthor

Hmmm @aschackmull I think adding the additional conjuncts to sinkNode breaks in the use of sinkNode in the partial flow case 😭. I've implemented one possible fix in 50f5c4d.

private predicate relevantState(FlowState state) {
sourceNode(_, state) or
sinkNode(_, state) or
sinkNodeWithState(_, state) or

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make another predicate to do a best-effort cartesian approximation for the reverse flow exploration case - this doesn't have to be extremely performant as it's just a debugging tool that'll often be restricted to specific sources/sinks anyway.
Add the following just below the relevantState predicate:

private predicate revSinkNode(NodeEx node, FlowState state) {
sinkNodeWithState(node, state)
or
Config::isSink(node.asNode()) and
relevantState(state) and
not fullBarrier(node) and
not stateBarrier(node, state)
}

and use it in the two places below.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Thanks! Fixed in 981f675.

Comment threadshared/dataflow/codeql/dataflow/DataFlowImpl.qll Outdated
Comment threadshared/dataflow/codeql/dataflow/DataFlowImpl.qll Outdated
Comment threadshared/dataflow/codeql/dataflow/DataFlow.qll Outdated
Comment threadshared/dataflow/change-notes/2023-08-02-dataflow-isSink.md Outdated
MathiasVPand others added 2 commits August 4, 2023 11:09
Co-authored-by: Anders Schack-Mulligen <aschackmull@users.noreply.github.com>
Comment threadshared/dataflow/codeql/dataflow/DataFlowImpl.qll Outdated
Co-authored-by: Anders Schack-Mulligen <aschackmull@users.noreply.github.com>

@aschackmullaschackmull left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now.

@MathiasVP

Copy link
Copy Markdown
ContributorAuthor

Hm, it looks like Java's DCA run isn't super happy about these changes. I'll investigate!

@aschackmull

Copy link
Copy Markdown
Contributor

Hm, it looks like Java's DCA run isn't super happy about these changes. I'll investigate!

It might very well be unrelated to this PR - I think we're seeing a lot of OOM kills in DCA at the moment for other reasons.

@MathiasVP

Copy link
Copy Markdown
ContributorAuthor

Hm, it looks like Java's DCA run isn't super happy about these changes. I'll investigate!

It might very well be unrelated to this PR - I think we're seeing a lot of OOM kills in DCA at the moment for other reasons.

Ah, thanks for the heads up. Stage timings also seem to blame a bunch of non-dataflow related queries so it's probably a fluke. In any case, I've started a separate run for Java, and I'll do a couple of local evaluations to make sure there's nothing wrong

@MathiasVP

Copy link
Copy Markdown
ContributorAuthor

FWIW, none of the projects that reported a slowdown on DCA seems to be slowing down locally.

@MathiasVP

Copy link
Copy Markdown
ContributorAuthor

Java has a bunch of OOMs, but this PR doesn't seem to contribute to any more of those OOMs. And since Java (nor any other language) isn't actually using this new feature yet this doesn't seem like it should block this PR. I've also verified that no bad joins are introduced.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@MathiasVP@aschackmull