69
A system for testing specifications of CPU semantics Lindsey Kuper or, What I did on my summer vacation 1 Tuesday, October 19, 2010

A system for testing specifications of CPU semantics

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A system for testing specifications of CPU semantics

A system for testing specifications of CPU

semantics

Lindsey Kuper

or,What I did on my summer vacation

1

Tuesday, October 19, 2010

Page 2: A system for testing specifications of CPU semantics

Static analysis of executables: what, why, and how?

2

Tuesday, October 19, 2010

Page 3: A system for testing specifications of CPU semantics

Static analysis of executables: what, why, and how?

• Abstract interpretation: a sound overapproximation of the behavior of a concrete system.

2

Tuesday, October 19, 2010

Page 4: A system for testing specifications of CPU semantics

Static analysis of executables: what, why, and how?

• Abstract interpretation: a sound overapproximation of the behavior of a concrete system.

• “WYSINWYX: What You See Is Not What You Execute” (Balakrishnan et al. 2005)

2

Tuesday, October 19, 2010

Page 5: A system for testing specifications of CPU semantics

Static analysis of executables: what, why, and how?

• Abstract interpretation: a sound overapproximation of the behavior of a concrete system.

• “WYSINWYX: What You See Is Not What You Execute” (Balakrishnan et al. 2005)

• What kinds of static analysis can one do on executables?

2

Tuesday, October 19, 2010

Page 6: A system for testing specifications of CPU semantics

Static analysis of executables: what, why, and how?

• Abstract interpretation: a sound overapproximation of the behavior of a concrete system.

• “WYSINWYX: What You See Is Not What You Execute” (Balakrishnan et al. 2005)

• What kinds of static analysis can one do on executables?

• Value-set analysis (VSA)

2

Tuesday, October 19, 2010

Page 7: A system for testing specifications of CPU semantics

Static analysis of executables: what, why, and how?

• Abstract interpretation: a sound overapproximation of the behavior of a concrete system.

• “WYSINWYX: What You See Is Not What You Execute” (Balakrishnan et al. 2005)

• What kinds of static analysis can one do on executables?

• Value-set analysis (VSA)

• Quantifier-free bit-vector (QFBV) analysis

2

Tuesday, October 19, 2010

Page 8: A system for testing specifications of CPU semantics

Static analysis of executables: what, why, and how?

• Abstract interpretation: a sound overapproximation of the behavior of a concrete system.

• “WYSINWYX: What You See Is Not What You Execute” (Balakrishnan et al. 2005)

• What kinds of static analysis can one do on executables?

• Value-set analysis (VSA)

• Quantifier-free bit-vector (QFBV) analysis

• ...

2

Tuesday, October 19, 2010

Page 9: A system for testing specifications of CPU semantics

The TSL testing problem

3

Tuesday, October 19, 2010

Page 10: A system for testing specifications of CPU semantics

The TSL testing problem

3

Lim, J, and Reps, T. , “A System for Generating Static Analyzers from Machine Instructions”, CC ’08

Tuesday, October 19, 2010

Page 11: A system for testing specifications of CPU semantics

The TSL testing problem

• TSL (Transformer Specification Language) lets us generate static analyzers from specifications. Great!

3

Lim, J, and Reps, T. , “A System for Generating Static Analyzers from Machine Instructions”, CC ’08

Tuesday, October 19, 2010

Page 12: A system for testing specifications of CPU semantics

The TSL testing problem

• TSL (Transformer Specification Language) lets us generate static analyzers from specifications. Great!

IA32

3

Tuesday, October 19, 2010

Page 13: A system for testing specifications of CPU semantics

The TSL testing problem

• TSL (Transformer Specification Language) lets us generate static analyzers from specifications. Great!

IA32

PowerPC

3

Tuesday, October 19, 2010

Page 14: A system for testing specifications of CPU semantics

The TSL testing problem

• TSL (Transformer Specification Language) lets us generate static analyzers from specifications. Great!

IA32

PowerPC

x86-64

3

Tuesday, October 19, 2010

Page 15: A system for testing specifications of CPU semantics

The TSL testing problem

• TSL (Transformer Specification Language) lets us generate static analyzers from specifications. Great!

VSA

IA32

PowerPC

x86-64

3

Tuesday, October 19, 2010

Page 16: A system for testing specifications of CPU semantics

The TSL testing problem

• TSL (Transformer Specification Language) lets us generate static analyzers from specifications. Great!

VSA

IA32

PowerPC

EMUL

x86-64

3

Tuesday, October 19, 2010

Page 17: A system for testing specifications of CPU semantics

The TSL testing problem

• TSL (Transformer Specification Language) lets us generate static analyzers from specifications. Great!

VSA

IA32

PowerPC

EMUL

x86-64

QFBV

3

Tuesday, October 19, 2010

Page 18: A system for testing specifications of CPU semantics

The TSL testing problem

• TSL (Transformer Specification Language) lets us generate static analyzers from specifications. Great!

VSA

IA32

PowerPC

EMUL

x86-64

QFBV

Analysis engine

Analysis engine

Analysis engine

Analysis engine

Analysis engine

Analysis engine

