Windows Driver Verification David Lariviere COMS E6832 – Formal Hardware & Software Verification Presentation of Project.

Slides:



Advertisements
Similar presentations
WDM 드라이버의 기본 구조 What is WDM?
Advertisements

Paging: Design Issues. Readings r Silbershatz et al: ,
Chapter 2 How Hardware and Software Work Together.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Virtual Memory Operating System Concepts chapter 9 CS 355
May 7, A Real Problem  What if you wanted to run a program that needs more memory than you have?
Lecture 12 Page 1 CS 111 Online Devices and Device Drivers CS 111 On-Line MS Program Operating Systems Peter Reiher.
Introduction to Plug and Play and Power Management in the Windows Driver Foundation 陳怡碩.
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
1 A Real Problem  What if you wanted to run a program that needs more memory than you have?
A problem has been detected and windows has been shut down to prevent damage to your computer. VIDEO_DRIVER If this is the first time you’ve seen this.
EEE 435 Principles of Operating Systems Principles and Structure of I/O Software (Modern Operating Systems 5.2 & 5.3) 5/22/20151Dr Alain Beaulieu.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Case Study: Windows 2000 Part I Will Richards CPSC 550 Spring 2001.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 12: Managing and Implementing Backups and Disaster Recovery.
1 DOS with Windows 3.1 and 3.11 Operating Environments n Designed to allow applications to have a graphical interface DOS runs in the background as the.
Operating System Organization
Cambodia-India Entrepreneurship Development Centre - : :.... :-:-
Static Analysis And Verification Of Drivers Donn Terry Software Development Engr. Microsoft Corporation Vlad Levin Software Development Engr. Microsoft.
Myrtle Entertainment Network Scanner How to work your way to installing a program via Myrtle Entertainment Network Scanner.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Driver Verifier Advancements In Windows 7 Daniel Mihai Principal Software Design Engineer Windows Engineering Tools.
System Resources INFO1119 (Fall 2012).
Stack Management Each process/thread has two stacks  Kernel stack  User stack Stack pointer changes when exiting/entering the kernel Q: Why is this necessary?
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
How Hardware and Software Work Together
Hands-On Microsoft Windows Server 2008
How Hardware and Software Work Together
Computing and the Web Operating Systems. Overview n What is an Operating System n Booting the Computer n User Interfaces n Files and File Management n.
Guide to Linux Installation and Administration, 2e1 Chapter 2 Planning Your System.
Chapter 14 Part II: Architectural Adaptation BY: AARON MCKAY.
From Quality Control to Quality Assurance…and Beyond Alan Page Microsoft.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Chapter 33 Troubleshooting Windows Errors. STOP Errors  When Microsoft Windows XP encounters a serious problem  And the operating system can't continue.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Operating Systems. Overview What is an Operating System (OS) What is an Operating System (OS) What Operating Systems do. What Operating Systems do. Operating.
Supporting Windows 9x Chapter 12 Key Terms By Bill Ward.
11 INSTALLING AND MANAGING HARDWARE Chapter 6. Chapter 6: Installing and Managing Hardware2 INSTALLING AND MANAGING HARDWARE  Install hardware in a Microsoft.
Processor Architecture
Memory management.
IT1001 – Personal Computer Hardware & System Operations Week5- Installation and configuration of driver software.
Jakob Lichtenberg Software Development Engineer SDV Adam Shapiro Program Manager Donn Terry Software Development Engineer PFD.
CSC 480 Software Engineering Test Planning. Test Cases and Test Plans A test case is an explicit set of instructions designed to detect a particular class.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
Customer and Partner Connections Design and Develop Assess and Certify.
Copyright © 2007 by Curt Hill Interrupts How the system responds.
Efficient Software-Based Fault Isolation Authors: Robert Wahbe Steven Lucco Thomas E. Anderson Susan L. Graham Presenter: Gregory Netland.
Lesson 2 Component Overview Core Hardware Fundamentals.
Myrtle Entertainment System Scanner How to work your way to installing a program via Myrtle Entertainment System Scanner.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
John Samuels October, Why Now?  Vista Problems  New Features  >4GB Memory Support  Experience.
OPERATING SYSTEMS DO YOU REQUIRE AN OPERATING SYSTEM IN YOUR SYSTEM?
Static Analysis And Verification Of Drivers
Memory Management.
Chapter Objectives In this chapter, you will learn:
A Real Problem What if you wanted to run a program that needs more memory than you have? September 11, 2018.
Crash Dump Analysis - Santosh Kumar Singh.
CSE451 I/O Systems and the Full I/O Path Autumn 2002
Operating System Structure
Chapter 9: Virtual-Memory Management
Introduction to writing device drivers for Windows
Page Replacement.
Memory Management Tasks
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
CSE451 Virtual Memory Paging Autumn 2002
Chapter-1 Computer is an advanced electronic device that takes raw data as an input from the user and processes it under the control of a set of instructions.
COMP755 Advanced Operating Systems
Cache writes and examples
Presentation transcript:

Windows Driver Verification David Lariviere COMS E6832 – Formal Hardware & Software Verification Presentation of Project

Presentation Outline Windows Drivers Microsoft Verification Tools Operating Systems 101 Examples: –PortTalk –SDV’s “Fail_driver1” Example –Eightball Conclusions

Microsoft Windows Drivers Can be EXTREMELY confusing. –Many different ways to achieve the same thing. –Constantly changing Many different Libraries have been used over time: –Virtual Device Driver (VxD): Windows 3.x, 95, 98, and ME –Windows NT Driver Model: Windows NT –Windows Driver Model (WDM): Introduced in Windows 98 and Must be either a bus, function, or filter driver. Must support PnP, Power Management, and WMI. –Windows Driver Foundation (WDF): Windows 2000, XP, Server 2003, and Vista Kernel-Mode Driver Framework (KMDF): –Windows 2000, XP, Server 2003, and Vista –used to create drivers that conform to WDM –simplifies common complicated tasks, like PnP and Power Management User-mode Driver Framework (UMDF): –Windows XP and Vista –Used in cases where running within the kernel not necessary.

Basic Driver Model Taken from WDK – “Overview of System Components for Driver Writers”

Overview of Windows Components Taken from WDK: “Overview of Windows Components”

WDM Driver Types Filter Driver: filters requests between other drivers. Function Drivers: control individual device Bus Drivers: Services a bus controller, adapter, or bridge (USB, PCI, etc) Taken from WDK: “Types of WDM Drivers”

WDM Types Example – USB Joystick Taken from WDK: “WDM Driver Layers: An Example”

I/O Request Packets (IRP) Drivers Communicate with IRPs. IRPs are passed through the Driver stack, as multiple drivers process and pass on the driver. Analogy: TCP/IP, where each Router is a driver. Taken from WDK: “Example I/O Request – An Overview”

IRQ Levels (IRQL) Different driver routine execute at different levels (from lowest to highest priority) –PASSIVE_LEVEL: –APC_LEVEL: –DISPATCH_LEVEL: –DIRQL: IRQL indicates which interrupts are turned off, and therefore which functions can be safely called. Example: –A routine the DIRQL (highest priority) will have all interrupts turned off, including page fault interrupts. –Therefore it cannot access any memory that might be paged! Taken from WDK: “Managing Hardware Priorities”

Microsoft Verification Tools It is hopefully now clear that writing drivers can be difficult, let alone writing correct bug-free drivers. Verification tools to the Rescue! –PREfast –Static Driver Verifier –Driver Verifier

The following slides are taken from “Static Analysis and Verification of Drivers” WINHEC 2006 by Donn Terry and Vlad Levin of Microsoft. Property of Microsoft. Used explicitly for Academic purposes…. Please don’t sue me *

Static Analysis – How Does It Work? The tool builds an abstract model of a driver and exhaustively inspects execution along all paths –The abstract model is simpler: it’s reduced... –It’s so much simpler that it’s possible to have it inspected (“simulated”) exhaustively Over-approximation of the driver –The control part remains the same All paths are preserved and treated equally –The data state is over-approximated if argument x is not constrained, assume any value if (x>0) guards the point of interest, keep track of boolean (x>0), but not integer value of x: boolean is simpler than integer –if (x > 0) { IoCompleteRequest (Irp); }

Static Analysis Not a silver bullet Does not replace functional testing Targets violations of a given set of well-defined constraints Principal limitation –It doesn’t know about every possible error –Algorithms are based on source code abstraction and heuristics Which results in both false positives and false negatives It is not a silver bullet… It is a useful tool

Our Static Tools For Drivers PREfast For Drivers (PFD) –Lightweight and fast (runs in minutes) –Easy to use early in development – start early Use on any code that compiles –Limited to a procedure scope –Works on any code, C and C++ –Finds many local violations Static Driver Verifier (SDV) –Extremely deep analysis (runs in hours) –More useful in the later stages of development Requires complete driver Works over the whole driver –Limited to WDM and to C (more planned) –Finds deep bugs

A problem has been detected and Windows has been shut down to prevent Damage to your. Damage to your computer.DRIVER_IRQL_NOT_LESS_OR_EQUAL If this is the first time you've seen this Stop error screen, restart your computer. If this screen appears again, follow these steps: Check to make sure any new hardware or software is properly installed. If this is a new installation, ask your hardware or software Manufacturer for any Windows updates you might need. If problems continue, disable or remove any newly installed hardware or software. Disable BIOS memory options such as caching or shadowing. If you need to use Safe Mode to remove or disable components, restart your computer, press F8 to select Advanced Startup Options, and then select Safe Mode Technical information: *** STOP: 0x (0x , ,0x ,0x ) Driver Tools Relationship Easy Reproducibility Hard Easy Reproducibility Hard Depth Driver Verifier Static Driver Verifier PREfast for drivers Hard Ease Of Use Complex

