From Pointer Systems to Counter Systems using Shape Analysis Arnaud - - PowerPoint PPT Presentation

from pointer systems to counter systems using shape
SMART_READER_LITE
LIVE PREVIEW

From Pointer Systems to Counter Systems using Shape Analysis Arnaud - - PowerPoint PPT Presentation

From Pointer Systems to Counter Systems using Shape Analysis Arnaud Sangnier EDF R&D, LSV, ENS Cachan & CNRS joint work with: S ebastien Bardin, Alain Finkel, Etienne Lozes LSV, ENS Cachan & CNRS ACI S ecurit e


slide-1
SLIDE 1

From Pointer Systems to Counter Systems using Shape Analysis

Arnaud Sangnier EDF R&D, LSV, ENS Cachan & CNRS joint work with: S´ ebastien Bardin, Alain Finkel, Etienne Lozes LSV, ENS Cachan & CNRS ACI S´ ecurit´ e Informatique - 13th March 2006

1

slide-2
SLIDE 2

Motivation (I)

Cheking safety properties on systems manipulating dynamic linked lists

void deleteAll(List x) { List elem; while (x!=NULL) { elem=x; x=x->n; elem->n=NULL; free(elem); } }

List reverse(List x) { List y,t; y =NULL; while (x!=NULL) { t=y; y=x; x=x->n; y->n=t; t=NULL; } return y; }

Introduction

2

slide-3
SLIDE 3

Motivation (II)

We manipulate pointer variables + memory heap Memory heap = collection of memory cells A memory cell contains : data or address 2 1 3 NULL x data address

Introduction

3

slide-4
SLIDE 4

Motivation (III)

Properties Absence of memory violation (Segmentation fault) Absence of memory leak Qualitative properties on the memory heap (shape analysis)

Ex: The reverse function returns an acyclic list.

Quantitative properties on the memory heap

Ex: The reverse function returns a list of the same size as the input list.

Introduction

4

slide-5
SLIDE 5

Existing tools

TVLA [Sagiv, Reps, Wilhelm 2002] Abstract interpretation The user has to provide control predicates PALE [Moller, Schwartzbach 2001] Models the heap with a decidable monadic second order logic The user has to annotate the program Smallfoot [Berdine, Calcagno, O’Hearn 2005] Checks separation logic specifications

Introduction

5

slide-6
SLIDE 6

Symbolic methods

[Bardin, Finkel, Nowak 2004] Symbolic representation of the memory heap using graphs Were looking for an acceleration technique [Bouajjani, Habermehl, Moro, Vojnar 2005] Abstract regular model checking Regular expressions represent the memory heap [Bozga, Iosif 2005] Alias logic with counters

Introduction

6

slide-7
SLIDE 7

Our contribution

Modeling the memory heap using counters Translate the actions of the program into actions on the counters Propose a two-step analysis procedure

Introduction

7

slide-8
SLIDE 8

Outline

1

Models

2

Symbolic Computation

3

Translation

4

Analysis

5

Conclusion

Introduction

8

slide-9
SLIDE 9

Models and Systems

A system model M = (D, G, A) where D is an infinite set of data G ⊆ 2D is a set of guards A ⊆ DD is a set of actions A system A system S = (Q, δ) in M = (D, G, A) with Q is a finite set of control states δ ⊂ Q × G × A × Q is a transition relation. Semantics of a system A transition system TS(S) = (Q × D, →) where →⊆ (Q × D)2 is defined as (q, d) → (q′, d′) iff ∃g, a such that (q, g, a, q′) ∈ δ, d ∈ g and a(d) = d′

Models

9

slide-10
SLIDE 10

Modeling the memory heap

Memory graph (N, next, var) [BFN 04] N is a finite set of nodes with {z, p, r} ⊂ N next : N → N is a function such that :

next−1({r}) = {z, p, r}

var : N → 2V is such that {var(n)}n∈N forms a partition of the set of pointer variables V {x} n2 {y} n1 z p {t} r

N = {n1, n2, z, p, r} next(n1) = next(n2) = z var(n1) = {y}, var(n2) = {x}, var(p) = {t}

Models

10

slide-11
SLIDE 11

Pointer systems

The pointer model Data are memory graphs Syntax of guards : g ::= True | IsNull(x) | ¬IsNull(x) | ... Syntax of actions : a ::= x:=E | x.s:=E | x:=new | free(x) | nop where E is either null, or x or x.s.

Models

11

slide-12
SLIDE 12

A pointer system

The program deleteAll that deletes all the elements of a list

void deleteAll(List x) { List elem; while (x!=NULL) { elem=x; x=x->n; elem->n=NULL; free(elem); } }

4 3 2 1 5 ¬IsNull(x) ֒ → elem := x IsNull(x) ֒ → nop x := x.s elem.s := null free(elem)

Models

12

slide-13
SLIDE 13

Deciding memory problems

Definition [Memory violation] A memory graph has a memory violation if var(r) = ∅ Definition [Memory leakage] A memory graph has a memory leakage if N contains at least one node not reachable from a node labeled by a variable. Theorem [BFN 04] The reachability of memory leakage and of memory violation are undecidable problems for pointer systems with at least 3 pointer variables.

Models

13

slide-14
SLIDE 14

Counter systems

The counter model ; Data are vectors of NK (K is a finite set of counters) Guards are Presburger formulae interpreted in NK Actions are linear functions in NK We can use the tool FAST ([Bardin, Finkel, Leroux, Petrucci 2003]) to analyze counter systems: Symbolic verification of counter system terminates often in practice

Models

14

slide-15
SLIDE 15

Outline

1

Models

2

Symbolic Computation

3

Translation

4

Analysis

5

Conclusion

Symbolic Computation

15

slide-16
SLIDE 16

Memory shapes

{x} {y} z p {t} r Memory graph

Symbolic Computation

16

slide-17
SLIDE 17

Memory shapes

Compression of irrelevant nodes

{x} {y} z p {t} r Memory graph

Symbolic Computation

16

slide-18
SLIDE 18

Memory shapes

Compression of irrelevant nodes

{x} {y} z p {t} r Memory graph {x} {y} z p {t} r Memory shape

Symbolic Computation

16

slide-19
SLIDE 19

Memory shapes

Compression of irrelevant nodes Labeling with strictly positive counters

{x} {y} z p {t} r Memory graph {x} {y} z p {t} r k1 k2 Memory shape

Symbolic Computation

16

slide-20
SLIDE 20

Memory shapes

Compression of irrelevant nodes Labeling with strictly positive counters

{x} {y} z p {t} r Memory graph {x} {y} z p {t} r k1 k2 Memory shape

k1 = 2 k2 = 1

A memory shape + a counter valuation = a unique memory graph (without memory leakage)

Symbolic Computation

16

slide-21
SLIDE 21

Memory shapes

Compression of irrelevant nodes Labeling with strictly positive counters Two special memory shapes: MemLeak and SegF

{x} {y} z p {t} r Memory graph {x} {y} z p {t} r k1 k2 Memory shape

k1 = 2 k2 = 1

A memory shape + a counter valuation = a unique memory graph (without memory leakage)

Symbolic Computation

16

slide-22
SLIDE 22

Properties of memory shapes

We consider a finite set of pointer variables V. Number of counters The number of counters in a memory shape is bounded by 2.|V|. Number of memory shapes The number of memory shapes built over V is bounded by 2.|V|(3.|V|). Equality test Testing equality of two memory shapes can be done in linear time.

Symbolic Computation

17

slide-23
SLIDE 23

Symbolic computation on memory shapes (I)

Effect of the action x.s := y on the memory shape MS1

{y} zN rN pN {x}

MS1

k1 k2 k3 Symbolic Computation

18

slide-24
SLIDE 24

Symbolic computation on memory shapes (I)

Effect of the action x.s := y on the memory shape MS1

{y} zN rN pN {x}

MS1

k1 k2 k3

{y} {x} zN rN pN [k1 := k2 + k1,k2 := 0]

k1 k3

k3 = 1?

Symbolic Computation

18

slide-25
SLIDE 25

Symbolic computation on memory shapes (I)

Effect of the action x.s := y on the memory shape MS1

{y} zN rN pN {x}

MS1

k1 k2 k3

{y} {x} zN rN pN [k1 := k2 + k1,k2 := 0]

k1 k3

k3 = 1?

MemLeak

k3 > 1?

Symbolic Computation

18

slide-26
SLIDE 26

Symbolic computation on memory shapes (II)

The symbolic function TEST Decides whether a memory shape satisfies a pointer guard (ie all the underlying memory graphs for any valuation satisfy it). The symbolic function POST Produces, from a given memory shape and a pointer action, the set {(φi, fi, MSi)} of all possible issues (the φi’s are Presburger formulae and the fi’s are linear functions)

Symbolic Computation

19

slide-27
SLIDE 27

Outline

1

Models

2

Symbolic Computation

3

Translation

4

Analysis

5

Conclusion

Translation

20

slide-28
SLIDE 28

Building of the counter system

To each control state of the counter system we associate a memory shape and a control state of the pointer system

