Static Code Analysis Procedures in the Development Cycle



Similar documents
Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

C++ INTERVIEW QUESTIONS

Secure Software Programming and Vulnerability Analysis

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Towards practical reactive security audit using extended static checkers 1

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Satisfying ASIL Requirements with Parasoft C++test Achieving Functional Safety in the Automotive Industry

Trace-Based and Sample-Based Profiling in Rational Application Developer

Sources: On the Web: Slides will be available on:

The programming language C. sws1 1

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Using Eclipse CDT/PTP for Static Analysis

Oracle Solaris Studio Code Analyzer

Jonathan Worthington Scarborough Linux User Group

Stack Allocation. Run-Time Data Structures. Static Structures

Detecting Critical Defects on the Developer s Desktop

Glossary of Object Oriented Terms

Data Flow Static Code Analysis Best Practices

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Java Interview Questions and Answers

Virtuozzo Virtualization SDK

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

TOOL EVALUATION REPORT: FORTIFY

A Test Suite for Basic CWE Effectiveness. Paul E. Black.

The FDA Forensics Lab, New Tools and Capabilities

Technical paper review. Program visualization and explanation for novice C programmers by Matthew Heinsen Egan and Chris McDonald.

8.5. <summary> Cppcheck addons Using Cppcheck addons Where to find some Cppcheck addons

Static Analysis for Software Verification. Leon Moonen

Keil C51 Cross Compiler

Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP

How To Trace

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

Object Oriented Software Design II

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Linux Kernel. Security Report

The C Programming Language course syllabus associate level

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Developers and the Software Supply Chain. Andy Chou, PhD Chief Technology Officer Coverity, Inc.

Lecture 9. Semantic Analysis Scoping and Symbol Table

Semester Review. CSC 301, Fall 2015

No no-argument constructor. No default constructor found

Chapter 6, The Operating System Machine Level

Testing for Security

Static Analysis. Find the Bug! : Analysis of Software Artifacts. Jonathan Aldrich. disable interrupts. ERROR: returning with interrupts disabled

Tutorial on C Language Programming

Basic Unix/Linux 1. Software Testing Interview Prep

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Pemrograman Dasar. Basic Elements Of Java

Introduction to Automated Testing

Object Oriented Software Design II

Semantic Analysis: Types and Type Checking

Leak Check Version 2.1 for Linux TM

D. Best Practices D.1. Assurance The 5 th A

Chapter 5 Names, Bindings, Type Checking, and Scopes

Crystal Reports.Net 1.1 Patch

Monitoring Java enviroment / applications

Fuzzing in Microsoft and FuzzGuru framework

IBM SDK, Java Technology Edition Version 1. IBM JVM messages IBM

Compiler I: Syntax Analysis Human Thought

Measuring the Effect of Code Complexity on Static Analysis Results

Source Code Review Using Static Analysis Tools

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

The Power of Ten Rules for Developing Safety Critical Code 1. Gerard J. Holzmann NASA/JPL Laboratory for Reliable Software Pasadena, CA 91109

Planning Optimization in AX2012

Persist It Using and Abusing Microsoft s Fix It Patches

Crash Course in Java

Applying Clang Static Analyzer to Linux Kernel

Programming Languages

Threat Modeling/ Security Testing. Tarun Banga, Adobe 1. Agenda

Building Embedded Systems

Helping you avoid stack overflow crashes!

MOVES Batch Mode: Setting up and running groups of related MOVES run specifications. EPA Office of Transportation and Air Quality 11/3/2010

How to Avoid an Attack - Security Testing as Part of Your Software Testing Process

Client-server Sockets

Real World Software Assurance Test Suite: STONESOUP

Eliminate Memory Errors and Improve Program Stability

Lesson 4 Web Service Interface Definition (Part I)

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Data Integrator. Pervasive Software, Inc B Riata Trace Parkway Austin, Texas USA

Open-source Versus Commercial Software: A Quantitative Comparison

3.GETTING STARTED WITH ORACLE8i

ISTQB Certified Tester. Foundation Level. Sample Exam 1

5 Arrays and Pointers

Visualizing Information Flow through C Programs

Using C to Access Data Stored in Program Memory on the TMS320C54x DSP

