-
Notifications
You must be signed in to change notification settings - Fork 17
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
[WIP][TA] Analyze out-of-BT func with tainted parameters #47
base: main
Are you sure you want to change the base?
Conversation
virtual unsigned getRegSize(std::string RegName) const = 0; | ||
|
||
// Get RegAliasTuple from the RegMap with selected Id. | ||
RegAliasTuple &getRegMap(unsigned Id) const { | ||
return const_cast<RegAliasTuple &>(RegMap.at(Id)); | ||
} | ||
|
||
// Get RegAliasTuple from the RegMap with selected Id. | ||
std::unordered_map<unsigned, RegAliasTuple> getWholeRegMap() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better return a reference to map instead of copying the entire map; no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, I missed this, thanks!
@@ -134,13 +134,19 @@ void TaintDataFlowGraph::findBlameFunction(Node *v) { | |||
if (a->MI->getParent() == adjNode->MI->getParent() && | |||
!a->CallMI && !adjNode->CallMI) { | |||
if (MDT->dominates(adjNode->MI, a->MI)) { | |||
// Do not erase potential blame nodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why didn't you terminate in the begining of the loop (line 134) after?
the terminating condition is repeated all over this loop which makes it hard to understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I will move this condition to the beginning of the iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the extensive work,
I didn't see much functional issues in the code, but there are couple efficiency issues that I commented on and also the style is a bit hard to understand. for example, runOnBlameMF has grown too big and the added complexity of two flags runFwAnalysis and runBwAnalysis hasn't made it easier to understand.
Nevertheless, I'm ok with this code checked in, so I'm approving it, but not merging it. Waiting for other team members to comment
Thanks for your comments, Ali! I will add a new commit with suggested updates. Feel free to add new suggestions, if you notice some. |
New commits address the reviewers comments and introduce support for parameters on the stack. Content of commits in new changes0007 Addressing comments 1
0008 [TA] Support parameters on the stack
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is invalid code which results in a compiler warning about incompatible integer to pointer conversion. Is that intentionally ignored to create a test case? Fixing the code by passing address of k ( pass &k to fun()) fixes the code and there is no core-dump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment. Yes, this in intentionally ignored to create a test case. I am using "int" to "int*" conversion to mimic behavior of setting bad pointer value. In real cases the value is usually "nullptr", but I am using different magic values (like 1,2,3...) to make it easier to track the flow of the bad value.
In this particular test, I am testing the case where pointer ptr
is passed as a stack parameter, and set to the bad value, which originated from val
, which also a parameter forwarded through the stack.
Summary
This patch introduces support for analysis of functions, which call site is not in the backtrace, if the parameter is tainted. For now, only parameters forwarded through registers are supported.
This partially resolves #36
Description
To be able to track the value of function parameters, this patch introduces forward TaintAnalysis, which propagates the Taint from the function entry point to the point where the parameter value is set. If the path of the Taint is not terminated in the call (it is not set to constant value like in the tainted-param-inside-blame.test ), we should run the backward TaintAnalysis to try to propagate the Taint from the point where the parameter is set to a value, to the point where that value is set to constant ( tainted-params-outside-blame.test ).
Content of commits
0001-Target-Helpers-for-param-forwarding-registers.patch
0002-TaintDFG-Upgrade-TaintDFG-infrastructure.patch
0003-TA-Detect-tainted-parameters.patch
0004-TA-Introduce-forward-Taint-Analysis.patch
(like runOnBlameMF, but simplified, and in the forward direction)
Idea is to propagate the Taint from parameter (function entry point) to the
program point, where the parameter's value is set.
(Simplified version of propagateTaint, but in the oposite (forward) direction)
is not empty, we run the Backward Analysis
(that covers cases where the parameter is set in the call, or if it gets value from another parameter)
0005-TA-Analysis-of-already-decompiled-functions.patch
(so crash-start is not at the expected place as for other out of the BT calls)
0006-New-tests-for-tainted-params-analysis.patch
Example
Run crash analyzer:
llvm-crash-analyzer --print-potential-crash-cause-loc ./m --core-file core.m
Output:
TaintDFG: