one million (loc) and counting: static analysis for errors and vulnerabilities in the linux kernel...

Post on 10-Jun-2015

51 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Talk on "1,000,000 (LOC) and Counting: Static Analysis for Errors and Vulnerabilities in the Linux Kernel Source Code" given at Reliable Software Technologies/Ada-Europe, Porto, Portugal, 5-9 June, 2006 . A preprint of the full paper is available at http://www.academia.edu/1413557/One_million_LOC_and_counting_Static_analysis_for_errors_and_vulnerabilities_in_the_Linux_kernel_source_code . It's published in Springer LNCS 4006, pp 56-70. The URL for Springer's reference is http://link.springer.com/chapter/10.1007%2F11767077_5, and the DOI is 10.1007/11767077_5.

TRANSCRIPT

1,000,000 (LOC) and CountingStatic Analysis for Errors and Vulnerabilities

in the Linux Kernel Source Code

Peter T. Breuer & Simon PickinUniversidad Carlos III de Madrid

Reliable Software Technologies – Ada- Europe 2006

Piet Hein - Grooks

"A needle in a haystack may be difficult to find;

your chance of ever finding one is small.

Especially with haystacks of the ordinary kind, which don' t have any

needles in at all."

Goal Apply

Mathematical Methodsto the source code of the

Linux kernel

Must be

post hoc

capable of application by nonexperts

able to handle 6.5 million lines of rapidly changing C

Sleep under Spinlock Hunt (SluSH)

What is "sleep under spinlock"?

• Sleep - thread scheduled out of CPU

• Spinlock - busy wait for lock

"2+2 = 1"

2 CPUs + 2 threads busy waiting= 1 dead machine

Output from SluSH run

Output summarises liklihoods

Example of bad code

• snd_sb_csp_load() in sb16_csp.c

Another piece of guilty code

• Kernel 2.6.12 sound/oss/sequencer.c midi_outc()

Cox owns up

Other problem classes ...

• Access (read/write) to kfreed memory

• Overflow 4096B of stack

• Spinlock under spinlock

• Call to function that expects non NULL parameters with possibly NULL argument

– Logic is configured, so new tests can be invented

Example of kfree/access

• drivers/scsi/aix7xxx_old.c in kernel 2.6.3

Basic technique

The abstract view

Symbolic Approximation

• Description of statements as logic transformers

– p x.count=x.count+1 p[n- 1/n]

– p ◊ spin_trylock(&x) p[n- 1/n] ◊ 1 | p ◊ 0

• Approximation of programs

– More approximate program, weaker logic for reasoning about it

– More specified, can say more about program

– Choice of approximation is choice of logic

Other aspects of system

Symbolic approximation provides theoryclass of abstract interpretations with ≤

Different perspectives of each approximationTrigger/action system for raising alarms!

Compositional logic NRBGnormal, return, break, goto

Adjusting logic adjusts approximation

NRB - Statement Logic

• Empty statement

– maintains condition p normally (p)

– empty statement cannot return (F)

– empty statement cannot break (F)

Sequence logic - NRB• normal exit: traverse A then B

• return exit: return from A OR traverse A then return from B

• break exit: break from AOR traverse A then break from B

NRB - Forever Loop logic

• break from body is normal exit from while(1)

• relax p until it is invariant

Programmable trigger/action engine

• Three rules handle propagation of call graph and other housekeeping.

– a sleep call while the objective function is positive causes output:

Using the analyser

• Call with the same arguments as given to the gcc compiler

Limitations• Predicates are restricted to unions of n- cubes

– checking if p q NP- complete problem

• State is not followed well enough:

– x = 1; if (x) A else B;● treated correctly - only A is evaluated

– if (x) A else B; if (x) C else D;● generally over- abstracted - A;C | A;D | B;C | B;D

– solution is to push branch hypotheses down((x≠0);A | (x=0);B) ; ((x≠0);C | (x=0);D)

● hypotheses not always calculable● approximate logic of branching = symbolic approximation

Example of symbolic approximation

● Branch hypotheses q0 q

1

● weak logic● q

0 ↔ q

1 ↔ True

● strong logic (exact)● e.g. q

0 ↔ ∃u,v. u2 + v2 = w2

q1 ↔ ∀u,v. u2 + v2 ≠ w2

Implication of predicates is decidable

• Basic evaluation is C U Ci of cubes

– i.e. U Ci covers C

Summary

• A step towards analyses of 100MLOC.

– No expertise needed

– Fast

– Safe

– Copes with massive amounts of code

• Negatives

– (deliberately) not perfect tracking program state● symbolic approximation provides the theory/context

– Needs expert to extend to new problem classes

top related