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

Upper frame crash-start sunk into next BB #34

Open
niktesic opened this issue Dec 16, 2022 · 2 comments
Open

Upper frame crash-start sunk into next BB #34

niktesic opened this issue Dec 16, 2022 · 2 comments

Comments

@niktesic
Copy link
Contributor

Test source code:

void crash(int* ptr) {
  *ptr = 3;
}

int main(){
  int* p;
  int cond = 1;
  p = 0x0;
  if (cond)
    crash(p);
  cond += 2;
  return cond - *p;
}

Compiled with:
$ clang -g -O0 m.c -o m

In the decompiled MIR, for the presented test case, in the main() frame,
call instruction (corresponding to crash(p)) is the last in it's Basic block.
Since Decompiler marks with crash-start flag, the instruction after call,
it means that crash-start instruction for main() frame is first in it's Basic block.
For this reason, Taint Analysis is skipped for function main() and
any upper frames in similar cases.

@niktesic niktesic changed the title Upper frame crash-start sinked into next BB Upper frame crash-start sunk into next BB Dec 16, 2022
@ananthakri
Copy link

It does not make sense why main() is skipped. Is there an issue in starting analysis at the start of a basic-block? The function main() should be analyzed from call-site( crash()) back to entry point of main.

@niktesic
Copy link
Contributor Author

It does not make sense why main() is skipped. Is there an issue in starting analysis at the start of a basic-block? The function main() should be analyzed from call-site( crash()) back to entry point of main.

The current Taint Analysis implementation expects the following sequence of instructions for any upper frame:

  1. First analyzed instruction for that frame
  2. Call instruction to the lower frame
  3. Crash-start instruction after the call
    Whole sequence needs to be in the same Basic Block.

The code which prevents analysis if the sequence is not as expected is at crash_analyzer::TaintAnalysis::runOnBlameMF.

There are two possible solutions that come to my mind:

  1. Add artificial NOP after Call instruction to ensure there is expected sequence
  2. Make TA resilient to such cases, and look for the first analyzed instruction in the previous BB.

For this reason, Taint Analysis is skipped for function main() and
any upper frames in similar cases.
My mistake, the TA would be performed for upper frames, but the corrupted one (without expected instruction sequence) would be skipped.

Thanks,
Nikola

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants