Presentation is loading. Please wait.

Presentation is loading. Please wait.

HardBound: Architectural Support for Spatial Safety of the C Programming Language Joe Devietti *, Colin Blundell, Milo Martin, Steve Zdancewic * University.

Similar presentations


Presentation on theme: "HardBound: Architectural Support for Spatial Safety of the C Programming Language Joe Devietti *, Colin Blundell, Milo Martin, Steve Zdancewic * University."— Presentation transcript:

1 HardBound: Architectural Support for Spatial Safety of the C Programming Language Joe Devietti *, Colin Blundell, Milo Martin, Steve Zdancewic * University of Washington, University of Pennsylvania devietti@cs.washington.edu, {blundell, milom, stevez}@cis.upenn.edu

2 This work licensed under the Creative Commons Attribution-Share Alike 3.0 United States License You are free: to Share to copy, distribute, display, and perform the work to Remix to make derivative works Under the following conditions: Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license. For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to: http://creativecommons.org/licenses/by-sa/3.0/us/ Any of the above conditions can be waived if you get permission from the copyright holder. Apart from the remix rights granted under this license, nothing in this license impairs or restricts the author's moral rights. [ 2 ] HardBound – Joe Devietti – ASPLOS 2008

3 Who cares about spatial safety, anyway? [ 3 ] HardBound – Joe Devietti – ASPLOS 2008 January 14 February 12 February 8 January 16

4 HardBound: Spatial Safety for C Bounded pointer primitive in hardware A new hardware/software contract for pointers Software finds where pointers are created Hardware checks and propagates pointers Inspired by software-only fat pointer proposals Pointers become (pointer, base, bound) triples +Can provide complete spatial safety Changes memory layout Hardware support enables: Unchanged memory layout high compatibility Efficient fat pointer encodings low overheads (5%) [ 4 ] HardBound – Joe Devietti – ASPLOS 2008

5 memory Spatial Violation Example struct BankAccount { char acctID[3]; int balance; } b;... b.balance = 0; char* id = b.acctID; inputID(id);... void inputID(char* p) { while (*p = readchar()) p++; } [ 5 ] HardBound – Joe Devietti – ASPLOS 2008 bal id acctID 123123 9x10 9 0 p p

6 Preventing Spatial Violations [ 6 ] HardBound – Joe Devietti – ASPLOS 2008 write perfect code treat the symptoms address space randomization non-executable stack/heap protect return addresses all incomplete add bounds checking to C use a safe language what about existing code?

7 Software-Only Bounds Checking for C approach can handle sub-objects? compatibility?examples object lookup nohigh Jones & Kelly [1997] CRED [Ruwase & Lam, 2004] JK/RL/DA [Dhurjati & Adve, 2006] fat pointer yeslow SafeC [Austin et al, 1994] Cyclone [Jim et al, 2002] CCured [Necula et al, 2005] [ 7 ] HardBound – Joe Devietti – ASPLOS 2008

8 Code Example with Fat Pointers struct BankAccount { char acctID[3]; int balance; } b;... b.balance = 0; char* id = b.acctID; inputID(id);... void inputID(char* p) { while (*p = readchar()) p++; } [ 8 ] HardBound – Joe Devietti – ASPLOS 2008 acctID 123123 bound id base pointer bal 0 p p pointer base bound

9 standard C layout fat pointer layout struct { int* ptr; int i; } s; ptr i i base bound i ptr CCured +Uses fat pointers only where needed determined by whole-program type inference significantly reduces overhead Curing a program requires programmer help Interfacing with non-cured libraries C nastiness: arbitrary casts, unions, … CCured team: 1% of source code lines changed Spec95, Olden, Ptrdist [ 9 ] HardBound – Joe Devietti – ASPLOS 2008 Curing a program is a non-trivial task

10 HardBound: A New Hope Bounded pointer hardware primitive implemented via shadow memory and registers Compiler identifies where pointers are created examples: malloc, &variable (intraprocedural analysis) using setbound instruction Hardware checks and propagates the pointers +Fat pointer representation hidden by hardware +compatible (memory layout unchanged) +enables optimized metadata encodings [ 10 ] HardBound – Joe Devietti – ASPLOS 2008

11 Rest of Talk How do we make HardBound work? pointer propagation and checking memory layout How do we make HardBound fast? compressing non-pointers compressing pointers [ 11 ] HardBound – Joe Devietti – ASPLOS 2008

