Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How compilers got less terrible

How compilers got less terrible

A talk I gave at hushcon east

Richo Healey

May 15, 2015
Tweet

More Decks by Richo Healey

Other Decks in Programming

Transcript

  1. who am I • security engineering at Stripe • work

    on (and have capital-F Feelings about) compilers • Co-own the only CVE for a skateboard with mike • (Go lookup 2015-2247 it’s pretty lols) • wrong island con
  2. Compilers are super neat • Sometimes they’ll save you from

    yourself • Sometimes they won’t • Sometimes they’ll essentially go out of their way to be footguns
  3. what even is a compiler Lex tokens Parse AST Codegen

    asm Assembler Object Link Executable input
  4. TOK int TOK thing LPAREN tok void STAR tok s

    LBRACE tok puts LPAREN STRING hi! RPAREN SEMI RBRACE
  5. what even is a compiler Lex tokens Parse AST Codeg

    asm Assem Objec Link Execu input Analysis!
  6. what even is a compiler Lex tokens Parse AST Codeg

    asm Assem Objec Link Execu input Type checking Coherence Optimisation
  7. cool, so why do I give a fuck? • In

    the context of safety there are really only two high level things you should actually care about:
  8. cool, so why do I give a fuck? • How

    hard is it to crash my program? • How hard is it for an attacker to make that crash turing complete?
  9. difficulty of crash == memory safety • Naïve solutions, fully

    managed memory: • Refcounting • Garbage collection
  10. memory safety: hardcode mode • Region based analysis: • Apple’s

    ARC • Rust’s borrow checker • enferex wrote a paper on slapping this onto golang
  11. Creating an stack frame Dataz Old frame pointer return address

    mflr r0 stw r0, 4(r1) stwu r1, -16(r1) Dataz Old frame pointer return address
  12. Destroying an stack frame Dataz Old frame pointer return address

    addi r1, r1, 16 lwz r0, 4(r1) mtlr r0 blr Dataz Old frame pointer return address
  13. ohnoes Dataz Old frame pointer return address lwz r3, -16(r1)

    blr sym.gets addi r1, r1, 16 lwz r0, 4(r1) mtlr r0 blr Dataz Old frame pointer return address
  14. You don’t even have to do that iff: * Your

    overwite is big enough * Some idiot made the stack executable
  15. RELRO • Not actually a great protection, but a fine

    deterrent • Some pretty neat WTF about it’s original design
  16. Conclusion • I did not actually have a point •

    I just think compilers are neat • Rust == Good • Go == Good but fucking lulzy if you dare peek under the covers • Shoutout to ben who lent me a charger at 1 this morning