Lightweight Verification of Array Indexing Martin Kellogg* , - - PowerPoint PPT Presentation

lightweight verification of array indexing
SMART_READER_LITE
LIVE PREVIEW

Lightweight Verification of Array Indexing Martin Kellogg* , - - PowerPoint PPT Presentation

Lightweight Verification of Array Indexing Martin Kellogg* , Vlastimil Dort**, Suzanne Millstein*, Michael D. Ernst* * University of Washington, Seattle ** Charles University, Prague The problem: unsafe array indexing In unsafe


slide-1
SLIDE 1

Lightweight Verification of Array Indexing

Martin Kellogg*, Vlastimil Dort**, Suzanne Millstein*, Michael D. Ernst*

* University of Washington, Seattle ** Charles University, Prague

slide-2
SLIDE 2

The problem: unsafe array indexing

  • In unsafe languages (C): buffer overflow!
  • In managed languages (Java, C#, etc.): exception, program

crashes

2

slide-3
SLIDE 3

The state of the art

3

Strength of guarantees Practical for developers

slide-4
SLIDE 4

The state of the art

4

Strength of guarantees Practical for developers Coq KeY Clousot

slide-5
SLIDE 5

The state of the art

5

Strength of guarantees Practical for developers Coq KeY Clousot FindBugs Coverity

slide-6
SLIDE 6

The state of the art

6

Strength of guarantees Practical for developers Coq KeY Clousot FindBugs Coverity The Index Checker (this talk)

slide-7
SLIDE 7

Problems with complex analyses

  • false positives
  • annotation burden
  • complex analyses are hard to predict

7

slide-8
SLIDE 8

Problems with complex analyses

  • false positives
  • bounds checking is hard → complex analysis
  • complex analysis → harder to implement
  • harder to implement → more false positives
  • annotation burden
  • complex analyses are hard to predict

8

slide-9
SLIDE 9

Problems with complex analyses

  • false positives
  • bounds checking is hard → complex analysis
  • complex analysis → harder to implement
  • harder to implement → more false positives
  • annotation burden
  • complex analysis → complex annotations
  • complex analyses are hard to predict

9

slide-10
SLIDE 10

Problems with complex analyses

  • false positives
  • bounds checking is hard → complex analysis
  • complex analysis → harder to implement
  • harder to implement → more false positives
  • annotation burden
  • complex analysis → complex annotations
  • complex analyses are hard to predict

10

slide-11
SLIDE 11

Fundamental problem is complex analyses! Insight:

11

slide-12
SLIDE 12

Cooperating simple analyses

Solve all three problems:

12

slide-13
SLIDE 13

Cooperating simple analyses

Solve all three problems:

  • simpler implementation → fewer false positives

13

slide-14
SLIDE 14

Cooperating simple analyses

Solve all three problems:

  • simpler implementation → fewer false positives
  • simpler abstractions → easier to write annotations

14

slide-15
SLIDE 15

Cooperating simple analyses

Solve all three problems:

  • simpler implementation → fewer false positives
  • simpler abstractions → easier to write annotations
  • simpler analysis → simpler to predict

15

slide-16
SLIDE 16

Proving an array access safe T[] a = …; int i = …; ... a[i] ...

We need to show that:

  • i is an index for a

16

slide-17
SLIDE 17

Proving an array access safe T[] a = …; int i = …; ... a[i] ...

We need to show that:

  • i is an index for a
  • i ≥ 0
  • i < a.length

17

slide-18
SLIDE 18

Proving an array access safe T[] a = …; int i = …; ... a[i] ...

We need to show that:

  • i is an index for a
  • i ≥ 0

A lower bound on i

  • i < a.length

An upper bound on i

18

slide-19
SLIDE 19

A type system for lower bounds

T ↑ i ≥ -1 ↑ ↑ i ≥ 0 i ≥ 1

@LowerBoundUnknown int i

@GTENegativeOne int i

↑ ↑

@NonNegative int i @Positive int i

19

slide-20
SLIDE 20

A type system for lower bounds

T ↑ i ≥ -1 ↑ ↑ i ≥ 0 i ≥ 1

@LowerBoundUnknown int i

@GTENegativeOne int i

↑ ↑

@NonNegative int i @Positive int i

20

slide-21
SLIDE 21

A type system for upper bounds

if (i >= 0 && i < a.length) { a[i] = ... }

21

slide-22
SLIDE 22

A type system for upper bounds

if (i >= 0 && i < a.length) { a[i] = ... }

22

i < a.length @LTLengthOf(“a”) int i

slide-23
SLIDE 23

Type systems

Linear inequalities i < j Minimum lengths a.length > 10 Negative indices | i | < a.length Lower bounds i ≥ 0 Equal lengths a.length = b.length Upper bounds i < a.length

23

slide-24
SLIDE 24

Type systems

Linear inequalities i < j Minimum lengths a.length > 10 Negative indices | i | < a.length Lower bounds i ≥ 0 Equal lengths a.length = b.length Upper bounds i < a.length

24

slide-25
SLIDE 25

A type system for minimum array lengths

if (a.length >= 3) { a[2] = ...; }

25

slide-26
SLIDE 26

A type system for minimum array lengths

if (a.length >= 3) { a[2] = ...; }

26

a.length ≥ i

T @MinLen(i) [] a

slide-27
SLIDE 27

Evaluation

Three case studies:

  • Google Guava (two packages)
  • JFreeChart
  • plume-lib

Comparison to existing tools:

  • FindBugs, KeY, Clousot

27

slide-28
SLIDE 28

Case Studies

Guava JFreeChart plume-lib Total Lines of code 10,694 94,233 14,586 119,503 Bugs found 5 64 20 89 Annotations 510 2,938 241 3,689 False positives 138 386 43 567 Java casts 222 2,740 219 3,181

28

slide-29
SLIDE 29

Comparison to other tools: confirmed bugs

Tool Index Checker FindBugs KeY Clousot True Positives False Negatives Approach

Types Bug finder

  • Verif. w/ solver
  • Abs. interpret.

Time (100k LoC)

29

slide-30
SLIDE 30

Comparison to other tools: confirmed bugs

Tool Index Checker FindBugs KeY Clousot True Positives False Negatives Approach

Types Bug finder

  • Verif. w/ solver
  • Abs. interpret.

Time (100k LoC) ~10 minutes ~1 minute cannot scale ~200 minutes

30

slide-31
SLIDE 31

Comparison to other tools: confirmed bugs

Tool Index Checker FindBugs KeY Clousot True Positives

18/18 0/18 9/18 16/18

False Negatives

0/18 18/18 1/18 2/18

Approach

Types Bug finder

  • Verif. w/ solver
  • Abs. interpret.

Time (100k LoC) ~10 minutes ~1 minute cannot scale ~200 minutes

31

slide-32
SLIDE 32

Using the Index Checker

  • Distributed with Checker Framework

www.checkerframework.org

32

slide-33
SLIDE 33

Contributions

  • A methodology: simple, cooperative type systems
  • An analysis: abstractions for array indexing
  • An implementation and evaluation for Java
  • Verifying the absence of array bounds errors in real

codebases (and finding bugs in the process!)

33