12 Metadata Propagation and Checking All registers and memory have metadata Example operations: a dd R1 < R2 + imm R1.value < R2.value + imm R1.base < R2.base R1.bound < R2.bound l oad R1 < Memory[R2] assert(R2.base <= R2.value < R2.bound) R1.value < Memory[R2.value].value R1.base < Memory[R2.value].base R1.bound < Memory[R2.value].bound [ 12 ] HardBound – Joe Devietti – ASPLOS 2008 propagation bounds check propagation insn

13 struct BankAccount { char acctID[3]; int balance; } b;... b.balance = 0; char* id; id = inputID(id);... void inputID(char* p) { while (*p = readchar()) p++; } The HardBound Hardware/Software Approach [ 13 ] HardBound – Joe Devietti – ASPLOS 2008 memory bal id acctID base bound 123123 pointer setbound(b.acctID,3); b.acctID; 0 p p base bound pointer propagation where?

14 HardBound Memory Layout [ 14 ] HardBound – Joe Devietti – ASPLOS 2008 Virtual Memory struct { int* ptr; int i; } s; ptr i i boundbase metadata shadow space regular space (layout unchanged) enables compatibility… …how do we make it fast?

15 Eliminating Metadata for Non-pointers Most data are not pointers add 1-bit tag to act as a filter prevents an expensive base/bound lookup lives in virtual memory 1 bit per word (3% overhead) [ 15 ] HardBound – Joe Devietti – ASPLOS 2008 non-pointer 0 0 pointer base bound 1 1 tag

16 Compressing In-Memory Metadata 1.Many pointers point to the beginning of an object 2.Many pointers point to small objects [ 16 ] HardBound – Joe Devietti – ASPLOS 2008 pointer: 1000 base: 1000 bound: 1003 3 3 tag:1 bound: 1003 used opportunistically on stores External encoding: fold size into tag base: 1000 + + size pointer: 1000

17 Most programs dont use much of virtual memory pointers contain more bits than are really needed base: 1000 Compressing Metadata for Pointers [ 17 ] HardBound – Joe Devietti – ASPLOS 2008 base: 1000 bound: 1003 tag: 1 bound: 1003 Internal encoding: hide offset in pointer + + cmprsd? size pointer: 1000 3 3

18 HardBound Metadata Lookup [ 18 ] HardBound – Joe Devietti – ASPLOS 2008 Processor Core L2$ d$ i$ tag$ TLB Memory

19 Experiments Experimental methodology Source-to-source compiler written in CIL FeS 2 x86 inorder single-cycle processor with Simics Tested correctness with a suite of 291 spatial violations [Kratkiewicz & Lippmann, 2005] 286 are compatible with our simulation environment no false positives, no false negatives [ 19 ] HardBound – Joe Devietti – ASPLOS 2008

20 Performance Experiments Olden pointer-intensive benchmark suite no source code modifications required for correctness we even found a bug in em3d we made two small performance-only modifications bh: manually inlined two functions reduce number of redundant setbound insns mst: manually inserted three setbound insns to tighten bounds for better compression [ 20 ] HardBound – Joe Devietti – ASPLOS 2008

21 Experimental Configurations encodingsize of tag spacetag cache encodes pointers up to external 4-bit4 bits8KB56 B internal 4-bit1 bit2KB56 B internal 11-bit1 bit2KB4 KB [ 21 ] HardBound – Joe Devietti – ASPLOS 2008

22 Normalized Runtime Results [ 22 ] HardBound – Joe Devietti – ASPLOS 2008 bhbisort em3dhealthmst perimpowertreeaddtsp avg 5% average overhead

23 Conclusions HardBound is a hardware/software approach that provides spatial safety for C Hardware-managed pointer metadata enables: high compatibility (doesnt change memory layout) low overhead (enables encoding tricks) Our experiments show that HardBound is: effective (no false positives, no false negatives) efficient (compressing metadata works) Future work further reduce overhead using CCureds static analysis temporal safety (dangling pointers) [ 23 ] HardBound – Joe Devietti – ASPLOS 2008

24


Download ppt "HardBound: Architectural Support for Spatial Safety of the C Programming Language Joe Devietti *, Colin Blundell, Milo Martin, Steve Zdancewic * University."

Similar presentations


Ads by Google