The Zoo of Software Security Techniques

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Copyright W. Howden1 Programming by Contract CSE 111 6/4/2014.
Abstraction of Source Code (from Bandera lectures and talks)
Semantics Static semantics Dynamic semantics attribute grammars
Copyright , Doron Peled and Cesare Tinelli. These notes are based on a set of lecture notes originally developed by Doron Peled at the University.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
50.530: Software Engineering Sun Jun SUTD. Week 10: Invariant Generation.
Finding bugs: Analysis Techniques & Tools Comparison of Program Analysis Techniques CS161 Computer Security Cho, Chia Yuan.
Reasoning About Code; Hoare Logic, continued
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
11111 Functional Program Verification CS 4311 A. M. Stavely, Toward Zero Defect Programming, Addison-Wesley, Y. Cheon and M. Vela, A Tutorial on.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
50.530: Software Engineering Sun Jun SUTD. Week 9: Hoare Logic.
1 University of Toronto Department of Computer Science © 2001, Steve Easterbrook Lecture 10: Formal Verification Formal Methods Basics of Logic first order.
A survey of techniques for precise program slicing Komondoor V. Raghavan Indian Institute of Science, Bangalore.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
Axiomatic Verification I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 17.
Axiomatic Semantics The meaning of a program is defined by a formal system that allows one to deduce true properties of that program. No specific meaning.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
Predicate Transformers
CSE 331 Software Design & Implementation Dan Grossman Winter 2014 Lecture 2 – Reasoning About Code With Logic 1CSE 331 Winter 2014.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLine’s CSE 503, Software Engineering University of Washington 26 Apr 2004.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Software Quality: Testing and Verification II. 2 1.A failure is an unacceptable behaviour exhibited by a system — The frequency of failures measures software.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Describing Syntax and Semantics
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
Type Systems CS Definitions Program analysis Discovering facts about programs. Dynamic analysis Program analysis by using program executions.
Reasoning about programs March CSE 403, Winter 2011, Brun.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
Semantics In Text: Chapter 3.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Software Engineering 2 -Prakash Shrestha.
13 Aug 2013 Program Verification. Proofs about Programs Why make you study logic? Why make you do proofs? Because we want to prove properties of programs.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Dr. Naveed Riaz Design and Analysis of Algorithms 1 1 Formal Methods in Software Engineering Lecture # 26.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2014.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
Verification and Validation
CSE 331 Software Design & Implementation
Formal Methods in Software Engineering 1
Hoare-style program verification
Mathematical Structures for Computer Science Chapter 1
Reasoning About Code; Hoare Logic
Lecture 5 Floyd-Hoare Style Verification
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Predicate Transformers
Functional Program Verification
Formal Methods in software development
Predicate Transforms II
Program correctness Axiomatic semantics
Program Verification with Hoare Logic
CSE 1020:Software Development
Predicate Abstraction
Programming Languages and Compilers (CS 421)
50.530: Software Engineering
Programming Languages 2nd edition Tucker and Noonan
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

The Zoo of Software Security Techniques Computer Security: Techniques and Tactics The Zoo of Software Security Techniques Acknowledgements: CMU 17654: Analysis of Software Artifacts, Jonathan Aldrich CMU 18732: Secure Software Systems, Lujo Baurer Stanford CS357: Techniques for Program Analysis and Verification, David Dill

Software (In)Security This Software is Secure. Prove the correctness. Show an counter-example.

Overview Human Inspection & Testing Program Specification and Verification Hoare Logic Program Verification Static Analysis Dataflow Analysis Model Checking Testing Fuzzing Taint Analysis Symbolic Execution (Defense/Mitigation) Sometimes dynamic analysis is under testing.

Inspection https://www.xkcd.com/371/

Inspection is Actually Powerful Raytheon Reduced "rework" from 41% of cost to 20% of cost Reduced effort to fix integration problems by 80% IBM 1 hour of inspection saved 20 hours of testing Saved 82 hours of rework if defects in released product IBM Santa Teresa Lab 3.5 hours to find bug with inspection HP System use 0.21 defects/hour Black box 0.28 defects/hour White box 0.32 defects/hour Reading/inspect 1.06 defects/hour

