20
Exploiting Undefined Behaviors for Efficient Symbolic Execution Asankhaya Sharma National University of Singapore

Exploiting undefined behaviors for efficient symbolic execution

Embed Size (px)

Citation preview

Page 1: Exploiting undefined behaviors for efficient symbolic execution

Exploiting Undefined Behaviors for Efficient Symbolic Execution

Asankhaya SharmaNational University of Singapore

Page 2: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 2

Motivation

Page 3: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 3

Rainbow Pony

Page 4: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 4

Software Engineering Works

Hall, Anthony. "Realising the Benefits of Formal Methods." J. UCS 13.5 (2007): 669-678.

Page 5: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 5

Symbolic Execution

• Software engineering tools (KLEE, PEX, Klover etc.) routinely use symbolic execution for – Test case generation– Bug finding– Debugging– Performance analysis– Verification

• Improving the performance can have big impact

Page 6: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 6

Efficient Symbolic Execution

• Bottlenecks for performance– Path explosion– Complexity of generated constraints

• Existing approaches– Constraint subsumption and simplification– Concoclic execution– State merging, caching and reusing constraints– Static analysis

Page 7: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 7

Key Idea

• Compilers are really good at optimization based on undefined behaviors

• Design a static analysis (Change Value Analysis) to introduce undefined behaviors in programs

• Use the optimized binaries for symbolic execution

Page 8: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 8

Main Benefits

• Does not require any change in the underlying symbolic execution engine to use the results from static analysis for dynamic path exploration

• Allows reduction in size of compiled binaries and prevents generation of irrelevant constraints

Page 9: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 9

Overview of Approach

Change Value Analysis of Program

Program with Undefined Behaviors

Compiler Optimizations

Binary for Symbolic Execution

Page 10: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 10

Change Value Analysis

int foo (int x, int y, int z){ int a; a = z; if (x – y > 0)

a = x; else

a = y; if (z > a) printf(“z is max”); return a;}

Changed

Unchanged

Undefined

Page 11: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 11

Change Value Analysis

int foo (int x, int y, int z){ int a; a = z; if (x – y > 0)

a = x; else

a = y; if (z > a) printf(“z is max”); return a;}

Changed

Unchanged

Undefined

a

Page 12: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 12

Change Value Analysis

int foo (int x, int y, int z){ int a; a = z; if (x – y > 0)

a = x; else

a = y; if (z > a) printf(“z is max”); return a;}

Changed

Unchanged

Undefined

a, x, y

z

Page 13: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 13

Introduce Undefined Behaviors

int foo (int x, int y, int z){ int a; a = *; if (x – y > 0)

a = x; else

a = y; if (* > a) printf(“z is max”); return a;}

Changed

Unchanged

Undefined

a, x, y

z

Replace Unchanged variables with nondeterministic value *

Page 14: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 14

After Compiler Optimizations

int foo (int x, int y, int z){ int a; a = *; if (x – y > 0)

a = x; else

a = y; if (* > a) printf(“z is max”); return a;}

int foo (int x, int y, int z){ int a; if (x – y > 0)

a = x; else

a = y; return a;}

Eliminates 3 lines from the program

Page 15: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 15

Experiments

• Change Value Analysis implemented as a compiler pass in LLVM

• Use an existing tool Fuzzgrind for symbolic execution of binaries

• Benchmarks from Software-artifact Infrastructure Repository (SIR)

Page 16: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 16

Results

Tacas

Schedule2

Replace

Totinfo

Print T

okens2

Space Grep

Flex

Sed

0

200

400

600

800

1000

1200

Constraints (Num)Constraints with CVA

30% Reduction in Number of Constraints

Page 17: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 17

Results

Tacas

Schedule2

Replace

Totinfo

Print T

okens2

Space Grep

Flex

Sed

020406080

100120140160180200

Time (Secs)Time with CVA

48% Reduction in Time taken for Symbolic Execution

Page 18: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 18

Conclusions

• Systematically introducing undefined behaviors in programs can speed up symbolic execution

• Compilers already optimize code for efficiency and size, we show that they can also optimize code for use in symbolic execution and testing

Page 19: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 19

Thank You !

• Questions ?• Source Code (GPL 3)– https://github.com/codelion/pathgrind– https://github.com/codelion/pa.llvm

• Contact– [email protected]

Page 20: Exploiting undefined behaviors for efficient symbolic execution

05/01/2023 ICSE SRC 2014 20

Comparison with Slicing

x = a;y = 5;if (a > 0) b = x + y; if (*) x = 1; else y = 0;if (y > 0) z = x;

Slicing w.r.t variable z

x = a;y = 5;if (a > 0) b = x + y; if (*) x = 1; else y = 0;if (y > 0) z = x;

Slicing may include dependencies from infeasible paths

Jaffar, Joxan, et al. "Path-sensitive backward slicing." Static Analysis. Springer Berlin Heidelberg, 2012. 231-247.

Using Change Value analysis - “a” is in Unchanged set