type casting verification stopping an emerging attack
play

Type Casting Verification: Stopping an Emerging Attack Vector - PowerPoint PPT Presentation

Type Casting Verification: Stopping an Emerging Attack Vector Byoungyoung Lee, Chengyu Song, Taesoo Kim, and Wenke Lee Georgia Institute of Technology 1 Vulnerability Trends Microsoft vulnerability trends (2013) Use-after-free Stack


  1. Type Casting Verification: Stopping an Emerging Attack Vector Byoungyoung Lee, Chengyu Song, Taesoo Kim, and Wenke Lee Georgia Institute of Technology 1

  2. Vulnerability Trends Microsoft vulnerability trends (2013) Use-after-free Stack overflow Heap overflow Bad casting (or type confusion) 2

  3. Stack Overflows Microsoft vulnerability trends (2013) # of Stack overflows is decreasing

  4. Use-After-Free # of Use-after-free is increasing  Preventing Use-after-free with Dangling Pointers Nullification [NDSS ’15] Microsoft vulnerability trends (2013)

  5. Bad-casting Bad-casting (or type confusion) is still not solved. 5

  6. Type Conversions in C++ • static_cast – Compile-time conversions – Fast : no extra verification in run-time – No information on actually allocated types in runtime. • dynamic_cast – Run-time conversions – Requires Runtime Type Information (RTTI) – Slow : Extra verification by parsing RTTI – Typically prohibited in performance critical applications 6

  7. Upcasting and Downcasting • Upcasting – From a derived class to its parent class • Downcasting – From a parent class to one of its derived classes 7

  8. Upcasting and Downcasting • Upcasting – From a derived class to its parent class • Downcasting – From a parent class to one of its derived classes Element HTMLElement SVGElement 7

  9. Upcasting and Downcasting • Upcasting – From a derived class to its parent class • Downcasting – From a parent class to one of its derived classes Upcasting Element HTMLElement SVGElement 7

  10. Upcasting and Downcasting • Upcasting – From a derived class to its parent class • Downcasting – From a parent class to one of its derived classes Downcasting Upcasting Element HTMLElement SVGElement 7

  11. Upcasting and Downcasting • Upcasting – From a derived class to its parent class • Downcasting – From a parent class to one of its derived classes Downcasting Upcasting Element HTMLElement SVGElement Upcasting is always safe, but downcasting is not! 7

  12. Downcasting is not always safe! class P { class D: public P { virtual ~P() {} virtual ~D() {} int m_P; int m_D; }; }; 8

  13. Downcasting is not always safe! class P { class D: public P { virtual ~P() {} virtual ~D() {} int m_P; int m_D; }; }; vftptr for P int m_P Access scope of P* 8

  14. Downcasting is not always safe! class P { class D: public P { virtual ~P() {} virtual ~D() {} int m_P; int m_D; }; }; vftptr for D vftptr for P int m_P int m_P Access scope of P* int m_D Access scope of D* 8

  15. Downcasting can be Bad-casting P *pS = new P(); D *pD = static_cast<D*>(pS); pD->m_D; 9

  16. Downcasting can be Bad-casting Bad-casting occurs: D is not a sub-object of P  Undefined behavior P *pS = new P(); D *pD = static_cast<D*>(pS); D *pD = static_cast<D*>(pS); pD->m_D; 9

  17. Downcasting can be Bad-casting P *pS = new P(); D *pD = static_cast<D*>(pS); pD->m_D; pD->m_D; Memory corruptions 9

  18. Downcasting can be Bad-casting vftptr for P P *pS = new P(); int m_P D *pD = static_cast<D*>(pS); pD->m_D; pD->m_D; Memory corruptions 9

  19. Downcasting can be Bad-casting &(pD->m_D) vftptr for P P *pS = new P(); int m_P D *pD = static_cast<D*>(pS); pD->m_D; pD->m_D; Memory corruptions 9

  20. Downcasting can be Bad-casting &(pD->m_D) vftptr for P P *pS = new P(); int m_P D *pD = static_cast<D*>(pS); int m_D pD->m_D; pD->m_D; Memory corruptions 9

  21. Downcasting can be Bad-casting &(pD->m_D) vftptr for P P *pS = new P(); int m_P D *pD = static_cast<D*>(pS); int m_D pD->m_D; pD->m_D; Memory corruptions 9

  22. Real-world Exploits on Bad-casting • CVE-2013-0912 – A bad-casting vulnerability in Chrome – Used in 2013 Pwn2Own ContainerNode Element HTMLElement SVGElement HTMLUnknownElement 10

  23. Real-world Exploits on Bad-casting • CVE-2013-0912 – A bad-casting vulnerability in Chrome – Used in 2013 Pwn2Own ContainerNode Element HTMLElement SVGElement HTMLUnknownElement 1. Allocated 10

  24. Real-world Exploits on Bad-casting • CVE-2013-0912 – A bad-casting vulnerability in Chrome – Used in 2013 Pwn2Own ContainerNode 2. Upcasting Element HTMLElement SVGElement HTMLUnknownElement 1. Allocated 10

  25. Real-world Exploits on Bad-casting • CVE-2013-0912 – A bad-casting vulnerability in Chrome – Used in 2013 Pwn2Own ContainerNode 2. Upcasting 3. Downcasting Element HTMLElement SVGElement HTMLUnknownElement 1. Allocated 10

  26. Real-world Exploits on Bad-casting • CVE-2013-0912 – A bad-casting vulnerability in Chrome – Used in 2013 Pwn2Own ContainerNode 2. Upcasting 3. Downcasting Element HTMLElement SVGElement 160 bytes HTMLUnknownElement 1. Allocated 96 bytes 10

  27. Real-world Exploits on Bad-casting ScriptWrapperble NoBaseWillBeGarbageCollectedFinalized<> EventTarget TreeShared<Node> Node ContainerNode Element HTMLElement PseudoElement VTTElement VTTElement SVGElement LabelableElement HtmlTableElement HTMLRubyElement HTMLFontElement 57 classes! HTMLMenuElement HTMLLabelElement … HTMLUnknownElement 11

  28. Real-world Exploits on Bad-casting ScriptWrapperble NoBaseWillBeGarbageCollectedFinalized<> EventTarget TreeShared<Node> Node ContainerNode Very complex class hierarchies Element  Error-prone type casting operations HTMLElement PseudoElement VTTElement VTTElement SVGElement LabelableElement HtmlTableElement HTMLRubyElement HTMLFontElement 57 classes! HTMLMenuElement HTMLLabelElement … HTMLUnknownElement 11

  29. Existing Solutions and Challenges • Replace all static_cast into dynamic_cast • dynamic_cast on a polymorphic class (with RTTI) – A pointer points to a virtual function table pointer – Traversing a virtual function table leads to RTTI Offset to the top ptr &std::type_info A class name vftptr 1 st virtual function … … 12

  30. Existing Solutions and Challenges • dynamic_cast on a non-polymorphic class – A pointer points to the first member variable – Simply traversing such a variable leads to a runtime crash ptr … ... 13

  31. Existing Solutions and Challenges • dynamic_cast on a non-polymorphic class – A pointer points to the first member variable – Simply traversing such a variable leads to a runtime crash ptr … ... C++ supports no reliable methods to resolve whether a pointer points to polymorphic or non-polymorphic classes. 13

  32. Existing Solutions and Challenges • dynamic_cast on a non-polymorphic class – A pointer points to the first member variable – Simply traversing such a variable leads to a runtime crash ptr … ... C++ supports no reliable methods to resolve whether a pointer points to polymorphic or non-polymorphic classes. Previous solutions including Undefined Behavior Sanitizer relies on blacklists. 13

  33. CaVer: CastVerifier • CaVer : CastVerifier – A bad-casting detection tool • Design goals – Easy-to-deploy: no blacklists – Reasonable runtime performance 14

  34. CaVer Overview Emit THTable Source code Instrumentation Compile 15

  35. CaVer Overview Emit THTable Source code Instrumentation CaVer Runtime Compile Link 15

  36. CaVer Overview Emit THTable Source Secured code executable Instrumentation CaVer Runtime Compile Link 15

  37. Technical Goal of CaVer P *ptr = new P ; static_cast< D *>( ptr ); 16

  38. Technical Goal of CaVer P *ptr = new P ; Allocated static_cast< D *>( ptr ); 16

  39. Technical Goal of CaVer P *ptr = new P ; Allocated static_cast< D *>( ptr ); To be casted 16

  40. Technical Goal of CaVer P *ptr = new P ; Allocated static_cast< D *>( ptr ); To be casted ptr Object (P) 16

  41. Technical Goal of CaVer P *ptr = new P ; Allocated static_cast< D *>( ptr ); To be casted Q. What are the class relationships b/w P and D?  THTable ptr Object (P) 16

  42. Technical Goal of CaVer P *ptr = new P ; Allocated static_cast< D *>( ptr ); To be casted Q. What are the class relationships b/w P and D?  THTable ptr Object (P) Q. Is ptr points to P or D?  Runtime type tracing 16

  43. Type Hierarchy Table (THTable) • A set of all legitimate classes to be converted – Class names are hashed for fast comparison – Hierarchies are unrolled to avoid recursive traversal THTable (P) THTable (D) h ash(“P”) h ash(“D”) … hash(“P”) … 17

  44. Type Hierarchy Table (THTable) • A set of all legitimate classes to be converted – Class names are hashed for fast comparison – Hierarchies are unrolled to avoid recursive traversal THTable (P) THTable (D) h ash(“P”) h ash(“D”) … hash(“P”) … Hashed class names 17

  45. Type Hierarchy Table (THTable) • A set of all legitimate classes to be converted – Class names are hashed for fast comparison – Hierarchies are unrolled to avoid recursive traversal Unrolled linearly THTable (P) THTable (D) h ash(“P”) h ash(“D”) … hash(“P”) … 17

  46. Runtime Type Tracing P *ptr = new P; P *ptr = new P; trace(ptr, &THTable(P)); 18

  47. Runtime Type Tracing P *ptr = new P; P *ptr = new P; trace(ptr, &THTable(P)); THTable (P) h ash(“P”) … ptr Object (P) 18

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend