Top Banner
Finding Bugs with American Fuzzy Lop George Dunlap
29

XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Jan 22, 2018

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Finding Bugs with

American Fuzzy LopGeorge Dunlap

Page 2: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

American Fuzzy Lop

Page 3: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

American Fuzzy Lop

Instrumentation-guided genetic fuzzer

Page 4: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Goals

• Tell you about AFL (because it’s cool)

• To encourage you to look into using AFL

• In your own test cases…

• …or in Xen

Page 5: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Outline

• AFL overview

• Using AFL for the Xen x86 instruction emulator

• Other opportunities for fuzzing in Xen

Page 6: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

AFL: Basic Idea

• Start with a set of “interesting” test cases

• Run them through an instrumented binary to see what paths are taken

• Take one off the list and start mutating it

• New path taken? Add it to your list of “interesting” test cases

• Crash? Keep it in a separate file

Page 7: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

x86_emulate• Common code to decode and emulate x86 instructions

• Over 8000 LoC

• Called from HVM, PV, and shadow code

• Pass it:

• CPU context, callbacks for all other state interaction

• 26 callbacks; most are optional, all can return failure

• Already has a user-space test harness

Page 8: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix
Page 9: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

x86_decode (single instruction)

Page 10: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix
Page 11: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

x86_emulate single instruction, blank cpu slate,

minimal set of callbacks

Page 12: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

x86_emulate multiple instructions

Page 13: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

FPU Exceptions• FPU instructions re-executed in the hypervisor context

• Xen has framework for handling exceptions, properly; AFL framework didn’t

• FPU exceptions don’t happen unless they’re enabled, and they start off disabled

• …so AFL had figured out how to turn them on

• Hack: Disable exceptions after every instruction iteration

Page 14: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Fuzz the core registers

Page 15: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

XSA-195: BT* instructions

Page 16: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix
Page 17: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Allowing AFL to fuzz more

• Implement more callbacks

• Allow reads to return fuzzed values (rather than zero)

• Allow more complete cpu state to be fuzzed

• Allow non-canonical addresses

• Allow random failure of callbacks

Page 18: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

A bug in one of the XSA fixes!

Page 19: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

(Valid) assertions about architecturally correct state

Page 20: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Unchecked return value

Page 21: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Unreal mode

Page 22: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

So AFL…• Discovered three critical bugs in x86_emulate

• Discovered…

• How to turn on FPU exceptions

• Assumptions about architectural consistency

• An unchecked return value

• Assumptions about unreal mode

Page 23: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

AFL in xen.git

Page 24: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Running afl-harness• Install AFL

• afl packages in debian-testing, others

• d/l and build from http://lcamtuf.coredump.cx/afl/

• Build afl-harness

• cd xen.git/tools/fuzz/x86_instruction_emulator

• make CC=afl-gcc afl

• Make starting input

• dd if=/dev/urandom of=input/rand bs=$(./afl-harness --min-input)

• Run afl-fuzz

• afl-fuzz -i input/ -o output/ -- ./afl-harness

Page 25: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Diving deeper

• “Map” and the branch path

• Fork server / “persistent mode”

• Other languages

• Python, Go, Rust, ocaml, GJC Java

• Running in parallel

Page 26: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Fuzzing more• Already fuzz libelf

• Xen hypercall interface

• GSOC student working on this

• xenstore?

• pygrub?

• disk / network backends?

Page 27: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

A request for help…

• oss-fuzz

• A Google fuzzing project

• Requires someone to sign a contributor agreement

Page 28: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Goal To convince you to look into using

AFL on your code

Page 29: XPDDS17: Using American Fuzzy Lop on the x86 Instruction Emulator - George Dunlap, Citrix

Questions

• http://lcamtuf.coredump.cx/afl/