Runtime check of SAFECode.
Function Pointers in SAFECode?
Where does the pool meta-data stored and used?
Can we also store meta-data for all pointers in type-unknown regions?
What is affine transformations? used in Control-C
Memory safety in C language.
Input:
Type inference in DSA: (2005TR1:) DSA attemps to compute type information for every “points-to set” in the program by inferring the intended type based on the uses of pointers to a points-to set object, and not based on the type declarations or cast operations in the program.
(From 2006DinakarPhD) Automatic pool allocation partitions the heap into regions based on a points-to graph. This leads us to the following new insight that is the key to the SAFECode work:
Insight1: pool based check instead of acrossing all memory range2:
Precondition (guarantteed by DSA): unaliasable memory objects are not allocated within the same region.
poolcheck($ph$, A, $o$)
: verifies that address, A
, is contained within the set of memory ranges assigned to pool, $ph$
, and has the correct alignment for the pool’s data type (or for the field at offset $o$ if $o\neq0$)
Insight2: No run-time check needed on initialized pointers in TK; Runtime check needed for arithmetic derived pointers and TU pointers3.
Insight3: Reused TK region will not violate type safety5.
Insight4: Release is safe only when no pointers into that regions6.
Published Papers:
Control-C in 2002CASES 7, 2003 LCTES 8, 2005Embed 9, 2005SAFECodeTR 1, 2005PLDIPool10,
2006ICSE 11, 2006PLDI 12, 2006DinakarPhD 13, 2011Formal 14.
The SAFECode analysis and transformation sources are organized as follows (from manual 15):
lib/ArrayBoundChecks
: This library contains several analysis passes for static array bounds checking.lib/InsertPoolChecks
: This library contains the transform passes for inserting run-time checks and for inserting code to register memory objects within individual pools. It also contains the CompleteChecks pass which
implements the Check Completion Phase.lib/OptimizeChecks
: This library contains several passes for optimizing run-time checks.lib/RewriteOOB
: This library contains passes for implementing Ruwase/Lam pointer rewriting. This code allows SAFECode to tolerate out-of-bounds pointers that are never dereferenced.lib/DebugInstrumentation
: This library implements code that modifies
run-time checks to contain additional debug information (if such debug
information is present in the program). It is used in SAFECode’s debug
tool mode.lib/DanglingPointers
: This library contains a pass that modifies a pro-
gram to perform dangling pointer detection.Control-C (in 2002 CASES1) , a subset of C, but with key restrictions designed to ensure that memory safety of code can be verified entirely by static checking, under certain system assumptions. Restrictions on C T1. Requires strong typing of all functions, variables, assignments, and expressions, using the same types as in C. T2. Disallows casts to or from any pointer type. Casts between other types (e.g., intergers, floating point numbers, and characters) are allowed.
Reference1 Challenge: dangling pointers Proving statically that a general C program (for example) never dereferences a freed pointer (the “dangling pointer” problem) is undecidable. Region-based memory management, however, has been used to guaranttee the safety of pointer-based accesses to region data without garbage collection, but with limitations: 1) manual effort to convert program to use regions; 2) many solutions disallow explicit deallocation. Automatic regions inference algorithms have been developed to solve limitation completely or partially, such as in ML, or Cyclone.
Reference1: Restricted C + Compiler = Safe language benefits with no garbage collection, no runtime checks. Safe definition: define a software entity (module, thread, or a complete program) to be safe if: not out of bound: never reference a memory location outside the data area by or for the entity. no alien code execution: never executes instructions outside the code area created by the compiler and linker within that space.
Reference: B. Steensgaard. Points-to analysis in almost linear time. POPL, 1996.1 Type system B. Steensgaard. Points-to analysis in almost linear time. POPL, 1996. ↩
Q & A How to do encoding? What kind of information has been encoded? How does the type checking work on those encodings? What kinds of safety property can be checked? Program Presentation SAFECode support full C, but here a subset of C is used the simplify the presentation: Figure 2006DinakarPhD1, same as in 2005SAFECodeTR2: This language includes most sources of potential memory errors in the weakly typed C language, including:
Runtime Check in SAFECode All pointers in Type-Unknown pools are checked. All casts from int to pointer are runtime checked to ensure in the right pool. Pointers in TU are all loaded as int1 All pointers derived from array indexing operations need run-time check (2006 PLDI1), regardless of TK or TU. More about array bound checking. All function pointers need runtime check before being used. (2005-SAFECode-TR: function pointer)
Stack Check Reference1 safecode/include/StackSafety.h: This file defines checks for stack safety. struct checkStackSafety : public ModulePass { public : ... virtual bool runOnModule(Module &M); virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<DataLayout>(); AU.addRequired<EQTDDataStructures>(); AU.setPreservesAll(); } private : // // Tracks the DSNodes that have already been analyzed by an invocation of // markReachableAllocas(). // std::set<DSNode *> reachableAllocaNodes; bool markReachableAllocas(DSNode *DSN, bool start=false); bool markReachableAllocasInt(DSNode *DSN, bool start=false); }; } } safecode/lib/StackSafety/CheckStackPointer.
If you could revise
the fundmental principles of
computer system design
to improve security...
... what would you change?