Faults inside System Software

Post on 20-May-2015

1.209 views 0 download

description

(1) Analysis of Large-scale system software (2) Diagnose faults inside system software, especially for device drivers (2) Deal with faulty device driver implementation

Transcript of Faults inside System Software

Faults inside System Software

Jim Huang ( 黃敬群 ) <jserv@0xlab.org>June 6, 2013 / NCU, Taiwan

Rights to copy

Attribution – ShareAlike 3.0You are free

to copy, distribute, display, and perform the workto make derivative worksto make commercial use of the work

Under the following conditionsAttribution. You must give the original author credit.Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one.

For any reuse or distribution, you must make clear to others the license terms of this work.Any of these conditions can be waived if you get permission from the copyright holder.

Your fair use and other rights are in no way affected by the above.License text: http://creativecommons.org/licenses/by-sa/3.0/legalcode

© Copyright 2013 0xlabhttp://0xlab.org/

Corrections, suggestions, contributions and translations are welcome!

Latest update: June 8, 2013

Goals of This Presentation

• Analysis of Large-scale system software• Diagnose faults inside system software, especially for

device drivers• Deal with faulty device driver implementation

Agenda

• General Analysis about Faulty system software• Approaches to Deal

– Runtime Isolation

– Static Analysis

General Analysis about Faulty System Software

Some statistics

• Drivers cause 85% of Windows XP crashes.– Michael M. Swift, Brian N. Bershad, Henry M. Levy:

“Improving the Reliability of Commodity Operating Systems”, SOSP 2003

• Error rate in Linux drivers is 3x (maximum: 10x) higher than for the rest of the kernel– Life expectancy of a bug in the Linux kernel (~2.4):

1.8 years

– Andy Chou, Junfeng Yang, Benjamin Chelf, Seth Hallem, Dawson R. Engler: “An Empirical Study of Operating System Errors”, SOSP 2001

• Causes for driver bugs– 23% programming error

– 38% mismatch regarding device specification

– 39% OS-driver-interface misconceptions

– Leonid Ryzhyk, Peter Chubb, Ihor Kuz and Gernot Heiser: “Dingo: Taming device drivers”, EuroSys 2009

Some statistics

• [Aug 8, 2008] Bug report: e1000 PCI-X network cards rendered broken by Linux 2.6.27-rc– overwritten NVRAM on card

• [Oct 1, 2008] Intel releases quickfix– map NVRAM somewhere else

• [Oct 15, 2008] Reason found:– dynamic ftrace framework tries to patch __init code, but .init

sections are unmapped after running init code

– NVRAM got mapped to same location

– scary cmpxchg() behavior on I/O memory

• [Nov 2, 2008] dynamic ftrace reworked for Linux2.6.28-rc3

Anecdote: Linux e1000 NVRAM bug

FTrace & NIC driver!

Linux Device Driver bugs[Dingo: Taming device drivers, 2009]

• consists of– 7702 features

– 893 Kconfig files

– 31281 source files

– 88897 #ifdef blocks

Linux version 3.0

Even worse...

• Devices connected by buses (USB, PCI, PCIx)• Host chipset (DMA logic, IRQ controller) connects

buses and CPU

System Layout

Example: Intel 925x chipset

• Problem: more and more devices– need means of dynamic device discovery

• Probing– try out every driver to see if it works

• Plug-n-Play– first try of dynamic system description

– device manufacturers provide unique IDs

• PCI: dedicated config space• ACPI: system description without relying on underlying

bus/chipset

Bus & Devices

• Intel, 1996• Tree of devices

– root = Host Controller (UHCI, OHCI, EHCI)

– Device drivers use Host Controller (HC) to communicate with their device via USB Request Blocks (URBs)

– USB is a serial bus

• HC serializes URBs

• Wide range of device classes (input, storage, peripherals, ...)– classes allow generic drivers

Bus: USB

• BlackHat 2013– MACTANS: INJECTING MALWARE INTO IOS DEVICES

VIA MALICIOUS CHARGERS

– http://www.blackhat.com/us-13/briefings.html#Lau

• "we demonstrate how an iOS device can be compromised within one minute of being plugged into a malicious charger. We first examine Apple’s existing security mechanisms to protect against arbitrary software installation, then describe how USB capabilities can be leveraged to bypass these defense mechanisms."

Attack iOS through USB charger!

Device Driver Model

Bugs in Linux Device Driver

Bugs in Linux Device Driver

Device protocol violation examples:✗Issuing a command to uninitialized device✗Writing an invalid register value✗Incorrectly managing DMA descriptors

Linux Device Driver Bug Portion

Bugs in Linux Device Driver

Mellanox Infinihost controller Driver

if(cur_state==IB_RESET && new_state==IB_RESET){ return 0;}

Linux Device Driver Bug Portion

Concurrency errors

• Markus Peloquin, Lena Olson, Andrew Coonce, University of Wisconsin–Madison, “Simultaneity Safari: A Study of Concurrency Bugs in Device Drivers" (2009)

• Types of Device Driver Bugs

Further study about concurrency bugs

Linux Device Driver Bug Portion

Approaches

General methods

Approaches: Runtime Isolation

SUD-UML[Tolerating Malicious Device Drivers in Linux, MIT CSAIL]

