Fuzzing File Systems via Two-Dimensional Input Space Exploration Wen - - PowerPoint PPT Presentation

fuzzing file systems via two dimensional input space
SMART_READER_LITE
LIVE PREVIEW

Fuzzing File Systems via Two-Dimensional Input Space Exploration Wen - - PowerPoint PPT Presentation

Fuzzing File Systems via Two-Dimensional Input Space Exploration Wen Xu, Hyungon Moon, Sanidhya Kashyap, Po-Ning Tseng and Taesoo Kim INTRODUCTION 3 INTRODUCTION FILE SYSTEMS 101 $ ls -l /mnt drwxrwxr-x bar -rw-rw-r- foo Disk image


slide-1
SLIDE 1

Wen Xu, Hyungon Moon, Sanidhya Kashyap, Po-Ning Tseng and Taesoo Kim

Fuzzing File Systems via Two-Dimensional Input Space Exploration

slide-2
SLIDE 2

INTRODUCTION

slide-3
SLIDE 3

INTRODUCTION

FILE SYSTEMS 101

3

Disk image

File system

mount OS

$ ls -l /mnt drwxrwxr-x bar

  • rw-rw-r—- foo

cat /mnt/foo "hello"

  • peration
slide-4
SLIDE 4

INTRODUCTION

FILE SYSTEM ATTACKS

4

crafted image

File system

OS

Privilege escalation

$ ls -l /mnt drwxrwxr-x ???

  • rw-rw-r—- ???

untrusted package

▸ Evil maid attacks ▸ Air-gapped APT attacks

Syscall payload

▸ Linux/macOS root exploits

slide-5
SLIDE 5

INTRODUCTION

COMPLEX FILE SYSTEMS

5

FS LoC Active ext4 50K ✓ XFS 140K ✓ Btrfs 130K ✓

File systems are hard to be bug-free!

slide-6
SLIDE 6

CHALLENGES

SOLUTION: FUZZING

6

Efficient Minimal knowledge Practical

slide-7
SLIDE 7

INTRODUCTION

FUZZING FILE SYSTEMS

7

Images File operations

mount execute

binary blob system calls

AFL LibFuzzer Trinity Syzkaller

slide-8
SLIDE 8

CHALLENGES

slide-9
SLIDE 9

CHALLENGES

FILE SYSTEM IMAGES REVISITED

▸ Particularly large

9

ext4: 2MB Btrfs: 100MB XFS: 16MB

▸ Highly structured (metadata) ▸ Checksums

Super Block Group Desc Bitmap Inode Table Data Dir Entry Data Journal Data

ext4 disk layout

slide-10
SLIDE 10

CHALLENGES

[1] FUZZING IMAGES AS BLOBS

▸ Particularly large

10

Huge IO costs on loading and saving testcases

▸ Highly structured ▸ Checksums

Metadata is rarely touched Corrupted after mutation

slide-11
SLIDE 11

CHALLENGES

OUR APPROACH: META-ONLY IMAGE FUZZING

▸ Locate and extract only metadata blocks for mutation ▸ Record checksum information for each metadata block

11

slide-12
SLIDE 12

CHALLENGES

OUR APPROACH

▸ Particularly large

12

Metadata occupies < 1%

▸ Highly structured

Only metadata is fuzzed Enough information for fixing

▸ Checksums

slide-13
SLIDE 13

CHALLENGES

FILE OPERATIONS REVISITED

13

File operations File objects

How to operate What to operate

The inter-dependence between file operations and files on an image

slide-14
SLIDE 14

CHALLENGES

[2] GENERATING FILE OPERATIONS BY SPECS

14

* open(filename, flag) * rename(filename, filename) * mkdir(filename) * unlink(filename) * read(fd, buffer, int) * write(fd, buffer, int) Static rules (definitions of syscalls) used by Syzkaller

slide-15
SLIDE 15

CHALLENGES

COUNTER EXAMPLE 1

15

mkdir(“A”); int fd = open(“A”, O_RDWR);

slide-16
SLIDE 16

CHALLENGES

COUNTER EXAMPLE 2

16

rename(“A”, “B”); int fd = open(“A”, O_RDWR); read(fd, buf, 1024);

slide-17
SLIDE 17

CHALLENGES

FILE OPERATIONS REVISITED

17

File operations File objects

How to operate What to operate

The inter-dependence between file operations and files on an image

slide-18
SLIDE 18

CHALLENGES

OUR APPROACH: CONTEXT-AWARE GENERATION

18

Syscall0 File Status0 File Status1

Seed image

Syscall1 File Status2

Emulate Generate

slide-19
SLIDE 19

CHALLENGES

[3] FUZZING OS MODULES WITH VMS

19

▸ Conventional file systems are in-kernel modules ▸ OS fuzzers fuzz with VMs ▸ Never reboot until a VM crashes

Performance Aging kernel

Unstable executions Hard-to-reproduce bugs

slide-20
SLIDE 20

CHALLENGES

OUR APPROACH: LIBOS-BASED OS FUZZING

20

▸ We use library OS to fuzz OS. ▸ A user application linked with a library OS invokes

syscalls in user space.

Run on the same host

▸ Coverage monitoring ▸ Testcase sharing

Fast reboot ~10ms

▸ Non-aging OSes and modules ▸ Stable executions ▸ PoCs debugging

slide-21
SLIDE 21

CHALLENGES

[4] FUZZING BOTH IMAGES AND SYSCALLS

21

No existing fuzzing platforms supports jointly fuzzing binary blobs and API calls!

We propose Janus, which co-ordinates fuzzing in two dimensions.

slide-22
SLIDE 22

RESULTS

JANUS FOUND BUGS

22

▸ We run Janus for 4 months against 8 file systems on 1

