This is an archive of the discontinued LLVM Phabricator instance.

[RFC] Sanitize upcasts and conversion to virtual base
ClosedPublic

Authored by samsonov on Oct 6 2014, 5:47 PM.

Details

Reviewers
rsmith
Summary

This change adds UBSan check to upcasts. Namely, when we
perform derived-to-base conversion, we:

  1. check that the pointer-to-derived has suitable alignment and underlying storage, if this pointer is non-null.
  2. if vptr-sanitizer is enabled, and we perform conversion to virtual base, we check that pointer-to-derived has a matching vptr.

For now, this change lacks UBSan output tests in compiler-rt, I'm sending
it as an RFC to check that I'm doing the correct thing, and to agree
on error messages and enums wordings.

Diff Detail

Event Timeline

samsonov updated this revision to Diff 14480.Oct 6 2014, 5:47 PM
samsonov updated this revision to Diff 14481.
samsonov retitled this revision from to [RFC] Sanitize upcasts and conversion to virtual base.
samsonov updated this object.
samsonov edited the test plan for this revision. (Show Details)
samsonov added a reviewer: rsmith.
samsonov added a subscriber: Unknown Object (MLST).

Remove bogus comment.

rsmith added inline comments.Oct 7 2014, 5:36 PM
tools/clang/lib/CodeGen/CGClass.cpp
186

I am not sure that the SkipNullCheck behavior here is right. If NullCheckValue is false, then I think we should be performing a null check inside EmitTypeCheck rather than assuming the pointer is non-null.

samsonov added inline comments.Oct 7 2014, 6:28 PM
tools/clang/lib/CodeGen/CGClass.cpp
186

That is, just pass "false" here? But in some cases we're calling CodeGenFunction::GetAddressOfBaseClass on values which are guaranteed to be non-null (e.g. on materialized temporaries), as they happen in compiler-generated code. I'm not sure we still want to emit null-check in EmitTypeCheck in this case.

rsmith accepted this revision.Oct 7 2014, 6:32 PM
rsmith edited edge metadata.

OK, let's skip emitting the null check for now. If someone manages to get a null in here, then we'll probably crash on the UB, which is not ideal but acceptable.

This revision is now accepted and ready to land.Oct 7 2014, 6:32 PM
samsonov closed this revision.Oct 27 2014, 3:32 PM