mixing type checking and symbolic evaluation

18
Mix ing Type Checking and Symbolic Execution Khoo Yit Phang (UMD College Park) Bor-Yuh Evan Chang (CU Boulder) Jeffrey S. Foster (UMD College Park) FRACTAL - December 5, 2009

Upload: others

Post on 08-Dec-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mixing Type Checking and Symbolic Evaluation

Mixing Type Checking and

Symbolic Execution

Khoo Yit Phang (UMD College Park)

Bor-Yuh Evan Chang (CU Boulder)

Jeffrey S. Foster (UMD College Park)

FRACTAL - December 5, 2009

Page 2: Mixing Type Checking and Symbolic Evaluation

2

An all too common scenario …

Static verifiers must over-approximate

and thus raise false alarms.

Oh Verifier,

help me prove

my program

has no bugs.

On line 142,

there may

be a bug.

Isn’t it obvious

this can’t

happen!?!?

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

Page 3: Mixing Type Checking and Symbolic Evaluation

3

False alarm example:

The need for path sensitivity

if (multithreaded) fork();

… statements1 …

… statements2 …

if (multithreaded) lock();

if (multithreaded) unlock();

unlock();

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

mislabels

good code

as buggy

This abstraction is too coarse. Standard

practice is to re-design it to be precise

enough for this example.

Page 4: Mixing Type Checking and Symbolic Evaluation

4

Re-design with path sensitivity

if (multithreaded) fork();

… statements1 …

… statements2 …

if (multithreaded) lock();

if (multithreaded) unlock();

unlock();

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

multithreaded Æ

Ç:multithreaded Æ

Bad: Too much precision leads to slow,

inefficient analysis

Bad: Ad-hoc addition of precision leads

to brittle analyzers

Page 5: Mixing Type Checking and Symbolic Evaluation

5

Observation: Just need

precision in select places

if (multithreaded) fork();

… statements1 …

… statements2 …

if (multithreaded) lock();

if (multithreaded) unlock();

unlock();

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

assume(multithreaded); assume(!multithreaded);

fork();

lock();

unlock();

… statements1 …… statements1 …

… statements2 …… statements2 …

Page 6: Mixing Type Checking and Symbolic Evaluation

6

coarse

precise

Approach: Split the program

between analyses unlock();

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

coarse

coarse

coarse

if (multithreaded) fork();

… statements1 …

… statements2 …

if (multithreaded) lock();

if (multithreaded) unlock();

Switch to precise analysis only where needed

Page 7: Mixing Type Checking and Symbolic Evaluation

7

MIX is …

A tunable program analysis that alternates between

type inference and symbolic execution

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

MIX

• Standard, off-the-shelf type inference

• Standard, off-the-shelf symbolic execution

• Mixing rules to translate information at

block boundaries

Page 8: Mixing Type Checking and Symbolic Evaluation

8

Why type inference and symbolic execution?

• Case study of extremes

– Simple, well-understood algorithms

– Hard to imagine how to combine in more intricate ways

(e.g., in contrast to combining abstract interpreters)

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

precision

Type Inference• *-insensitive

• terminating analysis

• constraint graph

Symbolic Execution• *-sensitive

• may not terminate

• simulation + SMT solver

Page 9: Mixing Type Checking and Symbolic Evaluation

9

Outline

• Mixing rules

• Examples and idioms for switching blocks

• Preliminary experience with MIXY, a mixed

type qualifier inference engine for C

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

Page 10: Mixing Type Checking and Symbolic Evaluation

10

= (± Æ ¯ ; ® + ° : int)

Type checking and symbolic execution

at a glance

Type checking

x + (if b then y else 3)

Symbolic execution

x + (if b then y else 3)

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

x : int, b: bool, y : int

: int

± ; x = ®:int, b = ¯:bool, y = °:int

Typing context

x + (if b then y else 3)

type of the

expression

Symbolic context

path

condition

symbolic result

along the path

= (± Æ :¯ ; ® + 3 : int)

Page 11: Mixing Type Checking and Symbolic Evaluation

11

symex type

symex

= (¯ ; ® + ° : int)

Mixing rules: Conservatively translate states

type

Nested type checking

x + (if b then y else 3)

Nested symbolic execution

x + (if b then y else 3)

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

x : int, b: bool, y : int > ; x = ®:int, b = ¯:bool, y = °:int

= (:¯ ; ® + 3 : int)

: int

± ; x = ®:int, b = ¯:bool, y = °:int

= (± ; ² : int)

x : int, b: bool, y : int

: int

Path conditions

indicate exhaustive

exploration

Formalized and proven sound for an ML-like

language with references

Mixing rules are not particularly surprising

What may be surprising is that such simple

rules with off-the-shelf algorithms yield

increased precision in many ways

Page 12: Mixing Type Checking and Symbolic Evaluation

12

Outline

• Mixing rules

• Examples and idioms for switching blocks

• Preliminary experience with MIXY, a mixed

type qualifier inference engine for C

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

Page 13: Mixing Type Checking and Symbolic Evaluation

13

symex

symex

Flow, path, and context sensitivity

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

type type

type type

typesymex

x := 1; … ; x := “hello”; … ;

let pred n = if n = 0 then “err” else n–1

in … + (pred 3)

Static type checking for dynamically-typed code

Page 14: Mixing Type Checking and Symbolic Evaluation

14

symex

Local refinement

if (x > 0) {

}

else if (x == 0) {

}

else {

}

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

x : posint

x : zero

x : negint

type

type

type

Page 15: Mixing Type Checking and Symbolic Evaluation

15

symex

Abstraction during symbolic execution

type

type

let x = unknown_function() in

let y = recursive_function() in

let z = … operation not supported by solver … in

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

type

Page 16: Mixing Type Checking and Symbolic Evaluation

16

Outline

• Mixing rules

• Examples and idioms for switching blocks

• Preliminary experience with MIXY, a mixed

type qualifier inference engine for C

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

Page 17: Mixing Type Checking and Symbolic Evaluation

17

Preliminary experience

• MIXY, a prototype mixed type qualifier inference

engine for C

• Applied to check that a free function is called

only with a non-null pointer (using nonnull type

qualifier)

– On vsftpd 2.0.7

– Eliminated 2 false warnings

– A combination of flow, path, and context-

sensitivity was required

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution

Page 18: Mixing Type Checking and Symbolic Evaluation

18

Conclusion

• New approach for trading off precision and

efficiency in static program analysis

• Key: Nestable switching blocks to

alternate between different off-the-shelf

analyses

• Studied the mixing of type checking and

symbolic evaluation

– Proven soundness of symbolic execution/mix

Khoo Yit Phang, Bor-Yuh Evan Chang, Jeffrey S. Foster - Mixing Type Checking and Symbolic Execution