Trinity A Linux kernel fuzz tester.

Similar documents
Fault Injection in System Calls

Perf: From Profiling to Kernel Mobile Threat Response Team

Applications of. Virtual Memory in. OS Design

Virtual Memory: Systems

Lab 09 - Virtual Memory

Outline. 1 Details of paging. 2 The user-level perspective. 3 Case study: 4.4 BSD 1 / 19

CMSC 412 Project #4 Virtual Memory Due Friday April 11, 2014, at 5:00pm

API 퍼징을통한취약점탐지 카이스트 차상길

Processes and Threads

CMPSC 311 Exam 2. March 27, 2015

Dissecting a 17-year-old kernel bug

Princeton University. Computer Science 217: Introduction to Programming Systems. Dynamic Memory Management

ECE 650 Systems Programming & Engineering. Spring 2018

File Systems: Consistency Issues

ECEN 449 Microprocessor System Design. Review of C Programming. Texas A&M University

Tutorial 1: C-Language

CSCE 548 Building Secure Software Dirty COW Race Condition Attack

CAN STRACE MAKE YOU FAIL?

System Calls and Signals: Communication with the OS. System Call. strace./hello. Kernel. Context Switch

ECEN 449 Microprocessor System Design. Review of C Programming

CSE 124 Discussion Section Sockets Programming 10/10/17

Princeton University Computer Science 217: Introduction to Programming Systems. Dynamic Memory Management

Introduction to Linux, for Embedded Engineers Tutorial on Virtual Memory. Feb. 22, 2007 Tetsuyuki Kobayashi Aplix Corporation. [translated by ikoma]

Foundations of Computer Systems

CLIENT-SIDE PROGRAMMING

libnetfilter_log Reference Manual

Virtual Memory. Alan L. Cox Some slides adapted from CMU slides

TIP675-SW-82. Linux Device Driver. 48 TTL I/O Lines with Interrupts Version 1.2.x. User Manual. Issue November 2013

TCP: Three-way handshake

Page Which had internal designation P5

Having fun with apple s IOKit. Ilja van sprundel

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

Project 2-1 User Programs

User Programs. Computer Systems Laboratory Sungkyunkwan University

The Embedded I/O Company TIP700-SW-82 Linux Device Driver User Manual TEWS TECHNOLOGIES GmbH TEWS TECHNOLOGIES LLC

1 Do not confuse the MPU with the Nios II memory management unit (MMU). The MPU does not provide memory mapping or management.

Memory management. Johan Montelius KTH

Intel P The course that gives CMU its Zip! P6/Linux Memory System November 1, P6 memory system. Review of abbreviations

