This is an archive of the discontinued LLVM Phabricator instance.

[HWASan] Do not retag allocas before return from the function.
ClosedPublic

Authored by alekseyshl on Jun 27 2018, 11:12 AM.

Details

Summary

Retagging allocas before returning from the function might help
detecting use after return bugs, but it does not work at all in real
life, when instrumented and non-instrumented code is intermixed.
Consider the following code:

F_non_instrumented() {
  T x;
  F1_instrumented(&x);
  ...
}

{
  F_instrumented();
  F_non_instrumented();
}
  • F_instrumented call leaves the stack below the current sp tagged randomly for UAR detection
  • F_non_instrumented allocates its own vars on that tagged stack, not generating any tags, that is the address of x has tag 0, but the shadow memory still contains tags left behind by F_instrumented on the previous step
  • F1_instrumented verifies &x before using it and traps on tag mismatch, 0 vs whatever tag was set by F_instrumented

Diff Detail

Repository
rL LLVM

Event Timeline

alekseyshl created this revision.Jun 27 2018, 11:12 AM
eugenis accepted this revision.Jun 28 2018, 1:58 PM

LGTM, but I don't like the flag name. Not retagging sounds like we leave randomly tagged stack frame after returning from a function. Rename it to something like zero-uar-tag, or retag-to-zero ?

This revision is now accepted and ready to land.Jun 28 2018, 1:58 PM
alekseyshl edited the summary of this revision. (Show Details)Jun 28 2018, 2:47 PM
  • Renamed the flag

How about this name?

Good, but please update flag description, too.

Good, but please update flag description, too.

I did

This revision was automatically updated to reflect the committed changes.