practical memory safety with
play

Practical Memory Safety with REST KANAD SINHA & SIMHA - PowerPoint PPT Presentation

Practical Memory Safety with REST KANAD SINHA & SIMHA SETHUMADHAVAN COLUMBIA UNIVERSITY Is memory safety relevant? In 2017, 55% of remote-code execution causing bugs in Microsoft due to memory errors Is memory safety relevant? Yes!


  1. Practical Memory Safety with REST KANAD SINHA & SIMHA SETHUMADHAVAN COLUMBIA UNIVERSITY

  2. Is memory safety relevant? In 2017, 55% of remote-code execution causing bugs in Microsoft due to memory errors

  3. Is memory safety relevant? Yes!

  4. Practical memory safety Presenting… Random Embedded Security Tokens or REST Core H/W primitive: Insert known 64B random value ( token ) in program and detect accesses to them.

  5. Practical memory safety Presenting… Random Embedded Security Tokens or REST Core H/W primitive: Insert known 64B random value ( token ) in program and detect accesses to them. char *buf = malloc(BUF_LEN); buf for (i=0; i<out_of_bounds; i++) buf = 0; Other allocs Heap

  6. Practical memory safety Presenting… Random Embedded Security Tokens or REST Core H/W primitive: Insert known 64B random value ( token ) in program and detect accesses to them. Token char *buf = malloc(BUF_LEN); buf for (i=0; i<out_of_bounds; i++) Token buf = 0; Other allocs Heap

  7. Practical memory safety Presenting… Random Embedded Security Tokens or REST Core H/W primitive: Insert known 64B random value ( token ) in program and detect accesses to them. • Trivial hardware implementation • Software framework based on AddressSanitizer • Provides heap safety for legacy binaries

  8. Background: Spatial Memory Safety Xander’s House Yana’s House Zoey’s House

  9. Background: Spatial Memory Safety char *ptr buf = malloc(BUF_LEN); ptr buf … buf ptr buf [in_bounds] = X; … ptr buf [out_of_bounds] = Y;

  10. Background: Spatial Memory Safety char *ptr buf = malloc(BUF_LEN); ptr buf … buf ptr buf [in_bounds] = X; … ptr buf [out_of_bounds] = Y;

  11. Background: Spatial Memory Safety char *ptr buf = malloc(BUF_LEN); ptr buf … buf ptr buf [in_bounds] = X; … ptr buf [out_of_bounds] = Y;

  12. Background: Temporal Memory Safety Xander moves out, Will moves in Xander’s House Yana’s House Zoey’s House

  13. Background: Temporal Memory Safety Xander moves out, Will moves in Will’s House Yana’s House Zoey’s House

  14. Background: Temporal Memory Safety char *ptr buf = malloc(BUF_LEN); ptr buf ptr buf [in_bounds] = X; buf … free(ptr buf ); ptr buf [in_bounds] = Y;

  15. Background: Temporal Memory Safety char *ptr buf = malloc(BUF_LEN); ptr buf ptr buf [in_bounds] = X; … free(ptr buf ); ptr buf [in_bounds] = Y;

  16. Previous H/W Solutions Mainly categorizable into 2 types.

  17. Previous H/W Solutions Mainly categorizable into 2 types. • Whitelisting: Pointer based + Good coverage + Temporal safety (for some) ptr buf - Performance overhead buf - Implementation overhead - Imprecise

  18. Previous H/W Solutions Mainly categorizable into 2 types. • Whitelisting: Pointer based + Good coverage + Temporal safety (for some) ptr - Performance overhead buf - Implementation overhead - Imprecise • Blacklisting: Location based + Fast - Weaker coverage (has false negatives) - Implementation overhead - No temporal protection

  19. Previous H/W Solutions Tag-based buf Buf *ptr buf Metadata is_valid(ptr buf )?

  20. REST : Primitive Overview Content-based blacklisting Token *ptr buf buf Buf is(*ptr buf == token)? Token REST primitive has trivial complexity, overhead

  21. REST : Spatial Memory Safety Xander’s House Yana’s House Zoey’s House

  22. REST : Temporal Memory Safety Will gets new house Yana’s House Zoey’s House

  23. REST Software

  24. Heap Safety Heap • Allocate and bookend region, malloc to program buf 24

  25. Heap Safety Heap • Allocate and bookend region, malloc to program • REST ’ize at free • Do not reallocate region until heap sufficiently consumed 25

  26. Heap Safety Heap • Allocate and bookend region, malloc to Spatial Protection program • REST ’ize at free • Do not reallocate region until heap sufficiently consumed 26

  27. Heap Safety Heap • Allocate and bookend region, malloc to program • REST’ize at free • Do not reallocate region until heap Temporal Protection sufficiently consumed Can be enabled for legacy binaries 27

  28. Stack Safety void foo() { buf char buf[64]; … return; } foo ‘s frame Previous frame 28

  29. Stack Safety void foo() { rz1 char rz1[64]; char buf[64]; buf char rz2[64]; arm(rz1); rz2 arm(rz2); … disarm(rz1); foo ‘s frame disarm(rz2); Previous return; frame } 29

  30. Stack Safety void foo() { rz1 char rz1[64]; char rz1[64]; char buf[64]; char buf[64]; buf char rz2[64]; char rz2[64]; arm(rz1); rz2 arm(rz2); … disarm(rz1); foo ‘s frame disarm(rz2); Previous return; frame } 30

  31. Stack Safety void foo() { rz1 char rz1[64]; char buf[64]; buf char rz2[64]; arm : Set token arm(rz1); rz2 arm rz1; arm(rz2); arm rz2; … disarm(rz1); foo ‘s frame disarm(rz2); Previous return; frame } 31

  32. Stack Safety void foo() { rz1 char rz1[64]; char buf[64]; buf char rz2[64]; arm(rz1); rz2 arm(rz2); … disarm rz1; disarm(rz1); foo ‘s frame disarm : Unset token disarm rz2; disarm(rz2); Previous return; frame } 32

  33. Stack Safety void foo() { rz1 char rz1[64]; char buf[64]; buf char rz2[64]; arm(rz1); rz2 arm(rz2); … disarm(rz1); foo ‘s frame disarm(rz2); Previous return; frame } Requires recompilation with REST plugin 33

  34. REST Hardware

  35. Naïve Design Every store involves an extra load  Complicated and expensive load/store X Memory Token L1-D Value = Core

  36. Cache Modifications Comparator at L1-D mem interface + 1b per L1-D line load/store X Token Bits Memory Token L1-D Value = Core

  37. Cache Miss load/store X Token Bits Memory Token L1-D Value = Core

  38. Cache Hit load/store X Token Bits Memory Token L1-D Value = Core

  39. Cache Eviction Armed outgoing line filled with token value load/store X Token Bits Memory Token L1-D Value = Core

  40. What about the core? TODO: Have to support arms and disarms • 512b writes • Special semantics: can only touch token with disarm LSQ design concerns: • Forwarding would break semantics • 512b data entries • How to match unaligned token access?

  41. Load-Store Queue • Forwarding breaks semantics Add 1b tag • 512b data entries Only update token bit • Detecting unaligned token access Split regular match logic 6 Data = Address Token Match Match CAM bit Logic Address

  42. Load-Store Queue • Forwarding breaks semantics Add 1b tag • 512b data entries Only update token bit • Detecting unaligned token access Split regular match logic 6 REST Violation Data = = Address Token Match Match CAM bit Logic Address

  43. REST Overhead

  44. REST Performance

  45. REST Performance

  46. REST Performance REST primitive overhead near-zero. Software overhead mostly from allocator.

  47. To conclude… REST : Hardware/software mechanism to detect common memory safety errors ◦ Low overhead, low complexity hardware implementation ◦ Heap safety for legacy binaries 22-90% faster than comparable software solution on SPEC CPU Questions?

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