Frama-C for Code Security

Frama-C for Code Security

Frama-C for Code Security Julien Signoles Software Safety & Security Lab Cyber in Saclay February 11, 2021 Outline 1. Frama-C at a Glance 2. Deductive Verification with ACSL andWP 3. Value Analysis with Eva 4. Runtime Verification with E-ACSL 5. Combining Analyses for Security-Oriented Verifications Part I Frama-C at a Glance Frama-C Distribution Framework for analyses of source code written in ISO 99C [Kirchner et al, 2015] I developed by CEA LIST since 2005 I almost open source (LGPL 2.1) I first open-source release aka Hydrogen in 2008 I last open-source release aka 22-Titanium in November 2020 http://frama-c.com I also proprietary extensions and distributions I targets both academic and industrial usages I plug-ins connected to a kernel I provides an uniform setting (command lines, AST, etc) I provides general services (data structures, etc) I synthesizes useful information (proved properties, etc) I analyzer combinations [Correnson & Signoles, 2012] Frama-C, a Collection of Tools Several tools inside a single platform I plug-in architecture `ala Eclipse [Signoles, 2015] I tools provided as plug-ins I 31 plug-ins in the latest open source distribution I outside open source plug-ins I close source plug-ins, either at CEA( > 20) or outside Frama-C, a Collection of Tools Several tools inside a single platform I plug-in architecture `ala Eclipse [Signoles, 2015] I tools provided as plug-ins I 31 plug-ins in the latest open source distribution I outside open source plug-ins I close source plug-ins, either at CEA( > 20) or outside I plug-ins connected to a kernel I provides an uniform setting (command lines, AST, etc) I provides general services (data structures, etc) I synthesizes useful information (proved properties, etc) I analyzer combinations [Correnson & Signoles, 2012] Frama-C Plug-ins Gallery CaFE E-ACSL PathCrawler Mthread Eva Dedicated LTest SecureFlow Cfp Wp verification MetACSL Synthesis Variadic Before Conc2Seq Pilat Volatile support Rte Plug-ins Counter-Examples After Impact expressiveness Rpp StaDy Scope Aora¨ı From & InOut Clang Report JCard simplification Occurrence understanding Callgraph & Users Sparecode Constfold Metrics Slicing SecuritySlicing Nonterm distributed plug-in external plug-in close source plug-in I powerful low-cost analyser I dedicated plug-in for specific task (coding rules verifier) I dedicated plug-in for fine-grain parameterization I extension of existing analysers Frama-C, a Development Platform I developed in OCaml I was based on Cil [Necula et al, 2002] I library dedicated to analysis of C code development of plug-ins by third party Frama-C, a Development Platform I developed in OCaml I was based on Cil [Necula et al, 2002] I library dedicated to analysis of C code development of plug-ins by third party I powerful low-cost analyser I dedicated plug-in for specific task (coding rules verifier) I dedicated plug-in for fine-grain parameterization I extension of existing analysers Part II Proof of Formal Specifications with ACSL and WP I safety properties: ensure that the program does not fail I no undefined behaviors (w.r.t. ISO C99) I no division by zero, I no arithmetic overflow, I all memory accesses are valid, ... I if invalid, most of them lead to security vulnerabilities I termination I does my program terminate (when expected)? Deductive Verification in a Nutshell Objectives Rigorous, mathematical proof of program semantic properties I functional properties I does a function correctly implement its specification? I termination I does my program terminate (when expected)? Deductive Verification in a Nutshell Objectives Rigorous, mathematical proof of program semantic properties I functional properties I does a function correctly implement its specification? I safety properties: ensure that the program does not fail I no undefined behaviors (w.r.t. ISO C99) I no division by zero, I no arithmetic overflow, I all memory accesses are valid, ... I if invalid, most of them lead to security vulnerabilities Deductive Verification in a Nutshell Objectives Rigorous, mathematical proof of program semantic properties I functional properties I does a function correctly implement its specification? I safety properties: ensure that the program does not fail I no undefined behaviors (w.r.t. ISO C99) I no division by zero, I no arithmetic overflow, I all memory accesses are valid, ... I if invalid, most of them lead to security vulnerabilities I termination I does my program terminate (when expected)? Deductive Verification in a Nutshell Input/Output I based on weakest precondition calculus [Dijkstra, 1975] I Modular reasoning I handle each function independently I input: function+ precondition+ postcondition I precondition = what the function assumes on its inputs I postcondition = what is guarantee as function's outputs if the precondition is satisfied I output: does the precondition implies this property? I for each loop, need to write a loop invariant that hold just before entering the loop and at the end of each iteration I for termination, also need to write a loop variant for each loop (e.g., a nonnegative value that decreases at each loop iteration) I generate verification conditions (VC) to be proven I relies on external provers to prove them I automatic provers (Alt-Ergo, Z3, CVC4, ...) I proof assistants (Coq, PVS, Isabelle/HOL...) Deductive Verification in a Nutshell Verification Process deductive verification is NOT an automatic process I backward program analysis to express the postcondition in terms of function's inputs I generate verification conditions (VC) to be proven I relies on external provers to prove them I automatic provers (Alt-Ergo, Z3, CVC4, ...) I proof assistants (Coq, PVS, Isabelle/HOL...) Deductive Verification in a Nutshell Verification Process deductive verification is NOT an automatic process I backward program analysis to express the postcondition in terms of function's inputs I for each loop, need to write a loop invariant that hold just before entering the loop and at the end of each iteration I for termination, also need to write a loop variant for each loop (e.g., a nonnegative value that decreases at each loop iteration) Deductive Verification in a Nutshell Verification Process deductive verification is NOT an automatic process I backward program analysis to express the postcondition in terms of function's inputs I for each loop, need to write a loop invariant that hold just before entering the loop and at the end of each iteration I for termination, also need to write a loop variant for each loop (e.g., a nonnegative value that decreases at each loop iteration) I generate verification conditions (VC) to be proven I relies on external provers to prove them I automatic provers (Alt-Ergo, Z3, CVC4, ...) I proof assistants (Coq, PVS, Isabelle/HOL...) ACSL, a Formal Specification Language for C Specifications need to be formally expressed I formal specification language for ISO C 99 I designed by CEA LIST and Inria Toccata I Frama-C provides a reference implementation I like JML for Java, spec# for C# and Spark2014 for Ada I contract-based language like Eiffel I designed for program proving I based on first order typed polymorphic logic I logical terms include pure C expressions, and also mathematical integers and reals Function Contract Function contracts: I precondition: requires I what is assumed on the inputs (ensured by the callers) I postcondition: ensures I what is guaranteed by the function body (assuming the precondition) I written left-values: assigns I which memory locations may be modified by the function Specific keywords: I nresult: the returned value I nold(x): value of x in the pre-state I nat(x,l): value of x at label l I nnothing (in assigns): no left-value is written Example 1 A First Program Proof I specify and prove the following program /* returns the absolute value of x */ int abs(int x){ if (x >= 0) return x; return -x; } I prove it with Frama-C/WP and, e.g., Alt-Ergo I frama-c -wp file.c I frama-c-gui -wp file.c I also prove the absence of undefined behaviors I frama-c -wp -wp-rte file.c Example 1 A First Program Proof I the following specification is proved :-) #include<limits.h> /*@ requires x > INT_MIN; @ assigns \nothing; @ @ behavior pos: @ assumes x >= 0; @ ensures \result == x; @ @ behavior neg: @ assumesx<0; @ ensures \result == -x; @ @ complete behaviors; @ disjoint behaviors;*/ int my_abs(int x){ if (x >= 0) return x; return -x; } ACSL and Memory Properties I memory properties are important for code security I ACSL provides built-ins memory-related predicates and functions I nvalid(p): whether ∗p have been properly allocated I nvalid read(p): same as nvalid(p) but p is read only (e.g., literal string) I ninitialize(p): whether ∗p is initialized I nseparated(p,q): p and q point to disjoint memory blocks I p p+i nbase addr(p) noffset(p) nblock length(p) I ··· I a memory model is alway a trade-off between expressivity and automation I if very low-level: very expressive but almost no automation I if very high-level: automatic proofs but poorly expressive I makes assumption about the code I Frama-C/WP may handle several memory models, including: I Hoare: automatic proofs but allows no pointers I Typed: good trade-off between automation and expressiveness, yet no heterogeneous casts I Typed+ref: more automatic than Typed, but assumes no aliasing Deductive Verification and Memory Models I Proving memory properties requires a memory model, i.e. \the way that the analysis tool models the storage of the underlying machine on which the code runs" [Xu et al, 2010] I Frama-C/WP may handle several memory models, including: I Hoare: automatic proofs but allows no pointers I Typed: good trade-off between automation and expressiveness, yet no heterogeneous casts I Typed+ref: more automatic than Typed, but assumes no aliasing Deductive Verification and Memory Models I Proving memory properties requires a memory model, i.e.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    95 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us