SDV: Quality Comprehensive path coverage –Checks all possible paths in a driver –Checks cross procedure calls –Checks a driver together with libraries Finds deep defects that are hard to repro SDV is not perfect –Only one driver (not the entire driver stack) –DDI implementation code is abstracted away –Might run out of time

End of copied slides Seriously, don’t sue.

Operating Systems Modes Modern-day CPUs provide support for operating in different modes. The mode of operation determines what machine instructions and areas of memory can and cannot be accessed. Two main modes: –User: regular software –System (Protected): OS and Drivers

Operating Systems Paging Paging and Virtual Memory: –Increase size of available memory (beyond physical RAM) to programs by storing parts of the memory space on the HD. –Memory is broken up into chunks called pages. –Not all of a program’s pages will necessarily be in memory when the program is running. –Up to Operating System (Kernel) + Hardware (MMU) to implement and handle.

OS 101 – Memory Mapped I/O Memory Mapped I/O: hardware is mapped to memory addresses. Example: Parallel port –LPT1: mapped to 0x3bc  0x3bf –Writing to the destination will actually set the pins on the port high or low. –Reading will provide input from peripherals driving the pins. Using original PCs (including Win9x), user-mode software could access the memory-locations directly, thus controlling the PPs. On NT-based versions of Windows (with protected memory) user-mode programs cannot access the memory values directly. Segway!

Introducing PortTalk An Open-source Windows Driver for accessing the parallel port. Written by Craig Peacock (thank you!) Allows user mode programs (through the PortTalk driver) to control the PP

Case Study – Verifying PortTalk PREfast: –Found 4 Warnings The first always appears, stating it is not actually a warning. The second was a false- positive. The third and fourth were legitimate bugs. SDV: –No SDV rules applied. 

PREfast – False Positive Virtually every driver has the same initial routine in the DriverEntry function: NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { PDEVICE_OBJECT deviceObject; NTSTATUS status; WCHAR NameBuffer[] = L"\\Device\\PortTalk"; WCHAR DOSNameBuffer[] = L"\\DosDevices\\PortTalk"; UNICODE_STRING uniNameString, uniDOSString; … status = IoCreateDevice(DriverObject, 0, &uniNameString, FILE_DEVICE_UNKNOWN, 0, FALSE, &deviceObject); Notice in IoCreateDevice we pass a pointer to deviceObject. This is so that IoCreateDevice can put the object there. PREfast warned it might be a memory leak. In other situations, it is a legitimate concern.

PREfast – Pointer Bugs Within the PortTalk code are some Debug statements: KdPrint( ("PORTTALK: Offset = %d, Value = %d\n",Offset,Value) ); Where offset and value are pointers. PREfast warned that one must not use %d for pointers, since on a 64-bit machine pointers are 64-bits, but %d is explicitly for 32-bit integers. PREfast even gave the correct solution of using %X (specifically for pointers) instead.

SDV - failed_driver1 SDV comes with a few example drivers that are inccorect, including failed_driver1. It contains 6 common mistakes that SDV checks for. –CancelSpinLock –IrpProcessingComplete –IrqlReturn –LowerDriverReturn –NullExFreePool –SpinLock

SDV - CancelSpinLock CancelSpinLock rule requires: –that the driver calls IoAcquireCancelSpinLock before calling IoReleaseCancel –That the driver calls IoReleaseCancelSpinLock before any subsequent calls to IoAcquireCancelSpinLock –The driver must not hold any spin locks when the dispatch routine or cancel routine ends.

SDV - NullExFreePool NullExFreePool prohibits a driver from calling ExFreePool on a NULL pointer.

SDV on Custom Driver As part of project, I am also writing another driver, and verifying it along the way. PREfast has been (usually) quite helpful. SDV…. has not.

DriverEntry Bugs

DriverEntry Bugs Explained The previous code segment violated at least three rules (all intentionally): –SafeStrings –CancelSpinLock –NullExFreePool According to SDV, however: –SafeStrings does not apply. –CancelSpinLock passes –NullExFreePool: fails

Origin of Previous Test Originally, I was trying to debug another portion of the code for safe strings, but SDV was reporting the SafeStrings rule did not apply (meaning no unsafe string functions were being used). Strlen is an unsafe string function. Fearing SDV wasn’t analyzing the specific function within the code, I moved the test into DriverEntry. After it still wasn’t applying, I decided to include a rule taken directly from the failed example driver... But it passed! Fearing SDV still wasn’t actually scanning the code, I added yet another failed example code chunk… it finally failed, meaning SDV was actually processing the code!

Woes of Driver Development My machine after falling victim to a paging bug which neither PREfast nor SDV found.

Conclusions PREfast is great. –Extremely quickly finds many common mistakes. –Sometimes reports false positives on some very common cases. –Offers (sometimes unjustified) peace of mind while writing drivers. SDV… –Supposedly very good at finding extremely complex bugs with extremely difficult paths. –Showed difficulty finding some very simple bugs. –Might be buggy…