• In user-space, there is an unmodified Ethernet device driver running on top of SUD -UML.

• A separate driver process runs for each device driver. Shown in kernel-space are two SUD kernel modules, an Ethernet proxy driver (used by all Ethernet device drivers in SUD), and a safe PCI device access module (used by all PCI card drivers in SUD).

• Microkernel (MINIX/L4) / Hybrid kernel (XNU/DragonFly BSD) style

• Isolate components– device drivers (disk, network, graphic, …)

– stacks (TCP/IP, file systems, ...)

• Separate address spaces each– More robust components

• Problems– Overhead

• hardware multiplexing• context switches

– Need to handle I/O privileges

User-level Drivers

• LeVasseur et. al.: "Unmodified Device Driver Reuse and Improved System Dependability via Virtual Machines”, OSDI 2004

• provide a Linux environment to run drivers on L4 microkernel– Device Driver Environment (DDE)

Device Driver OS: Virtualization technique

Approaches: Static Analysis

• Coccinelle: Faults in Linux: Ten Years Later (ASPLOS 2011)

• Dingo: Taming Device Drivers (EuroSys 2009)• KLEE: Automatic generation of high-coverage tests

(EuroSys 2008)• RWset: Attacking path explosion (TACAS 2008)• EXE: Automatically generating inputs of death (CCS

2006)

Static Analysis

Static Analysis: Instrumentation

C Program Translator

InstrumentedC Program Compile &

Execute

Halt: MemorySafety Violation

Success

• Facts– 50% of software errors are due to pointers

– 50% of security errors due to buffer overruns

• Run-time bookkeeping for memory safety– Array bounds information

– Some run-time type information

• C statement “p++”, infer p is not SAFEstruct { int a; int b; } *p1, *p2;int *q = (int *)p1; // this cast is fineint **r = (int **)p2; // this one is not:

// p2 and r must be DYN

• DYNamic Pointer:

Static Analysis: Instrumentation

On use: - null check - bounds check - tag check/update

Can do: - dereference - pointer arithmetic - arbitrary typecasts

DYN DYN int

home ptr

DYN pointer

len

tags

1 1 0

• “static”: no test runs• “C”: full ANSI C + (GNU C)• Examples

int *c = (int *)malloc(sizeof(int)*10);

c[i] = 1; c[i + f()] = 1; c[*k + (*g)()] = 1;

x = c+5; x[1] = 1;

z->a = c; (z->a)[i] = 1;

foo(c+2); int foo(int *d) {… d[i] = 1; …}

Static Analyzer for Detecting Buffer Overrun Errors in C

Static Analyzer: Internals

C files

C’ files

x1 = F1(x1,…,xN)x2 = F2(x1,…,xN)…xN = FN(x1,…,xN)

equation solver

bug identification

Static Analyzer – Example: cdc_acm.c(Linux device driver)

Static Analyzer – Coverity

• Observations:– drivers fail to obey device spec

– developers misunderstand OS interface

– multi-threading is bad

• Drivers run as part of the kernel– Need to deal with concurrent invocations

– Shared state must be maintained

• Synchronization is hard to get right– Race conditions and deadlocks

– 20% of bugs in device drivers

Securing Driver: Dingo[Dingo: Taming device drivers, 2009]

• Tingu: state-chart-based specification of device protocols– Event-based state transition

– Timeouts

– Variables

Securing Driver: Dingo

• Device driver architecture• Single-threaded

– Builtin atomicity

– Not a performance problem for most drivers

• Event-based– Developers implement a Tingu specification

• Can use Tingu specs to generate runtime driver monitors

Securing Driver: Dingo

Deal with concurrency bugs

Event-based Device Driver

• DevIL (OSDI 2000): generate driver from an IDL spec of the device interface“...our vision is that Devil specifications either should be written by device vendors or should be widely available aspublic domain libraries...”

• Termite (SOSP 2009): use device driver spec (VHDL) to generate– Lets vendors generate drivers on their own

• RevNIC (EuroSys 2010):– Obtain I/O trace from existing driver (Windows)

– Analyze driver binary

– Generate Linux driver

Insightful Researches

Conclusion

• Device drivers are hard than expected while quality and stability are considered.

• Security risks exist inside every area of system software. Device driver is the major.

• It is a common technique to introduce virtual buses for isolating device resources.

• Performing static analysis as early as possible when you design the device driver model and adapt legacy implementations upon the revised frameworks.

Reference

• “Dingo: Taming Device Drivers”, Leonid Ryzhyk, Peter Chubb, Ihor Kuz, Gernot Heiser, UNSW/NICTA/Open Kernel Labs (2009)

• "Hardware and Device Drivers", Björn Döbel, TU Dresden (2012)

• "Configuration Coverage in the Analysis of Large-Scale System Software", Reinhard Tartler, Daniel Lohmann, Christian Dietrich, Christoph Egger, Julio Sincero, Friedrich-Alexander University (2011)

• “AIRAC: A Static Analyzer for Detecting All Buffer Overrun Errors in C Programs", Kwangkeun Yi, Seoul National University (2005)

• “CCured: Taming C Pointers”, George Necula, Scott McPeak, Wes Weimer, Berkeley (2002)

http://0xlab.org