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

C++: Fix barriers in invalid pointer deref #13725

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented Jul 11, 2023

Commit-by-commit review recommended.

  • The first two commits fixes the FPs. The general theme here is that we shouldn't be clearing every node in a basic block based on a guard condition. This is quite interesting: we normally consider all dataflow nodes that are guarded by some specific condition as being safe. This is because we're reasoning about an unsafe value flowing to a specific sink:
void test() {
  char* s = my_dangerous_source();
  if(safe(s)) { sink(s); }
}

and here it makes sense that every dataflow node guarded by the safe(s) condition is safe because there's presumably no way to turn s unsafe again. However, when we're reasoning about buffer overflows, simply having a check like if(i < size) doesn't mean that there's not a a[i + 100000000] = 0 somewhere inside the block that's guarded by if(i < size). And i + 100000000 very likely isn't safe even though i < size.

  • The third gets rid of an arbitrary bound on the flow state by precomputing the set of flow states. This could be achieved by piggy-backing on the existing dataflow traversal done using InvalidPointerToDerefBarrier::BarrierConfig, but this is needlessly complex and doesn't seem to give any additional performance boosts.
  • Finally, the last commit fixes a bad join.

This will conflict with #13699, but it shouldn't be difficult to handle the resulting merge-conflict.

@github-actions github-actions bot added the C++ label Jul 11, 2023
@MathiasVP MathiasVP marked this pull request as ready for review July 12, 2023 08:20
@MathiasVP MathiasVP requested a review from a team as a code owner July 12, 2023 08:20
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

QL changes seem reasonable (though I won't pretend to have a deep understanding of all of them). Test results speak for themselves.

On DCA we lose 6 results, which appear to be false positives as well (as best I can tell).

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.

None yet

2 participants