1 Model Checking One Million Lines of C Code Hao Chen Drew Dean (SRI International) David Wagner with David Schultz, Geoff Morrison, Ben Schwarz Jacob.

Slides:



Advertisements
Similar presentations
Static Analysis for Security
Advertisements

Target Code Generation
Cygwin Linux for Windows Desktop Paul Stuyvesant.
Assembly Code Verification Using Model Checking Hao XIAO Singapore University of Technology and Design.
January 13, Csci 2111: Data and File Structures Week1, Lecture 2 Basic File Processing Operations.
Using Programmer-Written Compiler Extensions to Catch Security Holes Authors: Ken Ashcraft and Dawson Engler Presented by : Hong Chen CS590F 2/7/2007.
SE 450 Software Processes & Product Metrics Reliability: An Introduction.
1 Property 3: standard file descriptors vulnerability attack.c at.c Standard File Descriptors 0:stdin 1:stdout 2:stderr close(1); close(2); execl(“at”,
MOPS MOdelchecking Security Properties David Wagner U.C. Berkeley.
Building Secure Software Chapter 9 Race Conditions.
#1 Pushdown model checking for security David Wagner U.C. Berkeley Work by Hao Chen, Ben Schwarz, and Drew Dean, Jeremy Lin, Geoff Morrison, David Schultz,
Guide To UNIX Using Linux Third Edition
Swami NatarajanJuly 14, 2015 RIT Software Engineering Reliability: Introduction.
CS465 - Unix C Programming (cc/make and configuration control)
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
The Impact of Programming Language Theory on Computer Security Drew Dean Computer Science Laboratory SRI International.
1 Introduction to Parsing Lecture 5. 2 Outline Regular languages revisited Parser overview Context-free grammars (CFG’s) Derivations.
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Introduction to Shell Script Programming
1 Setuid Demystified Hao Chen David Wagner UC Berkeley Drew Dean SRI International.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Proof Carrying Code Zhiwei Lin. Outline Proof-Carrying Code The Design and Implementation of a Certifying Compiler A Proof – Carrying Code Architecture.
CSCE 2013L: Lab 1 Overview  Java Basics The JVM Anatomy of a Java Program  Object-Oriented Programming Overview  Example: Payroll.java JDK Tools and.
CSC-682 Cryptography & Computer Security Sound and Precise Analysis of Web Applications for Injection Vulnerabilities Pompi Rotaru Based on an article.
Cygwin Linux for Windows Desktop Paul Stuyvesant.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Carnegie Mellon University 10/23/2015 Survivability Analysis via Model Checking Oleg Sheyner Jeannette Wing Carnegie Mellon University.
Model Checking an Entire Linux Distribution for Security Violations Work by Benjamin Schwarz, Hao Chen, David Wagner, Geoff Morrison, Jacob West, Jeremy.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
UNIT 13 Separate Compilation.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Overview of Compilers and JikesRVM John.
1 Setuid Demystified Hao Chen David Wagner UC Berkeley Drew Dean SRI International Proceedings of the 11th USENIX Security Symposium San Francisco, California,
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
Multiple File Compilation and linking By Bhumik Sapara.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
Context-free grammars. Roadmap Last time – Regex == DFA – JLex for generating Lexers This time – CFGs, the underlying abstraction for Parsers.
Race conditions and synchronization issues Exploiting UNIX.
Build Tools 1. Building a program for a large project is usually managed by a build tool that controls the various steps involved. These steps may include:
1 Model Checking One Million Lines of C Code Hao Chen, UC Berkeley Drew Dean, SRI International David Wagner, UC Berkeley.
MOPS: an Infrastructure for Examining Security Properties of Software Authors Hao Chen and David Wagner Appears in ACM Conference on Computer and Communications.
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
Chapter 4 Static Analysis. Summary (1) Building a model of the program:  Lexical analysis  Parsing  Abstract syntax  Semantic Analysis  Tracking.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
Revisiting building. Preprocessing + Compiling 2 Creates an object file for each code file (.c ->.o) Each.o file contains code of the functions and structs.
CLHEP Infrastructure Improvements CHEP 2004 Lynn Garren, FNAL and Andreas Pfeiffer, CERN.
Tuque Automated Software Distribution System By Erick Engelke.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Chapter 1 Introduction.
Introduction to Compiler Construction
C Programming.
Introduction to programming
Research in Language-Based Methods
Chapter 1 Introduction.
CS1010 Programming Methodology
CS1010 Programming Methodology
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
C Programming.
Verification of Software Security Properties
Appendix F C Programming Environment on UNIX Systems
C Programming.
MOPS: an Infrastructure for Examining Security Properties of Software
Functions, Procedures, and Abstraction
Race Condition Vulnerability
Presentation transcript:

1 Model Checking One Million Lines of C Code Hao Chen Drew Dean (SRI International) David Wagner with David Schultz, Geoff Morrison, Ben Schwarz Jacob West, Jeremy Lin

2 Outline Overview of MOPS Engineering efforts Make MOPS work on lots of real world applications Experience Security properties and findings

3 MOPS (MOdel checking Programs for Security properties) A static analysis tool that checks source programs for temporal safety properties Main features –Pushdown model checking –Inter-procedural analysis –Control flow centric

4 Algorithm: Pushdown Model Checking  : set of security operations –e.g.  = { seteuid(!0), seteuid(0), execl() } B  *: sequences of security operations that violate the property –B is a regular language –The user describes B by an FSA T  *: sequences of security operations from feasible traces in the program –T is a context-free language –MOPS automatically builds T from the program Question: Is B  T =  ? T B

5 The MOPS Process Parser Model Checker Program Safety Property CFG FSA Program OK Error Traces (they may violate the property) FSA: Finite State Automaton CFG: Control Flow Graph

6 Integrate MOPS into the Build Process Goal: build a CFG for each target executable in the source package Low-level programs –mops_cc1: parse each foo.c into foo.cfg –mops_ld: link all *.cfg together How to use these programs to build CFGs for each package conveniently?

7 First Attempt: Edit Makefile Feasible for packages with simple Makefiles –OpenSSH Problems –Some Makefiles are automatically generated – they will be overwritten when the package is rebuilt –Too many Makefiles to edit – some packages generate one Makefile in each sub-directory –Some Makefiles are very complicated

8 Second Attempt: Interpose on the Build Process to Generate CFGs Set the env variable GCC_EXEC_PREFIX to let gcc use –mops_cc1 for cc1 –mops_ld for ld Therefore –Each source file foo.c is parsed into a CFG file foo.o –Each executable file a.out contains a linked CFG –Note that machine code is not generated

9 Second Attempt: Advantages and Problems Advantage: works even if the build process –Moves files into other directories (mv) –Renames files (mv) –Creates libraries (ar) Problem –Sometimes machine code is needed By autoconf to test the functionality of the compiler By the build process to generate C header files –But we let gcc create CFGs instead of machine code

10 Third Attempt Build Both Machine Code and CFGs Solution –Build both machine code and CFGs. For each foo.c, build both foo.o and foo.cfg Problem –Machine code and its corresponding CFG may be separated if the build process Moves and renames files (mv) Creates and uses libraries (ar) –We need to “bind” machine code with its CFG

11 Final Attempt Place both machine code and its CFG in the same object file –The ELF object format allows user-defined sections –For each source file foo.c gcc’s cc1 generates machine code foo.o mops_cc1 generates CFG foo.cfg Run objcopy to place foo.cfg into foo.o

12 Now, as Easy as This mops –m property.mfsa -- gcc foo.c bar.c mops –b rpm –m property.mfsa -- rh9/*.src.rpm

13 Experiment: Checking Security Properties on Large Packages Properties –Drop privilege before making unsafe system calls –Avoid race condition in file system access –Create root-jail safely –Create temporary files safely –Avoid stderr vulnerability Programs –7 programs, total one millions LOC

14 Property: Drop Privilege before Executing Untrusted Programs Setuid-root programs need to drop root privilege before executing untrusted programs –exec...(), system(), popen() Otherwise, the untrusted program will run with the root privilege

15 Property: Avoid Race Condition in File System Access It is suspicious to make two system calls in a program path that use the same filename E.g. –access(f) followed by open(f) –stat(f) followed by create(f) Vulnerability –Symbolic links

16 Property: Create root jail securely Rule: chroot() must be followed by chdir() immediately A vulnerable program The adversary sends in../../etc/password from the network // cwd==/var/ftp chroot(“/var/ftp/pub”); filename = read_from_network(); fd = open(filename, O_RDONLY);

17 Property: Avoid Race Condition in Creating Temporary Files victim.c: filename = mktemp(template); fd = open(filename, …); But an adversary can create a file with the same name between the two statements Then, victim.c will –Open the adversary’s file, or –Fail to create the temporary file (with the O_EXCL flag)

18 Rules for Avoiding Race Condition in Creating Temporary Files Never use the unsafe functions: mktemp(), tmpnam(), tempname(), tmpfile() Never reuse the parameter f in mkstemp(f) in any other function call, such as stat(), chmod(), etc –Because the same name may refer to a different file (tmpwatch)

19 Property: Avoid stderr Vulnerability int main() { // fd 0 and 1 are open, but fd 2 is closed … f = open(“/etc/passwd”, O_RDWR); // now /etc/passwd is opened to fd 2 fprintf(stderr, “%s”, user_input); // oops, have written to /etc/passwd }

20 Rule: Avoid stderr Vulnerability Property –The first three file descriptors should not be opened by any file except /dev/null and /dev/zero

21 Property: stderr vulnerability PackageLOCRunning Time # Error Traces Real BugsTotal Sendmail221K13m32s02 Postfix97K58.2s02 OpenSSH58K3m1s37 Apache240K53.0s22 BIND280K3m13s11 At5.1K7.7s22 Cron3.7K5.0s22

22 Property: create temporary files safely PackageLOCRunning Time # Error Traces Real BugsTotal Sendmail221K43.9s00 Postfix97K28.8s00 OpenSSH58K49.0s01 Apache240K47.4s11 BIND280K67.3s11 At5.1K5.3s00 Cron3.7K4.4s00

23 Experiment: Build CFGs for All RPM Packages in Redhat 9.0 Linux Number of packages: 840 Time: 3 days 14 hours on 1.5G Pentium Preliminary results: –Successful: 514 packages –Failed: 326 packages Reasons for failure –Lack of prerequisite RPM packages (the major reason) –Bugs/limitations in MOPS’s parser –The package was not written in C

24 Summary Engineering efforts in making MOPS work on lots of real world applications Experience in checking security properties on large applications