SoK: Sanitizing for Security
Dokyung Song, Julian Lettner, Prabhu Rajasekaran, Yeoul Na, Stijn Volckaert, Per Larsen, Michael Franz
SoK: Sanitizing for Security Dokyung Song , Julian Lettner, Prabhu - - PowerPoint PPT Presentation
SoK: Sanitizing for Security Dokyung Song , Julian Lettner, Prabhu Rajasekaran, Yeoul Na, Stijn Volckaert, Per Larsen, Michael Franz Finding Bugs in C/C++ Manual Analysis Static Analysis Dynamic Analysis AddressSanitizer MemorySanitizer Code
Dokyung Song, Julian Lettner, Prabhu Rajasekaran, Yeoul Na, Stijn Volckaert, Per Larsen, Michael Franz
May 2019 2
C/C++ Source Code Code Review/Auditing
Static Analysis
Clang Static Analyzer
Dynamic Analysis Manual Analysis
american fuzzy lop Hand-written test suite libFuzzer Program Inputs
AddressSanitizer MemorySanitizer
May 2019 3
C/C++ Source Code Code Review/Auditing
Static Analysis
Clang Static Analyzer
Dynamic Analysis Manual Analysis
american fuzzy lop
AddressSanitizer MemorySanitizer
Hand-written test suite libFuzzer Program Inputs
– that find vulnerabilities specific to C/C++
May 2019 4
Bcc Memcheck
LBC ASan Electric Fence PageHeap D&A Safe-C P&F MSCC SoftBounds+CETS CRED BBC EffectiveSan PAriCheck Low-Fat DangSan DangNull 1990 2000 2005 2010 2015 RTCC 2019 TypeSan TySan CaVer CUP SGXBounds FreeSentry MSan Oscar CRCount UBSan 1995 HexType Purify 1980 Undangle
May 2019 5
Attack Flow
Function Pointer Overwrite Indirect Call Heap Overflow Integer Overflow +
May 2019 6
Attack Flow
Function Pointer Overwrite Indirect Call Heap Overflow Integer Overflow +
Exploit Mitigation Security Policies
Control-Flow Integrity Memory Safety Code Pointer Integrity AddressSanitizer UndefinedBehaviorSanitizer … and many others
Sanitization Policies
May 2019 7
Attack Flow
Function Pointer Overwrite Indirect Call Heap Overflow Integer Overflow +
Exploit Mitigation Security Policies
Control-Flow Integrity Memory Safety Code Pointer Integrity
Sanitization Policies
AddressSanitizer UndefinedBehaviorSanitizer … and many others
May 2019 8
Exploit Mitigation Sanitization
The goal is to … Mitigate attacks Find vulnerabilities Used in … Production Pre-release Performance budget is … Very limited Much higher Policy violation leads to … Program termination Problem diagnosis Violations triggered at location of bug Sometimes Always Tolerance for FPs is … Zero Somewhat higher Surviving benign errors is … Desired Not desired
9 May 2019
J.2 Undefined behavior The behavior is undefined in the following circumstances: … — Addition or subtraction of a pointer into, or just beyond, an array object and an integer type produces a result that does not point into, or just beyond, the same array object (6.5.6). … — An object is referred to outside of its lifetime (6.2.4). … — A pointer is used to call a function whose type is not compatible with the referenced type. … — An object has its stored value accessed other than by an lvalue
…
10 May 2019
J.2 Undefined behavior The behavior is undefined in the following circumstances: … — Addition or subtraction of a pointer into, or just beyond, an array object and an integer type produces a result that does not point into, or just beyond, the same array object (6.5.6). … — An object is referred to outside of its lifetime (6.2.4). … — A pointer is used to call a function whose type is not compatible with the referenced type. … — An object has its stored value accessed other than by an lvalue
…
→ Well-known Security Vulnerabilities
mov rsi, QWORDPTR[rdi+8]
May 2019 11
Compile Source Code Binary Code sk = tun->sk; Null-pointer Dereference Null-pointer Dereference tun=NULL
if (!tun) return POLLERR;
// privileged code
May 2019 12
Compile sk = tun->sk; Source Code Binary Code Null-pointer Dereference tun=NULL
if (!tun) return POLLERR;
// privileged code
May 2019 13
Compile sk = tun->sk; Source Code Binary Code Null-pointer Dereference tun=NULL
Null pointer check gets eliminated (akin to CVE-2009-1897)
Compile if (!tun) return POLLERR;
// privileged code
mov rsi, QWORDPTR[rdi+8]
May 2019 14
sk = tun->sk;
// privileged code
Privilege Escalation Source Code Binary Code
Null pointer check gets eliminated (akin to CVE-2009-1897)
Null-pointer Dereference tun=NULL
15
Spatial Memory Safety Violation Temporal Memory Safety Violation Use of Uninitialized Variables Pointer Type Errors Bad Casting Other Pointer Type Errors Variadic Function Misuse Other Vulnerabilities Integer Overflow Other UBs
May 2019
violations.
Spatial Memory Safety Violation Temporal Memory Safety Violation Use of Uninitialized Variables Pointer Type Errors Bad Casting Other Pointer Type Errors Variadic Function Misuse Other Vulnerabilities Integer Overflow Other UBs
May 2019 16
bombs*.
*
Spatial Memory Safety Violation Temporal Memory Safety Violation Use of Uninitialized Variables Pointer Type Errors Bad Casting Other Pointer Type Errors Variadic Function Misuse Other Vulnerabilities Integer Overflow Other UBs
May 2019 17
bombs*.
*
pointer-checks
var-init=zero
aliasing
May 2019 18
Bug Finding Technique Metadata Management Program Instrumentation
Spatial Memory Safety Violation Red-zone Insertion (Guard Pages) Per-pointer Bounds Tracking Per-object Bounds Tracking Temporal Memory Safety Violation Reuse Delay Lock-and-key Dangling Pointer Tagging Use of Uninitialized Variables Uninitialized Memory Read Detection Uninitialized Value Use Detection Pointer Type Errors Pointer Casting Monitor Pointer Use Monitor Variadic Function Misuse Dangerous Format String Detection Argument Mismatch Detection Other Vulnerabilities Stateless Monitoring
(a) Dynamic Metadata (b) Static Metadata Object … Pointer …
Embedded Disjoint
(a) Language-level Instrumentation (b) IR-level Instrumentation (c) Binary Instrumentation
check(); call check
store ptr 111011101010 101010110101 010101011010 *ptr = 3;Others Instruction
19
Spatial Memory Safety Violation
Red-zone Insertion (Guard Pages) Per-pointer Bounds Tracking Per-object Bounds Tracking
Temporal Memory Safety Violation
Reuse Delay Lock-and-key Dangling Pointer Tagging
Use of Uninitialized Variables
Uninitialized Memory Read Detection Uninitialized Value Use Detection
Pointer Type Errors
Pointer Casting Monitor Pointer Use Monitor
Variadic Function Misuse
Dangerous Format String Detection Argument Mismatch Detection
Other Vulnerabilities
Stateless Monitoring
May 2019
Class of Bugs Bug Finding Technique
store ptr *ptr = 3; May 2019 20
Source code (C/C++) Intermediate Representation (e.g., LLVM IR) Binary
(a) Language-level (b) IR-level (c) Binary-level
check();
call check
11101110101 01010101101 01010101011 0101
Inlined Reference Monitor:
Fine-grained run-time monitoring
bugs as they occur.
Compiler Frontend Compiler Backend
(d) Library Interposition
LD_PRELOAD for instrumenting only calls to dynamically-linked external library functions
External Libraries
call
(a) Dynamic Metadata (b) Static Metadata
Others Instruction Object Pointer
May 2019 21
Embedded Disjoint
indirect/variadic call
before, after, and within an
Original program Sanitizer-instrumented program Needs to be created and propagated at run time
May 2019 22
Bug Finding Technique Metadata Management Program Instrumentation
Spatial Memory Safety Violation Red-zone Insertion (Guard Pages) Per-pointer Bounds Tracking Per-object Bounds Tracking Temporal Memory Safety Violation Reuse Delay Lock-and-key Dangling Pointer Tagging Use of Uninitialized Variables Uninitialized Memory Read Detection Uninitialized Value Use Detection Pointer Type Errors Pointer Casting Monitor Pointer Use Monitor Variadic Function Misuse Dangerous Format String Detection Argument Mismatch Detection Other Vulnerabilities Stateless Monitoring(a) Dynamic Metadata (b) Static Metadata Object … Pointer …
Embedded Disjoint
(a) Language-level Instrumentation (b) IR-level Instrumentation (c) Binary Instrumentation
check(); call check store ptr 1110111010101 0101011010101 0101011010 *ptr = 3;Others Instruction
False positives True negatives False negatives True positives
Performance and Memory Overheads Bug Detection Precision and Compatibility
sanitizers on the same experimental platform ( https://github.com/securesystemslab/ sanitizing-for-security-benchmarks)
bugs ( )
even smaller coverage
May 2019 23
May 2019 24
Well-defined programs w.r.t. the ISO Standard
Programs conforming to the ISO standard
May 2019 25
Well-defined programs w.r.t. the ISO Standard
Programs conforming to the ISO standard
May 2019 26
Well-defined programs w.r.t. the ISO Standard
Programs conforming to the ISO standard
e.g., programs creating OOB pointers Addition or subtraction of a pointer into, or just beyond, an array object and an integer type produces a result that does not point into, or just beyond, the same array object.*
* ISO/IEC JTC1/SC22/WG14. ISO/IEC 9899:2011, Programming Languages — C
May 2019 27 *
But in practice it seems to be common to transiently construct out-of-bounds pointers.* e.g., programs creating OOB pointers
Programs conforming to the de facto standard Programs conforming to the ISO standard
Real-world programs (Or De Facto Standard)
May 2019 28
Programs disallowed by the policy A typical sanitizer policy
False positives True negatives False negatives True positives
Programs conforming to the de facto standard Programs conforming to the ISO standard
May 2019 29
Programs disallowed by the policy A typical sanitizer policy
Compatibility with the ISO and de facto standards
Programs conforming to the de facto standard Programs conforming to the ISO standard
stored in memory
May 2019 30
May 2019 31
Programs disallowed by the policy A typical sanitizer policy Programs conforming to the de facto standard Programs conforming to the ISO standard
Finding bugs that elude existing or widely-deployed sanitizers
that elude AddressSanitizer:
reused
(static_casts)
casts and reinterpret_casts
programs if does not instruct the compiler using flags like -fno-strict- aliasing
May 2019 32
tracking
pointer metadata tracking difficult
while maintaining good compatibility
May 2019 33
fatptr=fat(ptr);
May 2019 34
Instrumented Uninstrumented
Fat pointer is not compatible with uninstrumented code Disjoint pointer metadata can get outdated, when uninstrumented code updates a pointer without updating corresponding metadata
Uninstrumented *fatptr *mem=new_ptr; check_bnds(ptr); Instrumented ptr=*mem; *ptr;
break programs having pointer to integer casts
between pointers and integers can be expensive
May 2019 35
some_object_type * → uint64_t
May 2019 36
atomic_store(addr_of_ptr, ptrA); atomic_store(addr_of_ptr, ptrB); *metadata_of_ptr = metadata_of_ptrA; *metadata_of_ptr = metadata_of_ptrB; Thread A Thread B Instrumented code metadata for ptr out-of-sync! ❶ ❷ ❸ ❹
are complex, due to weakly-typed nature of C
precision and performance trade-offs are yet to be explored.
stored value to be accessed by using pointers of many different types
May 2019 37
Composing sanitizers
source without generating duplicated bug reports for the bug’s side-effects
Using hardware features to improve performance and compatibility
tagging support in HW
Kernel and bare metal support
non-user-space programs in general
May 2019 38
Dokyung Song Ph.D. Student at UC Irvine dokyungs@uci.edu
39 May 2019