This is an archive of the discontinued LLVM Phabricator instance.

Cross-DSO control flow integrity (Clang part)
ClosedPublic

Authored by eugenis on Dec 8 2015, 6:26 PM.

Details

Reviewers
kcc
pcc
Summary

Clang-side cross-DSO CFI.

  • Enabled with -fsanitize-cfi-cross-dso
  • uses a runtime library, unlike "plain" CFI
  • does not yet support diagnostics
  • Emits __cfi_slowpath calls if bitset test fails. This routes the check to the target module, which may know more about the runtime type of the object or function.
  • Set a module flag to enable __cfi_check generation during LTO.

Diff Detail

Repository
rL LLVM

Event Timeline

eugenis updated this revision to Diff 42261.Dec 8 2015, 6:26 PM
eugenis retitled this revision from to Cross-DSO control flow integrity (Clang part).
eugenis updated this object.
eugenis added reviewers: kcc, pcc.
eugenis set the repository for this revision to rL LLVM.
eugenis added a subscriber: cfe-commits.
pcc added inline comments.Dec 9 2015, 2:46 PM
lib/CodeGen/CGExpr.cpp
2557

What happens if MD is not an MDString?

lib/CodeGen/CodeGenModule.cpp
1038

I would move the logic back here and make the check for definedness etc explicit. We shouldn't emit a bitset entry if the function has available_externally linkage for example.

eugenis updated this revision to Diff 42607.Dec 11 2015, 4:41 PM
eugenis marked an inline comment as done.
eugenis added inline comments.
lib/CodeGen/CGExpr.cpp
2557

assert + check on the caller side

pcc added inline comments.Dec 11 2015, 5:52 PM
lib/CodeGen/CGClass.cpp
2585

This could be an early return.

lib/CodeGen/CGExpr.cpp
2560

Use cast instead of dyn_cast/assert (but see my other comment).

3864

Early return.

lib/CodeGen/CodeGenModule.cpp
1037

This is a little hard to read and probably needs to go back into a function with early returns. Sorry, my bad. I also think the logic for available_externally is wrong (please add a test case).

1041

This isn't handling function types with internal linkage.

We can probably do this more consistently (e.g. by introducing a function that takes a Metadata from CreateMetadataIdentifierForType and returns a ConstantInt or nullptr if none suitable, and using it here, in callers of EmitCfiSlowPathCheck and in CreateVTableBitSetEntry).

eugenis updated this revision to Diff 42782.Dec 14 2015, 2:44 PM
eugenis marked 3 inline comments as done.
eugenis added inline comments.
lib/CodeGen/CGExpr.cpp
3864

It's too early to return.

lib/CodeGen/CodeGenModule.cpp
1037

Moved out to a function. Added a testcase. Looks like available_externally is handled correctly.

pcc edited edge metadata.Dec 14 2015, 3:00 PM

Please add documentation. At the very least please document flags in docs/ControlFlowIntegrity.rst and docs/UsersManual.rst. We should also document the design in docs/ControlFlowIntegrityDesign.rst.

lib/CodeGen/CGExpr.cpp
3864

Yes, sorry.

lib/CodeGen/CodeGenModule.cpp
1037

Yes, that's because you fixed it :)

1041

What about callers of EmitCfiSlowPathCheck?

eugenis updated this revision to Diff 42806.Dec 14 2015, 5:15 PM
eugenis edited edge metadata.
eugenis marked 2 inline comments as done.

added some docs

lib/CodeGen/CodeGenModule.cpp
1041

updated

1041

fixed

eugenis updated this revision to Diff 42902.Dec 15 2015, 1:37 PM

added the new flag to UserManual

pcc accepted this revision.Dec 15 2015, 2:23 PM
pcc edited edge metadata.

LGTM modulo some wordsmithing in the documentation.

docs/ControlFlowIntegrity.rst
31

"Experimental support for". Please also mention that the ABI is unstable.

32

"exists"

docs/ControlFlowIntegrityDesign.rst
375

"The basic CFI mode"

377

"hierarchy"; "at link time"

389

"comparable"

390

"from an instrumented DSO"

392

same

426

"It is possible, but unlikely, that collisions"

446

"is a"

450

I wouldn't claim this is "for performance reasons" unless we have data to back it up. I would remove this paragraph and mention the alignment in the next section.

include/clang/Driver/Options.td
628

"Disable"

This revision is now accepted and ready to land.Dec 15 2015, 2:23 PM
eugenis updated this revision to Diff 42914.Dec 15 2015, 2:40 PM
eugenis edited edge metadata.
eugenis marked 10 inline comments as done.
eugenis added inline comments.
docs/ControlFlowIntegrityDesign.rst
389

That changes the meaning of the sentence. I've changed the wording in a different way.

pcc added a comment.Dec 15 2015, 2:46 PM

LGTM

docs/ControlFlowIntegrityDesign.rst
389

"with a performance penalty"

eugenis updated this revision to Diff 42918.Dec 15 2015, 2:48 PM
eugenis marked an inline comment as done.
eugenis closed this revision.Dec 15 2015, 3:04 PM

r255694