This is an archive of the discontinued LLVM Phabricator instance.

UBSan: crash less often on corrupted Vtables.
ClosedPublic

Authored by krasin on Apr 29 2016, 4:15 PM.

Details

Summary

This CL adds a weak check for a Vtable prefix: for a well-formed
Vtable, we require the prefix to be within [-1<<20; 1<<20].

Practically, this solves most of the known cases when UBSan segfaults
without providing any useful diagnostics.

Diff Detail

Event Timeline

krasin updated this revision to Diff 55684.Apr 29 2016, 4:15 PM
krasin retitled this revision from to UBSan: crash less often on corrupted Vtables..
krasin updated this object.
krasin added a reviewer: pcc.

Hi Peter,

I realize that this CL misses a test and I would like to write one. I am currently stubled by the fact that the code changed lives within ubsan_type_hash_itanium.cc, so the test could only run on a subset of supported platforms. It's unclear to me what should I add to the test restrictions to make it happen.

krasin updated this revision to Diff 59289.Jun 1 2016, 3:22 PM

Added a test.

krasin updated this revision to Diff 59291.Jun 1 2016, 3:24 PM

remove debug printf.

krasin added a comment.Jun 1 2016, 3:25 PM

Hi Peter,

I have added a test. Please, take a look.

pcc added inline comments.Jun 1 2016, 4:53 PM
test/ubsan/TestCases/TypeCheck/vptr_itanium.cpp
1 ↗(On Diff #59291)

Maybe name this something like vptr-corrupted-vtable-itanium.cpp?

33 ↗(On Diff #59291)

This isn't necessarily true for objects with sufficiently large bases. Can we change this to say that the object probably has an invalid vptr?

krasin updated this revision to Diff 59319.Jun 1 2016, 5:33 PM
krasin marked an inline comment as done.

rename test; print better diagnostics for the suspicious offset.

krasin added a comment.Jun 1 2016, 5:35 PM

Peter,

please, take another look.
Note: I have also fixed a hidden bug (reproduced under TSAN) that sometimes the test would fail due to TypeInfo being zero rather than big abs(Offset). Now I try to properly initialize that field.

test/ubsan/TestCases/TypeCheck/vptr_itanium.cpp
33 ↗(On Diff #59291)

Done. Is it what you meant?

Peter,

friendly ping!

pcc accepted this revision.Jun 2 2016, 10:49 AM
pcc edited edge metadata.

LGTM with nits

lib/ubsan/ubsan_handlers_cxx.cc
60

"abs(offset) too big" doesn't really mean anything to users, maybe drop it?

62

same here

lib/ubsan/ubsan_type_hash.h
56

The comment is inaccurate, your code allows negative offsets.

Also, just "offsets" is a little unclear, maybe say "offset to top"?

This revision is now accepted and ready to land.Jun 2 2016, 10:49 AM
krasin updated this revision to Diff 59433.Jun 2 2016, 11:23 AM
krasin edited edge metadata.

fix comments / error messages.

Please, take another look.

lib/ubsan/ubsan_handlers_cxx.cc
60

abs(offset to top) too big -- is it better now?
even if the users would not be able to grasp the details, it will let them to distinguish between different error messages here, which is important since some them (like this one) has a lower confidence of being right.

Let me know if you feel strongly about removing these details from the message. I will comply.

lib/ubsan/ubsan_type_hash.h
56

Done.

pcc added a comment.Jun 2 2016, 11:37 AM

LGTM

lib/ubsan/ubsan_handlers_cxx.cc
60

Okay, sounds reasonable enough.

62

But you don't need to repeat the description here.

krasin closed this revision.Jun 2 2016, 11:42 AM