Testing Direct execution of code on test data in a controlled environment

Testing Direct execution of code on test data in a controlled environment Heavily used in real life Black-box testing: care about the coverage on input domain White-box testing: care about the coverage on program TODO: Advantage of different metrics Statement/code Coverage Branch Coverage Path Coverage

Program Specification and Verification Overview Human Inspection & Testing Program Specification and Verification Program Verification Hoare Logic Static Analysis Dataflow Analysis Model Checking Testing Fuzzing Taint Analysis Symbolic Execution (Defense/Mitigation) Sometimes dynamic analysis is under testing.

Program Verification Prove that a program S satisfies a property Q. In security specification: Q is a security property. How to prove? Wait a moment, something is wrong

Program Verification S: y = x * x; Q: y > 0; Does S satisfy Q? Depends on x. <---- precondition

(Hoare triples or Hoare notation) Program Verification {P}S{Q} (Hoare triples or Hoare notation) Whenever S is executed in a state satisfying P And if the execution of S terminates The state in which S’s execution terminates satisfies Q P: Precondition Q: Postcondition

Example {X = 1} X:=X+1 {X = 2}, True or False? {X = 1} WHILE T DO X := X {Y = 2}, True or False?

/*@ requires len >= 0 && array.length == len @ ensures \result == @ (\sum int j; 0 <= j && j < len; array[j]) @*/ float sum(int array[], int len) { float sum = 0.0; int i = 0; while (i < len) { sum = sum + array[i]; i = i + 1; } return sum; Notation from the Java Modeling Language (JML) (A representation Language)

Weakest Precondition The most “general” precondition given a S and Q {x = 5 && y = 10} z := x / y { z < 1 } {x < y && y > 0} z := x / y { z < 1 } {y ≠ 0 && x / y < 1} z := x / y { z < 1 } Which one is the weakest precondition? wp(S, Q) y ≠ 0 && x / y < 1 x = 5 && y = 10 x = 5 && y = 10

{P}S{Q} holds if and only if P -> wp(S, Q) Program Verification Prove {P}S{Q} is True {P}S{Q} holds if and only if P -> wp(S, Q) wp(S, Q) P

Now our goal is to find wp(S, Q). Program Verification Prove {P}S{Q} is True {P}S{Q} holds if and only if P -> wp(S, Q) Now our goal is to find wp(S, Q).

Finding wp(S, Q) by Hoare Logic High-level idea: using rules for different statements in S. e.g., Assignment rule wp(x := E, Q) = [E/x] Q [E/x] Q (Substitution Notation): Replacing all occurrences of x in Q by E Exercise: wp(x := 3*y + z, x * y - z > 0 )

Finding wp(S, Q) by Hoare Logic wp(x := 3*y + z, x * y - z > 0 ) = [3 * y + z / x] (x * y - z > 0) = ( 3 * y + z ) * y - z > 0 = 3y2 + yz - z > 0

Using Hoare Logic to Prove Correctness (Security) Requires a lot of work (deduction, or pre-defined precondition) Can be unsound E.g. loop never terminates Finding loop invariant

Overview Dataflow Analysis Human Inspection & Testing Program Specification and Verification Hoare Logic Program Verification Static Analysis Dataflow Analysis Model Checking Testing Fuzzing Taint Analysis Symbolic Execution (Defense/Mitigation) Sometimes dynamic analysis is under testing.

Dataflow Analysis: Motivation Tracking value flow through program Checking whether values satisfy a specific property E.g. Zero analysis: could a variable be 0? Property is a specification of Hoare logic Hoare logic allows any property to be expressed Specialization allows automation and soundness

Example: Zero Analysis y := x; z := 0; if (y > -1) { x := x / y; y := y-1; z := 5; } Could x be 0? Could y be 0? Could z be 0? Hard for program verification

Example: Zero Analysis σ = [ ]  maps variables to an abstract value: Z, NZ, MZ (abstract interpretation) x := 10; y := x; z := 0; if (y > -1) { x := x / y; y := y-1; z := 5; } Could x be 0? Could y be 0? Could z be 0? Hard for program verification

Example: Zero Analysis σ = [ ]  maps variable to an abstract value: Z, NZ, MZ x := 10; σ = [x -> 10] y := x; z := 0; if (y > -1) { x := x / y; y := y-1; z := 5; } Could x be 0? Could y be 0? Could z be 0? Hard for program verification

Example: Zero Analysis σ = [ ]  maps variable to an abstract value: Z, NZ, MZ x := 10; σ = [x -> NZ] y := x; z := 0; if (y > -1) { x := x / y; y := y-1; z := 5; } Could x be 0? Could y be 0? Could z be 0? Hard for program verification

Example: Zero Analysis σ = [ ]  maps variable to an abstract value: Z, NZ, MZ x := 10; σ = [x -> NZ] y := x; σ = [x -> NZ, y -> NZ] z := 0; σ = [x -> NZ, y -> NZ, z -> Z] if (y > -1) { σ = [x -> NZ, y -> NZ, z -> Z] x := x / y; y := y-1; z := 5; } σ = [x -> NZ, y -> NZ, z -> Z] Could x be 0? Could y be 0? Could z be 0? Hard for program verification

Example: Zero Analysis σ = [ ]  maps variable to an abstract value: Z, NZ, MZ x := 10; σ = [x -> NZ] y := x; σ = [x -> NZ, y -> NZ] z := 0; σ = [x -> NZ, y -> NZ, z -> Z] if (y > -1) { σ = [x -> NZ, y -> NZ, z -> Z] x := x / y; σ = [x -> NZ, y -> NZ, z -> Z] y := y-1; z := 5; } σ = [x -> NZ, y -> NZ, z -> Z] Could x be 0? Could y be 0? Could z be 0? Hard for program verification

Example: Zero Analysis σ = [ ]  maps variable to an abstract value: Z, NZ, MZ x := 10; σ = [x -> NZ] y := x; σ = [x -> NZ, y -> NZ] z := 0; σ = [x -> NZ, y -> NZ, z -> Z] if (y > -1) { σ = [x -> NZ, y -> NZ, z -> Z] x := x / y; σ = [x -> NZ, y -> NZ, z -> Z] y := y-1; σ = [x -> NZ, y -> MZ, z -> Z] z := 5; } σ = [x -> NZ, y -> NZ, z -> Z] Could x be 0? Could y be 0? Could z be 0? Hard for program verification

Example: Zero Analysis σ = [ ]  maps variable to an abstract value: Z, NZ, MZ x := 10; σ = [x -> NZ] y := x; σ = [x -> NZ, y -> NZ] z := 0; σ = [x -> NZ, y -> NZ, z -> Z] if (y > -1) { σ = [x -> NZ, y -> NZ, z -> Z] x := x / y; σ = [x -> NZ, y -> NZ, z -> Z] y := y-1; σ = [x -> NZ, y -> MZ, z -> Z] z := 5; σ = [x -> NZ, y -> MZ, z -> NZ] } σ = [x -> NZ, y -> NZ, z -> Z] Could x be 0? Could y be 0? Could z be 0? Hard for program verification

Example: Zero Analysis σ = [ ]  maps variable to an abstract value: Z, NZ, MZ x := 10; σ = [x -> NZ] y := x; σ = [x -> NZ, y -> NZ] z := 0; σ = [x -> NZ, y -> NZ, z -> Z] if (y > -1) { σ = [x -> NZ, y -> NZ, z -> Z] x := x / y; σ = [x -> NZ, y -> NZ, z -> Z] y := y-1; σ = [x -> NZ, y -> MZ, z -> Z] z := 5; σ = [x -> NZ, y -> MZ, z -> NZ] } σ = [x -> NZ, y -> MZ, z -> MZ] Could x be 0? Could y be 0? Could z be 0? Hard for program verification

Model Checking x=0, y=0, z=0,… x := 10; y := x; z := 0; x := 10; if (y > -1) { x := x / y; y := y-1; z := 5; } x := 10; y := x; z := 0; y > -1 y <= -1 x := x / y; y := y-1; z := 5;

Model Checking x=0, y=0, z=0,… x := 10; y := x; z := 0; [x -> NZ, y -> NZ, z -> Z] y > -1 y <= -1 [x -> NZ, y -> NZ, z -> Z] x := x / y; y := y-1; z := 5; [x -> NZ, y -> MZ, z -> MZ] x := x / y; y := y-1; z := 5;

Model Checking Equivalent

Model Checking Current abstract interpretation is insufficient for y and z x=0, y=0, z=0,… x := 10; y := x; z := 0; [x -> NZ, y -> NZ, z -> Z] y > -1 y <= -1 [x -> NZ, y -> NZ, z -> Z] x := x / y; y := y-1; z := 5; [x -> NZ, y -> MZ, z -> MZ] x := x / y; y := y-1; z := 5;

Predicate Abstraction x := 10; y := x; z := 0; x := 10; y := x; z := 0; if (y > -1) { x := x / y; y := y-1; z := 5; } assert(y == 0) if y > -1 Yes x := x / y; y := y-1; z := 5; No assert y == 0

Predicate Abstraction x := 10; y := x; z := 0; if y > -1 Yes No x := x / y; y := y-1; z := 5; assert y == 0 y == 0 y != 0

Predicate Abstraction – Adding Transaction x := 10; y := x; z := 0; if y > -1 ? Yes No x := x / y; y := y-1; z := 5; y <= -1 assert y == 0 y == 0 y != 0

Predicate Abstraction – Adding Transaction x := 10; y := x; z := 0; if y > -1 Yes No x := x / y; y := y-1; z := 5; assert y == 0 y == 0 y != 0

Predicate Abstraction – Find Counterexample y := x; z := 0; if y > -1 Yes No x := x / y; y := y-1; z := 5; assert y == 0 y == 0 y != 0

Predicate Abstraction – Validate Counterexample y := x; z := 0; x := 10; y := x; z := 0; if y > -1 Yes No y <= -1 x := x / y; y := y-1; z := 5; assert y == 0 y != 0

Predicate Abstraction – Refinement P : y == 0 Q : y <= -1 Predicate Abstraction – Refinement x := 10; y := x; z := 0; if y > -1 Yes No x := x / y; y := y-1; z := 5; assert y == 0 P && Q ¬ P && Q P && ¬Q ¬P && ¬Q

Predicate Abstraction – Second Iteration P : y == 0 Q : y <= -1 Predicate Abstraction – Second Iteration x := 10; y := x; z := 0; if y > -1 Yes No x := x / y; y := y-1; z := 5; assert y == 0 ¬ P && Q P && ¬Q ¬P && ¬Q

Predicate Abstraction – Second Iteration P : y == 0 Q : y <= -1 Predicate Abstraction – Second Iteration x := 10; y := x; z := 0; if y > -1 Yes No x := x / y; y := y-1; z := 5; assert y == 0 ¬ P && Q P && ¬Q ¬P && ¬Q

Predicate Abstraction – Second Iteration P : y == 0 Q : y <= -1 Predicate Abstraction – Second Iteration x := 10; y := x; z := 0; Counterexample! if y > -1 Yes No x := x / y; y := y-1; z := 5; assert y == 0 ¬ P && Q P && ¬Q ¬P && ¬Q

What if there is a loop P : y == 0 Q : y <= -1 ¬ P && Q P && ¬Q x := 10; y := x; z := 0; if y > -1 No Yes x := x / y; y := y-1; z := 5; assert y == 0 ¬ P && Q P && ¬Q ¬P && ¬Q

What if there is a loop

Quiz Which of the following will give us a counterexample while checking whether a program satisfies a property? Predicate abstraction Program verification Dataflow analysis All of the above