57 lines · plain
1==================================2Stack Safety Analysis3==================================4 5 6Introduction7============8 9The Stack Safety Analysis determines if stack allocated variables can be10considered 'safe' from memory access bugs.11 12The primary purpose of the analysis is to be used by sanitizers to avoid13unnecessary instrumentation of 'safe' variables. SafeStack is going to be the14first user.15 16'safe' variables can be defined as variables that can not be used out-of-scope17(e.g. use-after-return) or accessed out of bounds. In the future it can be18extended to track other variable properties. E.g. we plan to extend19implementation with a check to make sure that variable is always initialized20before every read to optimize use-of-uninitialized-memory checks.21 22How it works23============24 25The analysis is implemented in two stages:26 27The intra-procedural, or 'local', stage performs a depth-first search inside28functions to collect all uses of each alloca, including loads/stores and uses as29arguments functions. After this stage we know which parts of the alloca are used30by functions itself but we don't know what happens after it is passed as31an argument to another function.32 33The inter-procedural, or 'global', stage, resolves what happens to allocas after34they are passed as function arguments. This stage performs a depth-first search35on function calls inside a single module and propagates allocas usage through36functions calls.37 38When used with ThinLTO, the global stage performs a whole program analysis over39the Module Summary Index.40 41Testing42=======43 44The analysis is covered with lit tests.45 46We expect that users can tolerate false classification of variables as47'unsafe' when in-fact it's 'safe'. This may lead to inefficient code. However, we48can't accept false 'safe' classification which may cause sanitizers to miss actual49bugs in instrumented code. To avoid that we want additional validation tool.50 51AddressSanitizer may help with this validation. We can instrument all variables52as usual but additionally store stack-safe information in the53``ASanStackVariableDescription``. Then if AddressSanitizer detects a bug on54a 'safe' variable we can produce an additional report to let the user know that55probably Stack Safety Analysis failed and we should check for a bug in the56compiler.57