This is an archive of the discontinued LLVM Phabricator instance.

[safestack] Protect byval function arguments.
ClosedPublic

Authored by eugenis on Nov 24 2015, 4:07 PM.

Details

Reviewers
eugenis
pcc
Summary

Detect unsafe byval function arguments and move them to the unsafe
stack.

A simple SDAG change required to handle the case of dbg.declare for
a function parameter pointing to neither a function argument nor an
AllocaInst.

Diff Detail

Repository
rL LLVM

Event Timeline

eugenis updated this revision to Diff 41096.Nov 24 2015, 4:07 PM
eugenis retitled this revision from to [safestack] Protect byval function arguments..
eugenis updated this object.
eugenis added a reviewer: pcc.
eugenis set the repository for this revision to rL LLVM.
eugenis added a subscriber: llvm-commits.
pcc added inline comments.Nov 24 2015, 6:37 PM
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
4466–4471 ↗(On Diff #41096)

Can you please split this out into a separate change with its own test case?

lib/Transforms/Instrumentation/SafeStack.cpp
60

*Arguments

243–248

Seems simpler to have the caller pass in the size (or just the type) instead of computing it here.

504

Is it necessary to cast the result of getNextNode (here and elsewhere)? Looks like it already returns an instruction (see e.g. line 516).

test/Transforms/SafeStack/debug-loc.ll
17–21

This should all live next to the code so that it is clear what corresponds to what.

27

Should this be checking for specific constants? (same below)

eugenis updated this revision to Diff 41204.Nov 25 2015, 5:34 PM
eugenis marked 5 inline comments as done.
eugenis added inline comments.
lib/Transforms/Instrumentation/SafeStack.cpp
504

Right, it works without a cast. Fixed in multiple places.

pcc edited edge metadata.Nov 25 2015, 6:20 PM
pcc added a subscriber: pcc.

Lgtm once sdag change lands.

Do you also need to handle inalloca?

pcc added a comment.Nov 25 2015, 7:08 PM

There's not much we can do about inallocah because it represents an ABI break if we move them to the unsafe stack. This only affects windows right?

Peter

Would it be possible to handle inalloca by copying it onto the unsafe stack and then back before the return from the function? We would need to handle exceptional control flow as well, which could be quite complicated.

pcc added a comment.Nov 30 2015, 11:58 AM

That would break things, unfortunately. Consider this code:

A *ptr;

struct A {
  A() {
    ptr = this;
  }
};

void f(A a) {
 assert(ptr == &a);
}

void g() {
  f(A());
}

If we make a copy of a in f, the assertion would fail.

eugenis updated this revision to Diff 41454.Nov 30 2015, 4:40 PM
eugenis edited edge metadata.

rebase

eugenis accepted this revision.Nov 30 2015, 4:42 PM
eugenis added a reviewer: eugenis.

lgtm'd by pcc earlier

This revision is now accepted and ready to land.Nov 30 2015, 4:42 PM
eugenis closed this revision.Nov 30 2015, 4:43 PM

r254353
Thanks for the review.