Skip to content

Conversation

@aibaars
Copy link
Contributor

@aibaars aibaars commented Jul 7, 2020

Fixes: #3883

@aibaars aibaars added Java WIP This is a work-in-progress, do not merge yet! labels Jul 7, 2020
@aibaars
Copy link
Contributor Author

aibaars commented Jul 7, 2020

Thanks for the detailed list @Marcono1234 . This PR should address #3883 . It should include all of the suggestions you made except

  • reduce methods from ConcurrentHashMap. While it is possible that taint is preserved by the reducer, I think this is quite unlikely
  • methods that taint their arguments (copyInto, drainTo, toArray, etc). These should be put in taintPreservingQualifierToArgument .

If you spot any methods in this PR that I missed, other than the ones mentioned above, please let me know.

@aibaars aibaars changed the title Java: ContainerFlow: organize taintPreservingQualifierToMethod Java: Clean up ContainerFlow, consider more methods Jul 7, 2020
Copy link
Contributor

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

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

Thanks! I missed some Deque methods in #3883 and incorrectly listed Set.spliterator(), but luckily you spotted this. I have adjusted 3883 accordingly.

Often you only restricted the method using (CollectionMethod) or (MapMethod). I assume that this the reason why you then left out some methods, which - while not overriding any other method - are already being covered by one of the more generic (CollectionMethod) or (MapMethod) checks.
However, in my opinion it would be good to at least add them commented out (and mention where they are matched) so it is clear that the method was not left out by accident. Otherwise if later one of the more generic checks is refined, it might not match that (currently not listed) method anymore and that false negative would not be that obvious. I have left review comments at (hopefully) all places where this applies.

Additionally, what do you think about checking for Object.clone() as well? Unless I overlooked it, it appears there is currently no taint tracking for it.

aibaars added 3 commits July 8, 2020 22:08
While most flow for a qualifierToArgumentStep goes through a variable use
this is not always the case. Therefore it is best to remove the restriction
to RValue to allow taint steps to use postupdate nodes.

See also: ba86dea
@aibaars aibaars marked this pull request as ready for review July 9, 2020 10:43
@aibaars aibaars requested a review from a team as a code owner July 9, 2020 10:43
@aibaars
Copy link
Contributor Author

aibaars commented Jul 9, 2020

@Marcono1234 thanks for the detailed review. I addressed all your comments and also added a test case that should cover all the new flow that was implemented.

@aibaars aibaars removed the WIP This is a work-in-progress, do not merge yet! label Jul 9, 2020
Some method variants are captured by a super class. Added some comments
to indicate where this happens to make review of missing methods easier
in the future.
// java.util.Map
m
.(MapMethod)
.hasName(["computeIfAbsent", "entrySet", "get", "getOrDefault", "merge", "put", "putIfAbsent",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we should include merge, as this is dependent on the merge function preserving taint.

Stack.push(E) returns its argument, it does not propagate taint from
the stack to the return value.
@aschackmull
Copy link
Contributor

This is btw. definitely a PR for which we'll want a Java-Differences job before merging, as there might be a performance impact.

@aibaars aibaars requested a review from a team July 9, 2020 14:55
@aibaars
Copy link
Contributor Author

aibaars commented Jul 9, 2020

Copy link
Contributor

@aschackmull aschackmull left a comment

Choose a reason for hiding this comment

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

If we remove merge from taintPreservingQualifierToMethod then I think this is ready to merge.

@aschackmull aschackmull merged commit a1d272e into github:master Jul 10, 2020
Copy link
Contributor

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

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

Thanks, looks really good!
I noticed a few more minor things which could possibly be improved.

m.(CollectionMethod).hasName(["peek", "pop"])
or
// java.util.Queue
m.(CollectionMethod).hasName(["element", /*"peek", "remove"*/ "poll"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you remove the comment for peek by accident?
It would probably good to add a comment as well:

// covered by Stack: peek()

// covered by Deque: offerFirst(E, long, TimeUnit), offerLast(E, long, TimeUnit)
method.(CollectionMethod).hasName(["putFirst", "putLast"]) and arg = 0
or
//java.util.Dictionary
Copy link
Contributor

Choose a reason for hiding this comment

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

Would probably be good to add a space between // and java... to be consistent:

// java.util.Dictionary

*/
private predicate taintPreservingArgumentToMethod(Method method, int arg) {
// java.util.Stack
method.(CollectionMethod).hasName("push") and arg = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

@aschackmull, isn't that even data flow then and not only tainting?

Copy link
Contributor

Choose a reason for hiding this comment

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

I concur^^

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java: Clean up ContainerFlow, consider more methods

4 participants