Web Application Report

Stacks. Linear data structures

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Introduction to Java

Pattern Insight Clone Detection

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Performance rule violations usually result in increased CPU or I/O, time to fix the mistake, and ultimately, a cost to the business unit.

Transcription:

Static Code Analysis Procedures in the Development Cycle Tools, Technology, and Process in Engineering at Microsoft Mooly Beeri Microsoft Haifa R&D Center

Agenda Static code analysis tools PREfix and PREfast Integration into the development cycle Summary Slide #2

A Product s Life Cycle Cost of fixing bugs Plan & Design - no code bugs () Implementation Low cost, just fix the code and check in Stabilize Medium cost, track the bug, develop the right test case, etc. Release High cost, reputation, release a hot fix (patch), documentation, publishing, etc. Slide #3

A Product s Life Cycle cont. Types of tools Build, Source control Bug tracking ( RAID( RAID ) Compilers, Linkers & Debuggers Profiling & Optimization Testing: Coverage, Fault injection, Test case generation, Prioritization, Capture & Replay, Localization Run-time checkers/verifiers Static Analysis this is our focus today. Slide #4

Static analysis tools Analyze code and detect potential defects Advantages: Not limited by test cases Identify location of defect precisely (easy to fix) Applicable early in the development cycle Puts responsibility on developers Issues Up-front investment Usability and noise Scalability Integration into environment Slide #5

Three common questions Do these tools find important defects? Yes, definitely including defects that would cause security bulletins, blue screens, Is every warning emitted by the tools useful? No, definitely We continue to focus on noise, but it won t go away Do these tools find all the defects? No, no, no! Slide #6

PREfix Implemented by MSR PPRC (Microsoft Research, Programmer Productivity Research Center) C/C++ defect detection via static analysis Powerful inter-procedural analysis Incomplete Useful in practice Typically run as part of a centralized build Slide #7

Some Defects PREfix Finds Memory Management Double free Freeing pointer to non-allocated memory (stack, global, etc.) Freeing pointer in middle of memory block Initialization Using uninitialized memory Freeing or dereferencing uninitialized pointer Bounds violations Overrun (reference beyond end) Underflow (reference before start of buffer) Failure to validate buffer size Resource Leakage Leaking Memory/Resource Pointer Management Dereferencing NULL pointer Dereferencing invalid pointer Returns pointer to local Dereferencing or returning pointer to freed memory Illegal State Resource in illegal state Illegal value Divide by zero Writing to constant string Slide #8

High-level architecture Slide #9

PREfix Architecture Source Code Per-function analyses (aka plugins ) Per-exe analyses Defects (SQL or XML) Build Instructions Cross-exe analyses Build info Slide #10

PREfix: Viewing Results Slide #11

HTML User Interface Slide #12

PREfix Simulator Execution control Walks AST parse trees to follow various execution paths Virtual machine (VIM) Tracks symbolic state of virtual computer Auto Modeler Generates behavioral description (model( model) ) of each function from the virtual machine s information Error analysis Simulator Execution Control Auto Modeler Virtual Machine Finds and reports defects based on state of VIM Error Analysis Slide #13

Analysis is not Complete Functions may have huge numbers of paths PREfix only explores N paths per function User-configurable, default is 50 I.e., we give up on completeness Experiments indicate Number of defects grows slowly with more paths E.g., defects for 200 paths = 1.2 * defects for 50 paths defects for 1000 paths = 1.25 * defects for 50 paths Analysis time grows linearly with more paths E.g., time for 1000 paths = 20 * time for 50 paths Slide #14

Analysis is not Sound Approximations for performance, e.g. Loops: traverse 0 or 1 time and then approximate Recursion: explore cycles until we re bored Can t always find a model for a function call E.g., Function pointers, Virtual functions, 3 rd -party libraries Experiments indicate relatively few incorrect messages due to analysis inaccuracies Slide #15

Analysis works well in practice Finds enough real defects to be useful Noise is low enough that people use it Not just an analysis issue; see below Scales well, so works on large code bases Slide #16

Sample defect PREfix message void uwmsrsi4(lpctstr in) { TCHAR buff[100]; _tcsncpy(buff, in, sizeof(buff)); /*... */ } TCHAR is typedef ed as either char or wchar_t, depending on whether UNICODE is defined _tcsncpy expands to either strncpy or wcsncpy Slide #17

Sample defect PREfix message void uwmsrsi4(lpctstr in) { } TCHAR buff[100]; _tcsncpy(buff,in,sizeof(buff)); uwmsrsi4.c(10) : warning 51: using number of bytes instead of number of characters for 'buff used as parameter 1 (dest( dest) ) of call to 'wcsncpy' wcsncpy size of buffer 'buff' is 200 bytes reference is 399 bytes from start of buffer uwmsrsi4.c(9) : stack variable declared here problem occurs when the following condition is true: uwmsrsi4.c(10) : when wcslen wcslen(in) >= 200' during call to 'wcsncpy' wcsncpy' ' here Slide #18

PREfast Lightweight, desktop defect detection Simple intra-procedural analyses Implemented by MSR PPRC + others Windows devs involved in initial design, implementation Office devs contributed significantly, including OACR environment Extensibility allowed contributions from others Key goal: do less, but do it quickly Allow developers to find bugs before check in Extensibility led to very rapid enhancements Ties in with key challenges Initial focus on security defects Used as part of security bug bashes Slide #19

PREfast defect description An XML description of each defect, with Brief description (mandatory; everything else is optional) Additional details Effect of the defect Hypothesis about cause (phrased as question) Severity One or more examples (erroneous and corrected code) Slide #20

Some Defects PREfast Finds Buffer Overrun Array bounds violations HRESULT Abuses of the HRESULT type Precedence Precedence mistakes PREfix-Lite Uninitialized variables NULL pointers Leaks Typos Syntax errors in your code Slide #21

Sample PREfast message pfunc = (LPFN)GetProcAddress GetProcAddress(hModule,","GetCredentials"); if (NULL == pfunc) { rc = GetLastError(); if (ERROR_PROC_NOT_FOUND == rc) { goto Exit; } } rc = (pfunc)(hserver,0,(lpbyte*)&pcred pcred); Slide #22

Sample PREfast message pfunc = (LPFN)GetProcAddress GetProcAddress(hModule,","GetCredentials"); if (NULL == pfunc) { rc = GetLastError(); if (ERROR_PROC_NOT_FOUND == rc) { goto Exit; } } rc = (pfunc)(hserver,0,(lpbyte*)&pcred pcred); exportrrasconfig.cpp(324) : warning 11: Dereferencing NULL pointer pfunc'. problem occurs in function 'CheckServer' Path includes 19 statements on the following lines: 283 284 285 286 287 288 290 291 297 298 300 301 303 304 306 307 317 318 324 Slide #23

Sample PREfast message Slide #24

Noise Noise = messages people don t care about (not just bogus messages) Usually, noise is worse than missing a defect Too much noise => people won t use the tool == missing all the defects Slide #25

Message Prioritization Which messages correspond to defects that will actually be fixed? Rank : a synthetic metric of a message s goodness Better-ranking ranking messages are more likely to identify defects that will actually get fixed Multiple dimensions: Severity of consequences Likelihood that message is correct Comprehensibility of message Slide #26

Noise and history Noise naturally increases over time People fix the real defects A history mechanism avoids these problems Distinguish newly-occuring messages Goal: avoid re-examining examining noise messages Slide #27

Compare and contrast Use Model Analysis Kinds of defects Instant results PREfix Central Build Cross- function, detailed ~ 40 PREfast Desktop Single- function, superficial > 100 Slide #28

Sample usage: Windows organization PREfix: centralized runs Defects filed automatically Roughly monthly from 1/2000-present 30 MLOC 6 days to complete a run Some teams also run PREfix on their own PREfast: run by individual devs/testers Fix before check in Or run against checked-in code Slide #29

Summary Detecting defects earlier in the cycle PREfix: after code is checked in As opposed to during testing or post-release PREfast: before code is checked in Static analysis is becoming pervasive PREfix, PREfast s initial successes mean this is no longer a research technology Overcoming noise is vital Technology is encouraging process change Slide #30

Questions? Slide #31

Slide #32

Slide #33