workstation.

▸ 90 unique bugs in total ▸ 62 confirmed unknown bugs ▸ 32 assigned CVEs ▸ During the period, Syzkaller found and fixed 8 bugs, and

  • nly one of them is missed by Janus.
slide-23
SLIDE 23

RESULTS

SELECTED BUGS

FS #0days/#critical #mount-only ext4 [*] 16 (12) 1 XFS 7 (2) Btrfs 8 (2) 5 F2FS 11 (5) 5 Overall 42 11

23

* ext4 developers responded most actively to our bug reports.

slide-24
SLIDE 24

JANUS

▸ A coverage-driven fuzzers that efficiently and effectively test

images and file operations in a joint manner.

slide-25
SLIDE 25

DESIGN

ARCHITECTURE OVERVIEW

25

Seed images Seed programs Image mutator Syscall fuzzer LibOS-based executor Corpus

cov+

Results

crash asset Fuzzing engine Seeds

slide-26
SLIDE 26

DESIGN

IMAGE MUTATOR

00 00 BB BB 00 00 FF FF

LibOS executor

mount and run a workload image compress mutate fix checksum release FF FF checksum 00 00 immutable (data) fix checksums

26

BB BB FF FF C8 BB FF FF C8 BB FC FC 00 00 C8 BB 00 00 FC FC

[*]

* We develop a specific image parser for each target file system.

slide-27
SLIDE 27

DESIGN

SYSCALL FUZZER

27

Relative path Type Xattrs

Live file objects

Stale file objects Opened fds Program

A testcase of Janus’ syscall fuzzer

slide-28
SLIDE 28

DESIGN

SYSCALL FUZZER

▸ Phase 1: Generate based on the context ▸ Mutating the argument of an existing syscall ▸ or Appending a newly generated syscall ▸ Phase 2: Emulate ▸ Updating the corresponding context

28

slide-29
SLIDE 29

DESIGN

SYSCALL FUZZER

29

Path (const char[]) Dir path File path New path

Argument generation

slide-30
SLIDE 30

DESIGN

SYSCALL FUZZER

30

New file Old path New path

Context update

  • pen()
  • pen()

New FD New path

link()

slide-31
SLIDE 31

DESIGN

CO-ORDINATE TWO FUZZERS

▸ First, Janus mutates images.

31

▸ Second, Janus launches its syscall fuzzer without new coverage.

The image indicates the initial state of a file system, and its impact on file operations gradually decreases. Introducing new syscalls quickly increases the mutation space and erase the changes from past syscalls.

slide-32
SLIDE 32

IMPLEMENTATION

slide-33
SLIDE 33

IMPLEMENTATION

IMPLEMENTATION OVERVIEW

▸ Janus is a variant of AFL. ▸ Image parsers (8 FSes) 5,229 lines of C++ ▸ Syscall fuzzing 4,300 lines of C++ ▸ Janus selects Linux Kernel Library as its LibOS solution. ▸ Syscall executor 851 lines of C++ ▸ KASAN support 804 lines of C ▸ Instrumentation for coverage 360 lines of C++ ▸ Janus supports fuzzing 8 file systems on Linux. ▸ ext4, XFS, btrfs, F2FS, GFS2, HFS+, ReiserFS, and vFAT ▸ Janus supports fuzzing 34 system calls for file operation.

33

slide-34
SLIDE 34

EVALUATION

▸ We compared with the state-of-the-art OS fuzzer, Syzkaller. ▸ We used the same machine, seed images and starting programs to fuzz 8

file systems.

slide-35
SLIDE 35

EVALUATION

LIBOS REPRODUCE MORE BUGS

FS Syzkaller (KVM) Janus ext4 0/3 196/196 (8) XFS v5 0/6 24/24 (2) Btrfs 0/0 1793/2054 (18) F2FS 0/1288 2390/2458 (28) Overall 0% 88% - 100%

#reproduced/#crashes (#unique) in 12 hours 35

slide-36
SLIDE 36

EVALUATION

JANUS FUZZES IMAGES BETTER

4000 5250 6500 7750 9000 0 1 2 3 4 5 6 7 8 9 101112

Janus(i) Syzkaller

▸ ext4 (16MB seed): 1.5x

3500 7000 10500 14000 0 1 2 3 4 5 6 7 8 9 101112

▸ XFS (16MB seed, checksum): 14.3x

Code coverage (12 hours) 36

slide-37
SLIDE 37

EVALUATION

JANUS FUZZES SYSCALLS BETTER

▸ ext4: 1.2x

2000 4000 6000 8000 0 1 2 3 4 5 6 7 8 9 101112

Janus(s) Syzkaller

Code coverage (12 hours)

2500 5000 7500 10000 0 1 2 3 4 5 6 7 8 9 101112

▸ XFS: 1.5x

37

slide-38
SLIDE 38

EVALUATION

FUZZING BOTH IS MORE EFFECTIVE

5000 10000 15000 20000 1 2 3 4 5 6 7 8 9 10 11 12

Janus Janus(i) Janus(s) Syzkaller

Code coverage (12 hours)

▸ Btrfs (128MB seed): 4.2x

38

slide-39
SLIDE 39

CONCLUSION

NOT ONLY MEMORY SAFETY BUGS ON LINUX

▸ We believe Janus is a practical one-stop solution for all kinds of

file system or even OS testing in the future.

▸ Janus is easy to be extended for ▸ Testing other types of file systems on other OSes ▸ FUSE ▸ Verified file systems ▸ Finding other types of bugs ▸ Crash consistency ▸ Semantic correctness ▸ Further work is supported by Google Faculty Research Award.

39

slide-40
SLIDE 40

THANKS

We will open source at https://github.com/sslab-gatech/janus