<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 27, 2017 at 12:04 AM, Dmitry Vyukov <span dir="ltr"><<a href="mailto:dvyukov@google.com" target="_blank">dvyukov@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">On Wed, Mar 22, 2017 at 12:29 AM, Kostya Serebryany via Phabricator<br>
via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
> kcc added a comment.<br>
><br>
>>> But I foresee that as being difficult<br>
><br>
> Yep. That pesky phase-ordering again.<br>
><br>
><br>
> Repository:<br>
>   rL LLVM<br>
><br>
> <a href="https://reviews.llvm.org/D31112" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D31112</a><br>
<br>
<br>
</div></div>FWIW another option for general case that may be faster.<br>
<br>
We emit a unique hash after each call instruction:<br>
<br>
  call <foo><br>
  nop $0x12345678 // can use nop disp<br></blockquote><div><br></div><div>This is similar to Intel's ENDBRANCH, but applied to RET instead of CALL</div><div>and with a callee-specific hash instead of a global one. </div><div><br></div><div>This protection may be bypassed in the presence of a JIT<br></div><div>if the attacker may force the JIT to emit the code containing the magic bytes. </div><div><br></div><div>But otherwise, yes, that's yet another option to consider (we've discussed it quite a few times offline),</div><div>and the compiler analysis required here is very similar. </div><div><br></div><div>--kcc </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
The hash is associated with the callee. Callee checks that there is a<br>
correct hash at the return site:<br>
<br>
<foo>:<br>
  ...<br>
  mov 8(%rsp), %r8<br>
  cmpd 2(%r8), $0x12345678<br>
  jne bad<br>
  ret<br>
<br>
Can also use pop+jmp, not sure if it's faster:<br>
<br>
<foo>:<br>
  ...<br>
  pop %r8<br>
  cmpd 2(%r8), $0x12345678<br>
  jne bad<br>
  jmp %r8<br>
</blockquote></div><br></div></div>