4 3 2 1 5 ¬IsNull(x) ֒ → elem := x IsNull(x) ֒ → nop x := x.s elem.s := null free(elem) A1 B2 C3 D4 E1 F5 G3 H4 I1 k = 1? k > 1?[l := 1,k := k − 1] l = 1?[l := 0] l > 1?

Translation

21

slide-29
SLIDE 29

Building of the counter system

To each control state of the counter system we associate a memory shape and a control state of the pointer system

4 3 2 1 5 ¬IsNull(x) ֒ → elem := x IsNull(x) ֒ → nop x := x.s elem.s := null free(elem) A1 B2 C3 D4 E1 F5 G3 H4 I1 k = 1? k > 1?[l := 1,k := k − 1] l = 1?[l := 0] l > 1?

{x} z {elem} p {t} r k Translation

21

slide-30
SLIDE 30

Building of the counter system

To each control state of the counter system we associate a memory shape and a control state of the pointer system

4 3 2 1 5 ¬IsNull(x) ֒ → elem := x IsNull(x) ֒ → nop x := x.s elem.s := null free(elem) A1 B2 C3 D4 E1 F5 G3 H4 I1 k = 1? k > 1?[l := 1,k := k − 1] l = 1?[l := 0] l > 1?

{x} {elem} z p {t} r k Translation

21

slide-31
SLIDE 31

Building of the counter system

To each control state of the counter system we associate a memory shape and a control state of the pointer system

4 3 2 1 5 ¬IsNull(x) ֒ → elem := x IsNull(x) ֒ → nop x := x.s elem.s := null free(elem) A1 B2 C3 D4 E1 F5 G3 H4 I1 k = 1? k > 1?[l := 1,k := k − 1] l = 1?[l := 0] l > 1?

{elem} z {x} p {t} r k Translation

21

slide-32
SLIDE 32

Building of the counter system

To each control state of the counter system we associate a memory shape and a control state of the pointer system

4 3 2 1 5 ¬IsNull(x) ֒ → elem := x IsNull(x) ֒ → nop x := x.s elem.s := null free(elem) A1 B2 C3 D4 E1 F5 G3 H4 I1 k = 1? k > 1?[l := 1,k := k − 1] l = 1?[l := 0] l > 1?

{x} z p {t} r {elem} k l Translation

21

slide-33
SLIDE 33

Building of the counter system

To each control state of the counter system we associate a memory shape and a control state of the pointer system

4 3 2 1 5 ¬IsNull(x) ֒ → elem := x IsNull(x) ֒ → nop x := x.s elem.s := null free(elem) A1 B2 C3 D4 E1 F5 G3 H4 I1 k = 1? k > 1?[l := 1,k := k − 1] l = 1?[l := 0] l > 1?

{x} z p {t} r {elem} k l Translation

21

slide-34
SLIDE 34

Properties of the translation

The translation is effective. Bisimulation [BFLS 2006] The following relation :

R = (q, MS, val) , ((q, MS), val)

  • q ∈ Qp, MS ∈ MS, val ∈ NK

is a bisimulation between the transitions systems of the pointer system and the counter system.

Translation

22

slide-35
SLIDE 35

Outline

1

Models

2

Symbolic Computation

3

Translation

4

Analysis

5

Conclusion

Analysis

23

slide-36
SLIDE 36

2 steps analysis

Over-approximation The set of memory shapes appearing in the control states of the counter system is an over-approximation of the memory shapes reachable in the pointer system. This leads to a 2 step analysis :

1 Checking if the unsafe states are present in the control states

  • f the counter system

2 In the positive case, checking if they are effectively reachable

using FAST

Analysis

24

slide-37
SLIDE 37

2 steps analysis (example)

A B C D E F G H I MemLeak k = 1? k > 1?[l := 1,k := k − 1] l = 1?[l := 0] l > 1?

The memory shape SegF does not appear in the counter system The memory shape MemLeak does in state I

Analysis

25

slide-38
SLIDE 38

2 steps analysis (example)

A B C D E F G H I MemLeak k = 1? k > 1?[l := 1,k := k − 1] l = 1?[l := 0] l > 1?

The memory shape SegF does not appear in the counter system The memory shape MemLeak does in state I BUT the control state I is not reachable

Analysis

25

slide-39
SLIDE 39

Outline

1

Models

2

Symbolic Computation

3

Translation

4

Analysis

5

Conclusion

Conclusion

26

slide-40
SLIDE 40

Conclusion and future work

Concluding remarks Our translation is automatic It allows the verification of quantitative properties on classical examples A prototype has been implemented in O’CAML On going work Improve the translation to reduce the produced counter systems Add counter variables in the pointer systems

Conclusion

27