Page MenuHomePhabricator

hwasan: Instrument globals.
ClosedPublic

Authored by pcc on Aug 5 2019, 12:40 PM.

Details

Summary

Globals are instrumented by adding a pointer tag to their symbol values
and emitting metadata into a special section that allows the runtime to tag
their memory when the library is loaded.

Due to order of initialization issues explained in more detail in the comments,
shadow initialization cannot happen during regular global initialization.
Instead, the location of the global section is marked using an ELF note,
and we require libc support for calling a function provided by the HWASAN
runtime when libraries are loaded and unloaded.

Based on ideas discussed with @evgeny777 in D56672.

Depends on D65686

Depends on D65768

Depends on D65769

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.Aug 5 2019, 12:40 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptAug 5 2019, 12:40 PM
Herald added subscribers: Restricted Project, cfe-commits, hiraditya and 2 others. · View Herald Transcript
vitalybuka added inline comments.Aug 5 2019, 2:15 PM
compiler-rt/lib/hwasan/hwasan.cpp
221 ↗(On Diff #213434)

Can this be just following?

u32 size:24;
u8 tag;
236 ↗(On Diff #213434)

could this be a normal constant?

vitalybuka added inline comments.Aug 5 2019, 2:28 PM
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
1203 ↗(On Diff #213434)

what is going to happen with size > 2^24?

pcc marked 3 inline comments as done.Aug 5 2019, 2:40 PM
pcc added inline comments.
compiler-rt/lib/hwasan/hwasan.cpp
221 ↗(On Diff #213434)

It could, but since these structs are created by the pass I didn't want to make any assumptions about bitfield layout (even though I think we should always end up with the layout we expect on the platforms we care about), and the way I've written it the code is more "obviously" correct when comparing it against the pass.

236 ↗(On Diff #213434)

You mean like an enum? Sure.

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
1203 ↗(On Diff #213434)

We create multiple descriptors, see the loop on lines 1242-1262.

pcc updated this revision to Diff 213472.Aug 5 2019, 2:53 PM
  • Switch to an enum
pcc updated this revision to Diff 213477.Aug 5 2019, 3:28 PM
  • Increment num_descriptions_printed in the right place
vitalybuka accepted this revision.Aug 6 2019, 11:50 AM
This revision is now accepted and ready to land.Aug 6 2019, 11:50 AM
Closed by commit rL368102: hwasan: Instrument globals. (authored by pcc, committed by ). · Explain WhyAug 6 2019, 3:07 PM
This revision was automatically updated to reflect the committed changes.