TDDB68 Lesson 2 Pintos Assignments 3 & 4. Mattias Eriksson 2010 (or

Operating systems. Lecture 9

P6 memory system P6/Linux Memory System October 31, Overview of P6 address translation. Review of abbreviations. Topics. Symbols: ...

lpengfei Ding & Chenfu Bao lsecurity Researcher & Baidu X-Lab lfocused on Mobile, IoT and Linux kernel security

CS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016

CSC C69: OPERATING SYSTEMS

Virtual Memory: Systems

Memory Mapping. Sarah Diesburg COP5641

POSIX Shared Memory. Linux/UNIX IPC Programming. Outline. Michael Kerrisk, man7.org c 2017 November 2017

PROJECT 2 - MEMORY ALLOCATOR Computer Systems Principles. October 1, 2010

Other array problems. Integer overflow. Outline. Integer overflow example. Signed and unsigned

A Client-Server Exchange

Processes. Dr. Yingwu Zhu

Final Exam, Spring 2012 Date: May 14th, 2012

Operating System Labs. Yuanbin Wu

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

Lecture 24. Thursday, November 19 CS 375 UNIX System Programming - Lecture 24 1

MoonShine: Optimizing OS Fuzzer Seed Selection with Trace Distillation. Shankara Pailoor, Andrew Aday, Suman Jana Columbia University

Scaling CQUAL to millions of lines of code and millions of users p.1

EL2310 Scientific Programming

Changelog. Corrections made in this version not in first posting: 1 April 2017: slide 13: a few more %c s would be needed to skip format string part

Linux TCP Bind Shell from Scratch with Intel x86 Assembly

Inside ptmalloc2. Peng Xu Sep 14, 2013

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Process Address Spaces and Binary Formats

Ports under 1024 are often considered special, and usually require special OS privileges to use.

My malloc: mylloc and mhysa. Johan Montelius HT2016

Huawei Frame Buffer Driver Arbitrary Memory Write

Shared Memory Memory mapped files

CSE 120 Principles of Operating Systems

MMAP AND PIPE. UNIX Programming 2015 Fall by Euiseong Seo

Processes COMPSCI 386

Project 2 Overview: Part A: User space memory allocation

Contiguous memory allocation in Linux user-space

Memory Mapped I/O. Michael Jantz. Prasad Kulkarni. EECS 678 Memory Mapped I/O Lab 1

Design Overview of the FreeBSD Kernel CIS 657

Signal Example 1. Signal Example 2

CSE 306/506 Operating Systems Process Address Space. YoungMin Kwon

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

Intel P6 (Bob Colwell s Chip, CMU Alumni) The course that gives CMU its Zip! Memory System Case Studies November 7, 2007.

BINDER THE ANDROID IPC FRAMEWORK. Antoine 'xdbob' Damhet. July 15, 2016

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018

Optimizing Dynamic Memory Management

Session NM056. Programming TCP/IP with Sockets. Geoff Bryant Process software

Lecture 7. Followup. Review. Communication Interface. Socket Communication. Client-Server Model. Socket Programming January 28, 2005

Architecture and Drivers for Smartphones Introduction Labo 2

SUPPORTING NATIVE PTHREADS IN SYSCALL EMULATION MODE BRANDON POTTER JUNE 14 TH, 2015

CS61, Fall 2012 Midterm Review Section

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Asynchronous Events on Linux

Pentium/Linux Memory System March 17, 2005

ECE 598 Advanced Operating Systems Lecture 10

Linux Kernel Futex Fun: Exploiting CVE Dougall Johnson

Exploiting Concurrency Vulnerabilities in System Call Wrappers

A Socket Example. Haris Andrianakis & Angelos Stavrou George Mason University

bytes per disk block (a block is usually called sector in the disk drive literature), sectors in each track, read/write heads, and cylinders (tracks).

sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Federico Reghenzani

C Structures in Practice

Recitation Processes, Signals,UNIX error handling

EECS 482 Introduction to Operating Systems

CSC369 Lecture 2. Larry Zhang

BACKGROUND & TWI_CLKDIV

Transcription:

Trinity A Linux kernel fuzz tester. Presented by Dave Jones Red Hat. Slides license: CC-BY-SA

Syscall fuzzing.

A short history lesson.. Completely random. Circa 1991: Tsys. SVR4 Circa 2001: kg_crashme.

A short history lesson.. More intelligent. 2005: Ilja van Sprundel: 'sysfuzz' 2006: Clement LECIGNE: netusse 2006: 'scrashme' begins. Malformed, but good enough arguments.

A short history lesson.. Current state of the art. 2010: scrashme becomes 'Trinity'. 2010: Tavis Ormandy: iknowthis. A mix of malformed and plausible arguments.

How it works..

Trinity architecture. Give syscalls what they expect. Annotations. 'Address', 'length', 'file descriptor', 'filename'... Generic fuzz routines based on arg type. Generate 'things' on startup. Multi-process fuzzing using 'things'. Shared mmap between children.

Process model. Startup Main loop. Watchdog Child1 Child2 Child3 Child4

Watchdog. Keeps track of child progress. SIGKILL if 'stuck' Sanity check shm.

Types ARG_RANDOM_INT ARG_FD ARG_LEN ARG_ADDRESS ARG_NON_NULL_ADDRESS ARG_PID ARG_RANGE ARG_OP ARG_LIST ARG_RANDPAGE ARG_CPU ARG_PATHNAME ARG_IOVEC ARG_IOVECLEN ARG_SOCKADDR ARG_SOCKADDR_LEN

Syscall annotation example. struct syscall syscall_mmap = {.name = "mmap",.num_args = 6,.arg1name = "addr",.arg1type = ARG_ADDRESS,.arg2name = "len",.arg2type = ARG_LEN,.arg3name = "prot",.arg3type = ARG_LIST,.arg3list = {.num = 4,.values = { PROT_READ, PROT_WRITE, PROT_EXEC, PROT_SEM }, },.arg4name = "flags",.arg4type = ARG_OP,.arg4list = {.num = 2,.values = { MAP_SHARED, MAP_PRIVATE }, },.arg5name = "fd",.arg5type = ARG_FD,.arg6name = "off",.arg6type = ARG_LEN, };.sanitise = sanitise_mmap,

.sanitise routines. void sanitise_mmap(int childno) { /* no fd if anonymous mapping. */ if (shm->a4[childno] & MAP_ANONYMOUS) shm->a5[childno] = -1; } /* page align non-anonymous mappings. */ if (shm->a4[childno] & MAP_ANONYMOUS) shm->a6[childno] &= PAGE_MASK; else shm->a6[childno] = 0;

Interesting numbers. Instead of completely random numbers.. 0x00000000 0x00000001 Rand() % 256; 0x00000fff // 4095 0x00001000 // 4096 0x00001001 // 4097 0x00008000 0x0000ffff 0x00010000 0x40000000 0x7fffffff 0x80000000 0x80000001 0x8fffffff 0xc0000000 0xf0000000 0xff000000 0xffff0000 0xffffe000 0xffffff00 (rand() % 256); 0xffffffff;

More interesting numbers.. Addresses. 0x0000000100000000; 0x7fffffff00000000; 0x8000000000000000; 0xffffffff00000000; 0x0000000100000000 low; 0x00007fffffffffff; // x86-64 canonical addr end. 0x0000800000000000; // First x86-64 non-canonical addr 0xffff800000000000 (low << 4); // x86-64 canonical range 2 begin 0x7fffffff00000000 low; 0x8000000000000000 low; 0xffff880000000000 (low << 4); // x86-64 PAGE_OFFSET 0xffffffff80000000 (low & 0xffffff); // x86-64 kernel text 0xffffffffa0000000 (low & 0xffffff); // x86-64 module space 0xffffffffff600000 (low & 0x0fffff); // x86-64 vdso

Struct fabrication. Struct size parameter checks or EINVAL Sockaddr Needs knowledge of every protocol. static void gen_ipv4(unsigned long *addr, unsigned long *addrlen) { struct sockaddr_in *ipv4; ipv4 = malloc(sizeof(struct sockaddr_in)); if (ipv4 == NULL) return; } ipv4->sin_family = PF_INET; ipv4->sin_addr.s_addr = random_ipv4_address(); ipv4->sin_port = rand() % 65535; *addr = (unsigned long) ipv4; *addrlen = sizeof(struct sockaddr_in);

Self Protection. Check addresses when passing them to syscalls Blocking syscalls. Trapping signals.

Mo' problems..

Did I break the fuzzer? Proving absence of kernel bug after fix.

Over-sanitising void sanitise_tee(int childno) { if ((rand() % 10) > 0) { shm->a1[childno] = shm->pipe_fds[rand() % MAX_PIPE_FDS]; shm->a2[childno] = shm->pipe_fds[rand() % MAX_PIPE_FDS]; } }

Multiplexed syscalls. Socketcall calls other syscalls. Fcntl, others...

Avoiding OOM. Leaks! Tracking allocations.

Reproducability. Periodic reseeding. System state on startup. Corrupting state.

The results..

Results: Over 150 bugs found last year. +more by others. Bugs in new code found very quickly. Once discovered, bugs usually are repeatable Bugs tend to mask other bugs.

Types of bugs found. Not just syscall code! Lots of networking bugs. VM bugs. Drivers.

Types of bugs found. Very old bugs. (Oldest: Nov 1996. 2.1.8 setsockopt) only libfoo calls this mempolicy: (bug lifetime: 4+ years) VM under stress corner cases. page_alloc failures. OOM killer bugs.

Types of bugs found. CVE fix that needed a CVE. Error path memory leaks. Poor coverage tested code (Weirdo network protocols) Clearly untested code. Broken locks (ATM/BKL)

Types of bugs found. Hardware bugs. Marginal hardware shows up faults quickly under load. SMI handlers.

Types of bugs found. Trinity can break userspace too! trinity -c execve -V /bin

What next?

Next? Extending existing code New syscall support. More.sanitise routines. (currently just 10%) More struct fabrication. Lots to do here. More network protocol support. Most protos already done, but need improving. More flags for ARG_OP/ARG_LIST

Next? Syscall chains. Destructors. Root mode.

Ioctl Worst interface known to man. int ioctl(int fd, int request,...); The second argument is a device-dependent request code. The third argument is an untyped pointer to memory. request has encoded in it whether the argument is an in parameter or out parameter, and the size of the argument argp in bytes Need to annotate every ioctl. Pass down correct structures to right fd. Need to be very careful.

Demo time!

Questions? http://www.codemonkey.org.uk/ Contact: davej@redhat.com Slides license: CC-BY-SA