Analysis engine

Analysis engine

Analysis engine

3

Tuesday, October 19, 2010

Page 19: A system for testing specifications of CPU semantics

The TSL testing problem

• TSL (Transformer Specification Language) lets us generate static analyzers from specifications. Great!

• But how do we know if the generated analysis engines (multiplicatively many!) are correct?

VSA

IA32

PowerPC

EMUL

x86-64

QFBV

Analysis engine

Analysis engine

Analysis engine

Analysis engine

Analysis engine

Analysis engine

Analysis engine

Analysis engine

Analysis engine

3

Tuesday, October 19, 2010

Page 20: A system for testing specifications of CPU semantics

Our approach

4

Tuesday, October 19, 2010

Page 21: A system for testing specifications of CPU semantics

Our approach

4

Tuesday, October 19, 2010

Page 22: A system for testing specifications of CPU semantics

Our approach

• Narrow the focus to testing just the ISA specs.

4

Tuesday, October 19, 2010

Page 23: A system for testing specifications of CPU semantics

Our approach

• Narrow the focus to testing just the ISA specs.

EMUL

4

Tuesday, October 19, 2010

Page 24: A system for testing specifications of CPU semantics

Our approach

• Narrow the focus to testing just the ISA specs.

• Can we really isolate an ISA spec? We can come close by using EMUL, the “simplest” interpretation.

EMUL

4

Tuesday, October 19, 2010

Page 25: A system for testing specifications of CPU semantics

Our approach

• Narrow the focus to testing just the ISA specs.

• Can we really isolate an ISA spec? We can come close by using EMUL, the “simplest” interpretation.

IA32

EMUL

4

Tuesday, October 19, 2010

Page 26: A system for testing specifications of CPU semantics

Our approach

• Narrow the focus to testing just the ISA specs.

• Can we really isolate an ISA spec? We can come close by using EMUL, the “simplest” interpretation.

IA32

EMUL

IA32

Emulator

4

Tuesday, October 19, 2010

Page 27: A system for testing specifications of CPU semantics

Our approach

• Narrow the focus to testing just the ISA specs.

• Can we really isolate an ISA spec? We can come close by using EMUL, the “simplest” interpretation.

• And for now, start with IA32.

IA32

EMUL

IA32

Emulator

4

Tuesday, October 19, 2010

Page 28: A system for testing specifications of CPU semantics

Goal for the summer

5

Tuesday, October 19, 2010

Page 29: A system for testing specifications of CPU semantics

Goal for the summer

• Find out how complete and precise our IA32 TSL specification is...

5

Tuesday, October 19, 2010

Page 30: A system for testing specifications of CPU semantics

Goal for the summer

• Find out how complete and precise our IA32 TSL specification is...

• ...by generating an IA32 emulator, then comparing the emulator to the real processor.

5

Tuesday, October 19, 2010

Page 31: A system for testing specifications of CPU semantics

Goal for the summer

• Find out how complete and precise our IA32 TSL specification is...

• ...by generating an IA32 emulator, then comparing the emulator to the real processor.

• If resulting states differ on the same inputs, the spec was (probably) buggy.

5

Tuesday, October 19, 2010

Page 32: A system for testing specifications of CPU semantics

Goal for the summer

• Find out how complete and precise our IA32 TSL specification is...

• ...by generating an IA32 emulator, then comparing the emulator to the real processor.

• If resulting states differ on the same inputs, the spec was (probably) buggy.

• We already have all the pieces: IA32 spec, EMUL, and a third-party tool for testing CPU emulators. This will be easy, right?!

5

Tuesday, October 19, 2010

Page 33: A system for testing specifications of CPU semantics

A brief digression: abstract interpretation, ɣ, and α

6

Tuesday, October 19, 2010

Page 34: A system for testing specifications of CPU semantics

A brief digression: abstract interpretation, ɣ, and α

6

Tuesday, October 19, 2010

Page 35: A system for testing specifications of CPU semantics

How to test a CPU emulator

7

Tuesday, October 19, 2010

Page 36: A system for testing specifications of CPU semantics

How to test a CPU emulator

7

Martignioni, L. et al., “Testing CPU Emulators”, ISSTA ’09

EmuFuzzer’s design

Tuesday, October 19, 2010

Page 37: A system for testing specifications of CPU semantics

EmuFuzzer’s design

How to test a CPU emulator

7

Martignioni, L. et al., “Testing CPU Emulators”, ISSTA ’09

Tuesday, October 19, 2010

Page 38: A system for testing specifications of CPU semantics

EmuFuzzer’s design

How to test a CPU emulator

VSA

EMUL

QFBV

But wait!

We don’t only want to test ordinary emulators.

7

Martignioni, L. et al., “Testing CPU Emulators”, ISSTA ’09

Tuesday, October 19, 2010

Page 39: A system for testing specifications of CPU semantics

How to test a CPU emulatorany analysis engine(someday)

7

Tuesday, October 19, 2010

Page 40: A system for testing specifications of CPU semantics

How to test a CPU emulatorany analysis engine(someday)

Our design

7

Tuesday, October 19, 2010

Page 41: A system for testing specifications of CPU semantics

