Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Conversation

@sauyon
Copy link
Contributor

@sauyon sauyon commented Sep 21, 2021

Currently I'm bodging SourceOrSinkNode by using AstNode because we don't have a class that includes both a call and a callee. (Other than data-flow nodes, which can't be used because it causes non-monotonic recursion.)

Possibly the easiest solution would be to add a Top class, but alternatively we could extract decls for all functions, or split data-flow nodes into to layers.

To resolve before merging:

@sauyon sauyon requested a review from a team as a code owner September 21, 2021 05:53
@sauyon
Copy link
Contributor Author

sauyon commented Sep 21, 2021

(Needs testing, but I don't think this is testable without making one of those changes.)

@smowton
Copy link
Contributor

smowton commented Sep 22, 2021

Confirmed with some copying, pasting and diffing that 90f96e4 is only moving code, not making any substantial change.

@smowton
Copy link
Contributor

smowton commented Sep 22, 2021

There are also test failures to look at

@smowton
Copy link
Contributor

smowton commented Sep 22, 2021

I'd suggest we should add some actual models with this btw so we're not committing unused code -- perhaps port a small library that we already model by other means?

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

To talk about at standup: can we make SourceOrSinkElement a newtype?

class SourceOrSinkElement extends TSourceOrSinkElement {
Entity asEntity() { this = TEntityElement(result) }

AstNode asAstNode() { this = TAstElement(result) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the only current user casts this straight to DataFlowCall? Could we use that instead of AstNode?

@sauyon
Copy link
Contributor Author

sauyon commented Sep 28, 2021

This is currently still not in a working state, but I'm pretty stuck now; Steps::summaryLocalStep includes the step from the parameter to the summary return node, but partial flow seems to stop at the argument node. I believe that should just flow directly into the parameter node now, (the pair I'm looking for does show up in viableParamArg) but either that's not the case or it's being hidden somehow.

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

Looking into this now...

@smowton
Copy link
Contributor

smowton commented Sep 28, 2021

@sauyon have pushed two fix commits that get the basic test passing:

  • The step into the callable needed to use Node.getEnclosingCallable to associate the parameter node with its callee, but that wasn't implemented for summary parameter nodes
  • The step out of the callable needed ReturnNode to include those defined inside callables

I haven't looked into within-summary read and store steps or callables with parameter side-effects yet, but this is at least enough to get the most basic test passing.

@sauyon sauyon force-pushed the dataflow-update branch 3 times, most recently from d448b2f to 4251f31 Compare October 8, 2021 11:34
@owen-mc
Copy link
Contributor

owen-mc commented Oct 14, 2021

@smowton Do you know what the status of this is? Does it just need to be rebased, or are changes needed?

@smowton
Copy link
Contributor

smowton commented Oct 14, 2021

@sauyon could you give an update?

@sauyon
Copy link
Contributor Author

sauyon commented Oct 14, 2021

I believe I was waiting on a review for the parts that do work (csv modeling).

Content flow isn't currently working. I was intending to get to that but I am currently at KubeCon so that may be a bit delayed.

@owen-mc
Copy link
Contributor

owen-mc commented Nov 9, 2021

It seems that it supports "ReturnValue", "ReturnValue[n]" and "ReturnValue[n1..n2]". I assume "ReturnValue" is a synonym for "ReturnValue[0]". I guess that makes sense, since most of the time functions return a (result, err) pair and taint would normally flow through the first of those. I was just thinking of FunctionInput::functionResult(), where it only works when there is only one return value, so you're forced to use FunctionInput::functionResult(0) if that's what you mean.

@sauyon
Copy link
Contributor Author

sauyon commented Nov 24, 2021

It seems that it supports "ReturnValue", "ReturnValue[n]" and "ReturnValue[n1..n2]". I assume "ReturnValue" is a synonym for "ReturnValue[0]". I guess that makes sense, since most of the time functions return a (result, err) pair and taint would normally flow through the first of those. I was just thinking of FunctionInput::functionResult(), where it only works when there is only one return value, so you're forced to use FunctionInput::functionResult(0) if that's what you mean.

I forgot to address this; I think this is a good idea, but I think it was easier to make it work this way. I'll take a quick look after the variadic stuff and if it's easy I'll put it in, otherwise it's probably worth just doing later.

@owen-mc owen-mc force-pushed the dataflow-update branch 2 times, most recently from d11bd77 to d0c60dd Compare November 29, 2021 16:04
@owen-mc
Copy link
Contributor

owen-mc commented Nov 29, 2021

On further thought I think we should leave ReturnValue as a synonym for ReturnValue[0].

I've added some tests. I think this is ready to be re-reviewed now.

or
exists(c.(MethodCallNode).getTarget().getBody())
)
pos = i
Copy link
Contributor

Choose a reason for hiding this comment

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

#34 suggests that commit "Track receiver arguments to interface calls" may have performance or accuracy consequences. To consider, can we get what we need without reverting the desired effects of that PR?

var b test.B

b.Sink1(arg)
b.SinkMethod().(io.Writer).Write(arg.([]byte))
Copy link
Contributor

Choose a reason for hiding this comment

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

No sink found on this line?

Copy link
Contributor

Choose a reason for hiding this comment

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

@sauyon and I had a quick look and this does seem to be a bug. He'll try and dig into it some more.

@smowton
Copy link
Contributor

smowton commented Dec 2, 2021

Note this PR currently contains a test, ExternalFlowVarArgs, which only passes in CI because CI tests the merge-product with main. It doesn't work on this branch.

I removed asFunctionNode() because it would need an import, but it
doesn't seem to be used anywhere.
owen-mc and others added 4 commits December 8, 2021 15:28
This branch originally included a commit to enable flow through receivers
when there is no function body. This was dropped, to be pursued later.
viableParamArg should be evaluated first.
…ith Configurations

This is particularly important for ConversionWithoutBoundsCheckConfig which has 20 configs. By paring DataFlow::Node down to only those that have a local-flow successor, or only those with an isAdditionalFlowStep for some related configuration, the result size can be significantly reduced prior to taking the product against Configuration and finally paring down using config.fullBarrier etc.

Saves about 1m20s per analysis on cockroachdb.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants