bug class genocide
play

Bug class genocide Applying science to eliminate 100% of buffer - PowerPoint PPT Presentation

Bug class genocide Applying science to eliminate 100% of buffer overflows Hackito Ergo Sum, 2014 Andreas Bogk, @andreasdotorg TOP SECRET//HCS/SI/TK//ORCON/NOFORN The problem void foo (char* arg) { char some[16]; char* p = some; while (*p++


  1. Bug class genocide Applying science to eliminate 100% of buffer overflows Hackito Ergo Sum, 2014 Andreas Bogk, @andreasdotorg TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  2. The problem void foo (char* arg) { char some[16]; char* p = some; while (*p++ = *arg++); } TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  3. The problem: spatial memory safety void foo (char* arg) { char some[16]; char* p = some; while (*p++ = *arg++); } TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  4. The other problem void bar (char* arg) { char* p = malloc(16); free(p); while (*p++ = *arg++); free(p); } TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  5. The other problem: temporal memory safety void bar (char* arg) { char* p = malloc(16); free(p); while (*p++ = *arg++); free(p); } TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  6. Existing approaches ● Use a safe language! ● Mitigations: ASLR, DEP, stack canaries ● Memory debugging tools: – Valgrind – gcc and llvm memory sanitizer – SAFEcode – Ccured – SafeC – Cyclone – Etc... – – TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  7. A word on notation red.is->compiler_generated(code); black.is->user_written(code); TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  8. Object-based approach if (IsPoisoned(address)) { ReportError(address); } *address = ...; // or: ... = *address; TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  9. Intrastructural safety struct { char id[8]; int account_balance; } bank_account; char* ptr = &(bank_account.id); strcpy(ptr, "overflow..."); TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  10. Pointer-based approach ● Every pointer represented by three words: pointer value, base, bound ● We call that a „fat pointer“ TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  11. Meet SoftBoundCETS ● Santosh Nagarakatte, Jianzhou Zhao, Milo M. K. Martin, Steve Zdancewic; UPenn ● SoftBound: spatial safety ● CETS: temporal safety ● Uses disjoint fat pointers ● Proof of correctness (but caveat emptor) ● Implemented as LLVM optimizer pass TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  12. Meet SoftBoundCETS ● Source compatibility ● Complete coverage ● Separate compilation ● Low overhead TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  13. Spatial: instrumenting dereference check(ptr, ptr_base, ptr_bound, sizeof(*ptr)); value = *ptr; TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  14. Spatial: implementation of check void check(ptr, base, bound, size) { if ((ptr < base) || (ptr + size > bound)) { abort(); } } TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  15. „ Beware of bugs in the above code; I have only proved it correct, not tried it. “ – Donald E. Knuth TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  16. Spatial: correct implementation of check void check(ptr, base, bound, size) { if ((ptr < base) || (ptr + size > bound) || (ptr + size < ptr)) { abort(); } } TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  17. Spatial: memory allocation ptr = malloc(size); ptr_base = ptr; ptr_bound = ptr + size; if (ptr == NULL) ptr_bound = NULL; TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  18. Spatial: stack allocation int array[100]; ptr = &array; ptr_base = &array[0]; ptr_bound = ptr_base + sizeof(array); TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  19. Spatial: Pointer arithmetic newptr = ptr + index; // or &ptr[index] newptr_base = ptr_base; newptr_bound = ptr_bound; TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  20. Spatial: narrowing struct { ... int num; ... } *n; ... p = &(n->num); p_base = max(&(n->num), n_base); p_bound = min(p_base + sizeof(n->num), n_bound); TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  21. Spatial: more narrowing struct { ... int arr[5]; ... } *n; ... p = &(n->arr[2]); p_base = max(&(n->arr), n_base); p_bound = min(p_base + sizeof(n->arr), n_bound); TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  22. Spatial: loading metadata int** ptr; int* new_ptr; ... check(ptr, ptr_base, ptr_bound,sizeof(*ptr)); newptr = *ptr; newptr_base = table_lookup(ptr)->base; newptr_bound = table_lookup(ptr)->bound; TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  23. Spatial: storing metadata int** ptr; int* new_ptr; ... check(ptr, ptr_base, ptr_bound, sizeof(*ptr)); (*ptr) = new_ptr; table_lookup(ptr)->base = newptr_base; table_lookup(ptr)->bound = newptr_bound; ● TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  24. Spatial: augmenting function calls int func(char* s) { ... } int value = func(ptr); int func(char* s,void* s_base,void* s_bound) { ... } int value = func(ptr, ptr_base, ptr_bound); TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  25. Spatial: loose ends ● Global variables ● Separate compilation and library code ● Memcpy() ● Function pointers ● Creating pointers from integers ● Arbitrary casts and unions ● Variable argument functions TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  26. Temporal: allocation ptr = malloc(size); ptr_key = next_key++; ptr_lock_addr = allocate_lock(); *(ptr_lock_addr) = ptr_key; freeable_ptrs_map.insert(ptr_key, ptr); ● TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  27. Temporal: dereference check if (ptr_key != *ptr_lock_addr) { abort(); } value = *ptr; TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  28. Temporal: pointer arithmetic newptr = ptr + offset; // or &ptr[index] newptr_key = ptr_key; newptr_lock_addr = ptr_lock_addr; TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  29. Temporal: free if (freeable_ptrs_map.lookup(ptr_key) != ptr) { abort(); } freeable_ptrs_map.remove(ptr_key); free(ptr); *(ptr_lock_addr) = INVALID_KEY; deallocate_lock(ptr_lock_addr); TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  30. Temporal: propagating metadata int** ptr; int* newptr; if (ptr_key != *ptr_lock_addr) { abort(); } newptr = *ptr; newptr_key = table_lookup(ptr)->key; newptr_lock_addr = table_lookup(ptr)->lock_addr; TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  31. Temporal: propagating metadata int** ptr; int* newptr; if (ptr_key != *ptr_lock_addr) { abort(); } (*ptr) = newptr; table_lookup(ptr)->key = newptr_key; table_lookup(ptr)->lock_addr = newptr_lock_addr; TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  32. Temporal: globals int var; // global variable ptr = &var; ptr_key = GLOBAL_KEY; ptr_lock_addr = GLOBAL_LOCK_ADDR; TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  33. Temporal: loose ends ● Threads. Shared state is evil. Zalgo, etc. ● Shared memory. Shared state... see above. TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  34. Own contribution ● Introduced two function attributes to control instrumentation process ● Ported SoftBoundCETS to FreeBSD ● Instrumented FreeBSD libc and executable startup code ● Deleted ton of now useless wrappers ● Goal: build all of FreeBSD world with safe memory access ● Status: PoC works! TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  35. Demo Time! ● Everybody loves a good demo! ● Sufficiently advanced technology is indistinguishable from a propery rigged demo. TOP SECRET//HCS/SI/TK//ORCON/NOFORN

  36. Thanks and references ● SoftBoundCETS: http://www.cs.rutgers.edu/~santosh.nagarakatte/softbound/ ● SoftBoundCETS on FreeBSD: https://github.com/andreas23/freebsd/tree/softbounds ● Many thanks to Hannes Mehnert for joint work on FreeBSD port ● Many thanks to Santosh Nagarakatte, Milo M. K. Martin, Steve Zdancewic for answering questions and providing access to beta versions of code TOP SECRET//HCS/SI/TK//ORCON/NOFORN

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