Look-thru memory

8

Tuesday, October 19, 2010

Page 42: A system for testing specifications of CPU semantics

Look-thru memory

8

Tuesday, October 19, 2010

Page 43: A system for testing specifications of CPU semantics

Look-thru memory

• The ability to lazily instantiate the emulator's state (memory and registers) from that of the process as each instruction is being emulated.

8

Tuesday, October 19, 2010

Page 44: A system for testing specifications of CPU semantics

TSL validator main loop

9

Tuesday, October 19, 2010

Page 45: A system for testing specifications of CPU semantics

TSL validator main loop

9

Tuesday, October 19, 2010

Page 46: A system for testing specifications of CPU semantics

TSL validator main loop

9

Tuesday, October 19, 2010

Page 47: A system for testing specifications of CPU semantics

TSL validator main loop

9

Tuesday, October 19, 2010

Page 48: A system for testing specifications of CPU semantics

TSL validator main loop

9

Tuesday, October 19, 2010

Page 49: A system for testing specifications of CPU semantics

TSL validator main loop

9

Tuesday, October 19, 2010

Page 50: A system for testing specifications of CPU semantics

TSL validator main loop

9

Tuesday, October 19, 2010

Page 51: A system for testing specifications of CPU semantics

TSL validator main loop

State comparison is tricky

9

Tuesday, October 19, 2010

Page 52: A system for testing specifications of CPU semantics

TSL validator main loop

State comparison is tricky

9

Tuesday, October 19, 2010

Page 53: A system for testing specifications of CPU semantics

TSL validator main loop

State comparison is tricky

9

Tuesday, October 19, 2010

Page 54: A system for testing specifications of CPU semantics

Future work: short-term stuff

10

Tuesday, October 19, 2010

Page 55: A system for testing specifications of CPU semantics

• The hard part of state comparison: identify changed locations on the real process side, and compare them with corresponding locations on the emulator side.

Future work: short-term stuff

10

Tuesday, October 19, 2010

Page 56: A system for testing specifications of CPU semantics

• The hard part of state comparison: identify changed locations on the real process side, and compare them with corresponding locations on the emulator side.

• Better logging and reporting: eventually, we’d like to have a “dashboard” that will tell us roughly how complete and correct the existing TSL specifications are.

Future work: short-term stuff

10

Tuesday, October 19, 2010

Page 57: A system for testing specifications of CPU semantics

• The hard part of state comparison: identify changed locations on the real process side, and compare them with corresponding locations on the emulator side.

• Better logging and reporting: eventually, we’d like to have a “dashboard” that will tell us roughly how complete and correct the existing TSL specifications are.

• How to deal with test programs that “misbehave”? (Programs that mess with their own memory protection, install their own seg fault handlers, ...)

Future work: short-term stuff

10

Tuesday, October 19, 2010

Page 58: A system for testing specifications of CPU semantics

Future work: long-term stuff

11

Tuesday, October 19, 2010

Page 59: A system for testing specifications of CPU semantics

Future work: long-term stuff

11

Tuesday, October 19, 2010

Page 60: A system for testing specifications of CPU semantics

Future work: long-term stuff

• Support for more ISAs. (x64, at least!)

11

Tuesday, October 19, 2010

Page 61: A system for testing specifications of CPU semantics

Future work: long-term stuff

• Support for more ISAs. (x64, at least!)

• Support for true abstract interpretations, not just EMUL.

11

Tuesday, October 19, 2010

Page 62: A system for testing specifications of CPU semantics

Future work: long-term stuff

• Support for more ISAs. (x64, at least!)

• Support for true abstract interpretations, not just EMUL.

• Find ways to choose which inputs to test that will be most likely to turn up bugs in a specification.

11

Tuesday, October 19, 2010

Page 63: A system for testing specifications of CPU semantics

What I learned

12

Tuesday, October 19, 2010

Page 64: A system for testing specifications of CPU semantics

• Emulators, debuggers, and static analyzers are not made of magic

What I learned

12

Tuesday, October 19, 2010

Page 65: A system for testing specifications of CPU semantics

• Emulators, debuggers, and static analyzers are not made of magic

• First real systems programming experience: didn’t quite cross the kernel space boundary, but came right up next to it

What I learned

12

Tuesday, October 19, 2010

Page 66: A system for testing specifications of CPU semantics

• Emulators, debuggers, and static analyzers are not made of magic

• First real systems programming experience: didn’t quite cross the kernel space boundary, but came right up next to it

• A metric for how much I can accomplish in 13 weeks

What I learned

12

Tuesday, October 19, 2010

Page 67: A system for testing specifications of CPU semantics

• Emulators, debuggers, and static analyzers are not made of magic

• First real systems programming experience: didn’t quite cross the kernel space boundary, but came right up next to it

• A metric for how much I can accomplish in 13 weeks

• Finally convinced that OOP is good for something

What I learned

12

Tuesday, October 19, 2010

Page 68: A system for testing specifications of CPU semantics

Thank you!

Questions?13

Tuesday, October 19, 2010

Page 69: A system for testing specifications of CPU semantics

14

(exit)

Tuesday, October 19, 2010