Knowledge Base for the Linux Kernel Ashvin Goel University of Toronto Progress report for the Advanced Host Level Surveillance (AHLS) project Dec 10, 2013.

Slides:



Advertisements
Similar presentations
Secure In-VM Monitoring Using Hardware Virtualization Monirul Sharif, Wenke Lee, Weidong Cui, and Andrea Lanzi Presented by Tyler Bletsch.
Advertisements

Ensuring Operating System Kernel Integrity with OSck By Owen S. Hofmann Alan M. Dunn Sangman Kim Indrajit Roy Emmett Witchel Kent State University College.
Lecture 16 Buffer Overflow modified from slides of Lawrie Brown.
Implementing an Untrusted Operating System on Trusted Hardware.
EXTENSIBILITY, SAFETY AND PERFORMANCE IN THE SPIN OPERATING SYSTEM B. Bershad, S. Savage, P. Pardyak, E. G. Sirer, D. Becker, M. Fiuczynski, C. Chambers,
Extensibility, Safety and Performance in the SPIN Operating System Presented by Allen Kerr.
Knowledge Base for the Linux Kernel Ashvin Goel University of Toronto Progress report for the Advanced Host Level Surveillance (AHLS) project May 2, 2013.
The Kernel Abstraction. Challenge: Protection How do we execute code with restricted privileges? – Either because the code is buggy or if it might be.
Chapter 6 Limited Direct Execution
Using Programmer-Written Compiler Extensions to Catch Security Holes Authors: Ken Ashcraft and Dawson Engler Presented by : Hong Chen CS590F 2/7/2007.
Stack-Based Buffer Overflows Attacker – Can take over a system remotely across a network. local malicious users – To elevate their privileges and gain.
Securing software by enforcing data-flow integrity Manuel Costa Joint work with: Miguel Castro, Tim Harris Microsoft Research Cambridge University of Cambridge.
Extensibility, Safety and Performance in the SPIN Operating System Brian Bershad, Stefan Savage, Przemyslaw Pardyak, Emin Gun Sirer, Marc E. Fiuczynski,
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
OS Spring’03 Introduction Operating Systems Spring 2003.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
1 RAKSHA: A FLEXIBLE ARCHITECTURE FOR SOFTWARE SECURITY Computer Systems Laboratory Stanford University Hari Kannan, Michael Dalton, Christos Kozyrakis.
Jiang Wang, Joint work with Angelos Stavrou and Anup Ghosh CSIS, George Mason University HyperCheck: a Hardware Assisted Integrity Monitor.
Fast Dynamic Binary Translation for the Kernel Piyus Kedia and Sorav Bansal IIT Delhi.
Software fault isolation with API integrity and multi-principal modules MIT CSAIL Yandong Mao, Haogang Chen (MIT CSAIL), Tsinghua University IIIS Dong.
Stack Management Each process/thread has two stacks  Kernel stack  User stack Stack pointer changes when exiting/entering the kernel Q: Why is this necessary?
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
CS252: Systems Programming Ninghui Li Final Exam Review.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Vulnerability-Specific Execution Filtering (VSEF) for Exploit Prevention on Commodity Software Authors: James Newsome, James Newsome, David Brumley, David.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Secure Virtual Architecture John Criswell, Arushi Aggarwal, Andrew Lenharth, Dinakar Dhurjati, and Vikram Adve University of Illinois at Urbana-Champaign.
Kenichi Kourai (Kyushu Institute of Technology) Takuya Nagata (Kyushu Institute of Technology) A Secure Framework for Monitoring Operating Systems Using.
G53SEC 1 Reference Monitors Enforcement of Access Control.
Extensibility, Safety and Performance in the SPIN Operating System Ashwini Kulkarni Operating Systems Winter 2006.
Eric Keller, Evan Green Princeton University PRESTO /22/08 Virtualizing the Data Plane Through Source Code Merging.
Three fundamental concepts in computer security: Reference Monitors: An access control concept that refers to an abstract machine that mediates all accesses.
A Survey of Dynamic Techniques for Detecting Device Driver Errors Olatunji Ruwase LBA Reading Group 18 th May 2010.
Architecture Support for OS CSCI 444/544 Operating Systems Fall 2008.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
CS533 Concepts of Operating Systems Jonathan Walpole.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Enhanced Operating System Security Through Efficient and Fine-grained Address Space Randomization Vikram Reddy Enukonda.
1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
SCALABLE EVOLUTION OF HIGHLY AVAILABLE SYSTEMS BY ABHISHEK ASOKAN 8/6/2004.
G53SEC 1 Reference Monitors Enforcement of Access Control.
EXTENSIBILITY, SAFETY AND PERFORMANCE IN THE SPIN OPERATING SYSTEM
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
Buffer Overflow Attack Proofing of Code Binary Gopal Gupta, Parag Doshi, R. Reghuramalingam, Doug Harris The University of Texas at Dallas.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Operating Systems Security
Processes and Virtual Memory
Full and Para Virtualization
Efficient software-based fault isolation Robert Wahbe, Steven Lucco, Thomas Anderson & Susan Graham Presented by: Stelian Coros.
Dynamic Taint Analysis for Automatic Detection, Analysis, and Signature Generation of Exploits on Commodity Software Paper by: James Newsome and Dawn Song.
Security Architecture and Design Chapter 4 Part 2 Pages 319 to 357.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
Introduction to Operating Systems Concepts
Computer System Structures
Introduction to Operating Systems
YAHMD - Yet Another Heap Memory Debugger
Protection and OS Structure
Introduction to Operating Systems
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
System Calls David Ferry CSCI 3500 – Operating Systems
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Return-to-libc Attacks
Presentation transcript:

Knowledge Base for the Linux Kernel Ashvin Goel University of Toronto Progress report for the Advanced Host Level Surveillance (AHLS) project Dec 10, 2013

Motivation 2  Goal is to detect attacks on operating system kernels  Protect kernel against vulnerable modules  E.g., module calls unexported function, overwrites kernel stack  Detect anomalous behavior of malicious modules  E.g., sound module calls exported network send function  Requires understanding module behavior  What modules do  What they should be allowed to do

Approach  Instrument all module related code at runtime using dynamic binary translation (DBT)  Rewrite binary module code on-the-fly during execution Operates at instruction granularity Provides complete control over program execution  Requires no module sources to be available  Building a system called Granary  Two key ideas  Add module and kernel interface wrappers Allows mediating all control transfers between kernel and modules  Verify memory accesses by modules using watchpoints Allows mediating all data accesses by modules 3

Overview of Granary  Add kernel and module wrappers and watchpoints  Granary starts at module wrapper  Granary stops at kernel wrapper  Minimal overhead when kernel is running  Wrappers allow adding arbitrary integrity checking instrumentation code  Watchpoints allow instrumenting data accesses 4 Kernel Granary Untrusted modules Application Untrusted modules Module wrapper Kernel wrapper enter exit Instrumented code Data watchpoint

Instrumenting Data Accesses 5  Goals  Require flexible, powerful data-centric instrumentation  Requirements  Allow instrumenting typed objects (not bytes of memory)  Low overhead  Scale to millions of objects

Approach 6  Address watchpoints  Instrument data accesses by mangling memory addresses  Triggers the invocation of a type-specific function when watched memory address is dereferenced to access object  Example  When a module (e.g., a file sytem module) accesses any inode, an inode-specific watchpoint function is invoked

Benefits of Approach 7  Support millions of object-granularity watchpoints  Addresses limitations of h/w watchpoints  Enables selective instrumentation  Data selectivity Type specific Allocator specific  Code selectivity kernel code vs. module code Single thread, function Context specific, e.g., in a critical section

Watchpoint Applications 8  Detecting buffer overflows  Detecting read-before-write bugs, double free bugs  Detecting memory leaks using garbage collector  Debugging usage bugs, e.g., RCU bugs  Enforcing fine-grained memory access policies

Design of Address Watchpoints  Taint memory addresses that point to objects  Relies on x86-64’s 48-bit address implementation  Taint in the address indexes metadata stored in a global object descriptor table  Embeds context-specific information, such as object type 0xFFFF FFFFA x7654 FFFFA Index into object descriptor table 9

Achieving Data Selectivity  Tainted addresses are “non-canonical”, which enables data selectivity  Approach 1: Take a trap and turn on instrumentation  Approach 2: Instrument every load/store operation with DBT and detect tainted addresses 10

Achieving Code Selectivity  Different instrumentation policies for different execution contexts  E.g. heavyweight instrumentation inside a critical section, lightweight outside  Switch between policies  Granary enables instrumentation code specialization at runtime 11

Using Address Watchpoints  Example: use a function wrapper to add watchpoint on dynamically allocated memory FUNCTION_WRAPPER(__kmalloc,(size_t size, gfp_t gfp), { void *ret = __kmalloc(size, gfp); if(is_valid_address(ret)) { add_watchpoint(ret, size); } return ret; }) 12

Using Address Watchpoints  Example: use a function wrapper to add watchpoint on dynamically allocated memory  Developer identifies address sources (e.g. allocators) FUNCTION_WRAPPER(__kmalloc,(size_t size, gfp_t gfp), { void *ret = __kmalloc(size, gfp); if(is_valid_address(ret)) { add_watchpoint(ret, size); } return ret; }) 13

Using Address Watchpoints  Example: use a function wrapper to add watchpoint on dynamically allocated memory  Developer identifies address sources (e.g. allocators)  Specifies object metadata for descriptor FUNCTION_WRAPPER(__kmalloc,(size_t size, gfp_t gfp), { void *ret = __kmalloc(size, gfp); if(is_valid_address(ret)) { add_watchpoint(ret, size); } return ret; }) 14

Using Address Watchpoints  Example: use a function wrapper to add watchpoint on dynamically allocated memory  Developer identifies address sources (e.g. allocators)  Specifies object metadata for descriptor  Adds watchpoint to address FUNCTION_WRAPPER(__kmalloc,(size_t size, gfp_t gfp), { void *ret = __kmalloc(size, gfp); if(is_valid_address(ret)) { add_watchpoint(ret, size); } return ret; }) 15

Runtime Execution  Trap on watched, non-canonical address Native Code (no DBT) Load A Load B 16

Runtime Instrumentation  Trap on watched, non-canonical address  Turn on instrumentation Native Code (no DBT) Load A Load B Instrumented Basic Block Check if A is tainted Call Analyze(A) Load Untainted(A) Check if B is tainted Call Analyze(B) Load Untainted(B) … 17

Runtime Instrumentation  Trap on watched, non-canonical address  Turn on instrumentation Native Code (no DBT) Load A Load B Instrumented Basic Block Check if A is tainted Call Analyze(A) Load Untainted(A) Check if B is tainted Call Analyze(B) Load Untainted(B) … Back to native code 18

Evaluation  Goal: Measure CPU overhead of selective instrumentation  Preliminary evaluation with a microbenchmark  Data-centric instrumentation on objects primarily accessed by the Ext3 file system module  Ran iozone file system benchmark  We mounted Ext3 file system on a 2 GB ramdisk  Buffer cache disabled 19

20  Watched roughly 30% of all object accesses to Ext3 allocated objects  8% average overhead Native execution Address Watchpoints

Current Status 21  Building a system for Linux called Granary that  Instruments arbitrary, binary Linux kernel modules  Uses type-specific wrappers for interposing on all code crossing the kernel/module boundary  Granary uses address watchpoints for interposing on data accesses  Enables highly selective code+data-centric instrumentation  Preliminary evaluation shows low overhead  Leverages instrumentation selectivity  Tainted addresses are easy to detect

Future Work 22  Improvements in instrumentation performance  Faster watchpoints  Faster instrumentation tools  Build watchpoint-based tools  Working on detecting 1) buffer overflows, 2) use-after-free bugs, 3) uninitialized read, 4) memory leaks, 5) RCU bugs …  Understanding module behavior Is the module passing arguments or returning values of wrong type? What data is owned/can be modified, referenced, called by modules What functions can the kernel call on behalf of modules?

Thanks! 23  Questions

Entering/Exiting Instrumentation 24  How should intrumentation be started?  Need to understand how we exit instrumentation  Exit instrumention occurs when:  The module calls a kernel function  The module returns to the kernel  The module is interrupted

Exiting Instrumentation 25  Consider case when a module calls a kernel function  Granary exits instrumentation  Problem  Arguments to kernel functions can contain pointers to module functions  Granary needs to regain control when those pointers are executed  Solution  Route control through a kernel function wrapper  Wrapper changes pointers to module functions into pointers to shadow module functions

Wrappers 26  A pointer to a struct device_driver is passed as an argument to a kernel function int (*probe); int (*remove); int (*shutdown); int (*suspend); int (*resume); struct device_driver e1000_probe: push %rbp mov %rsp, %rbp … e1000_remove: … e1000_shutdown: … shadow(e1000_probe): attach_granary instrumented(e1000_probe)

Automatic Wrapper Generation 27  Static analysis of the kernel is used to automatically generate type-specific wrappers  Exposes rich type information for security enforcement struct device_driver {... int (*probe)(... ); int (*remove)(... ); void (*shutdown)(... ); int (*suspend)(... ); int (*resume)(... );... const struct dev_pm_ops *pm;... }; TYPE_WRAPPER(struct device_driver, { PRE { WRAP_FUNC(arg.probe); WRAP_FUNC(arg.remove); WRAP_FUNC(arg.shutdown); WRAP_FUNC(arg.suspend); WRAP_FUNC(arg.resume); } POST { WRAP_RECURSIVE(arg.pm); } })

Module Behavior  Kernel modules call core kernel functions, core kernel calls module functions  Kernel modules share data with kernel, e.g., stack 28 // Kernel code void spin_lock_init(spinlock_t *lock) { lock->v = 0; } // Correct module code spinlock_t mylock; spin_lock_init(&mylock); Module code Kernel memory Module memory Core kernel code

Attack  Attacker tricks kernel to overwrite UID to root  Similarly, attacker can trick kernel to call kernel functions of their choosing 29 // Kernel code void spin_lock_init(spinlock_t *lock) { lock->v = 0; } Module code Kernel memory Module memory Core kernel code // Malicious module code spin_lock_init(&thread->uid); Thread UID Privilege escalation!

Challenges in Rootkit Defenses  Kernel APIs are not written defensively  Assume modules obey implicit rules  Do not check arguments, permissions, etc.  Modules cannot be trusted to follow rules  Module can trick kernel into performing unexpected actions  Need to enforce rules for kernel API  Analogy: system call code assumes nothing about caller, checks every assumption  What are these rules? 30

Integrity Rules  Software fault isolation  Module can call module functions only  Module can write its own data  Module can invoke only exported kernel functions  Argument and return value integrity  Arguments, return values passed to kernel/module are owned or can be referenced by module  Callback integrity  Kernel invokes callback function only if the module could have invoked callback directly 31

Enforcing Integrity  Need to analyze modules  What arguments are owned by modules  What arguments can be referenced by modules  What functions can be called by modules  Challenges  Complex kernel interface 1000s of exported kernel functions Lots of complex arguments to these functions  Sensitive kernel data exposed to modules Global variables, stack, macros, etc.  Modules can be distributed as binaries 32

Expected Results 33  We will perform experimentation with the Linux kernel knowledge base to determine:  Whether it detects known rootkits  Whether it generates false alarms for benign modules  We plan to make the following available to the project as we build it:  All code for Granary  All code for analyzing and testing module behavior  Security policy knowledge base  All of this code will run on standard x86 machines, running a Linux kernel with some modifications for Granary

Focus of the Project 34  Instrument binary kernel modules at runtime  No need for module source code to be available  Any module code can be instrumented  Benefits  Kernel drivers and modules tend to be more buggy  More efficient to monitor modules than entire kernel  Adding more comprehensive instrumentation is feasible  Boundary between core kernel and modules is better defined, and hence is likely to provide us with rich information for the knowledge base

Importance of Kernel Security  Kernel is fully privileged  Kernel compromises are devastating  Remote attacker takes control of (i.e., owns) machine  Local user gets root privilege  Vulnerabilities in the Linux kernel  Vulnerabilities are routinely discovered in Linux  CVE 2010: 145 vulnerabilities in Linux kernel 35

Attacking the Kernel 36  Gain limited access to the system  Exploit a known software vulnerability E.g., crack weak password, buffer overflow in user-level software  Escalate privileges to gain elevated access  Exploit vulnerability in privileged programs E.g., get root shell by targeting vulnerable setuid program  Using social engineering E.g., deceive user into installing malicious program  Take steps to continue accessing the system  Install kernel rootkit

Kernel Rootkits 37  A kernel exploit that is designed to hide its presence  May open backdoors, steal information or actively disable kernel-based defenses  Often installed using social engineering  Example: Sony rootkit In 2005, Sony provided a music player on Windows Player installed a kernel rootkit that limited the user’s ability to access a CD Unfortunately, other kernel malware then took advantage of a vulnerability in this rootkit When Sony attempted to uninstall its rootkit, it exposed users to an even more serious vulnerability

How do Kernel Rootkits Work? 38  Modern kernels allow installing third-party, untrusted modules to extend kernel functionality  Loaded on demand, e.g., when USB camera is plugged in  Executed with the same privileges as the core kernel  A kernel rootkit can either be  A malicious module, or  A benign, vulnerable module that has been subverted  After rootkit is installed, it can fully control the machine, because it runs with the highest privileges

Understanding Rootkits 39  A “perfect rootkit” is similar to a “perfect crime”: one that nobody realizes has taken place  Rootkits have complete access to kernel code & data  Install or modify other module or core kernel code  Replace system calls, disable page protection  Load code into user processes  Conceal running processes, installed modules, files  Tamper with event logging facility  Bypass tools that monitor system calls or file modifications because they can execute entirely in kernel context

Vulnerabilities in Linux Kernel  Many exploits attack kernel modules  67% of Linux kernel vulnerabilities (CVE 2010) 40

Security Threat  Module are buggy  Have unrestricted access to kernel data and code  Attacker can exploit bugs to mount attacks  Example  Buffer overflow  Set current UID to root Module code Kernel memory Thread UID Privilege escalation! Module memory 41

Existing Approaches  User-level drivers, microkernels  Type safe languages  Software fault isolation 42

User-Level Drivers  Bugs in modules don’t cause kernel exploits  Performance issues, e.g., fuse file systems  Porting effort is non-trivial write not possible User level Kernel memory Thread UID 43 Module code Process Module memory

Type-Safe Languages  Write kernel and modules in Java, C#  Attacker cannot synthesize references  No reference to UID object => cannot change UID  Most kernels are not written in type-safe language Module in Java Kernel memory Thread UID No reference Module memory 44

Software Fault Isolation (SFI)  SFI stops errant writes Module code Kernel memory Thread UID char *p = &thread->uid; sfi_check_memory(*p = 0); *p = 0; SFI Runtime void sfi_check_memory(p) { if p not in “module memory” stop_module(); } Module memory Cannot bypass SFI check 45

Challenges 46  Comprehensive module instrumentation  No overhead on non-module kernel code  Interrupt handling  Modules can be interrupted at any point  Interrupts are handled by kernel code Need to detach instrumentation to execute the kernel’s interrupt handler natively, and re-attach instrumentation on return  Multi-core instrumentation  Instrumented module can be rescheduled to another CPU  Code cache is per-CPU, needs to be setup correctly

System Overview  Add kernel and module wrappers during module loading and linking  Granary starts at module wrapper  Granary stops at kernel wrapper  No overhead when kernel is running  Wrappers allow adding arbitrary integrity checking instrumentation code 47 Kernel Granary Untrusted modules Application Untrusted modules Module wrapper Kernel wrapper enter exit Instrumented code

Entering/Exiting Instrumentation 48  How should intrumentation be started?  Need to understand how we exit instrumentation  Exit instrumention occurs when:  The module calls a kernel function  The module returns to the kernel  The module is interrupted

Exiting Instrumentation 49  Consider case when a module calls a kernel function  Granary exits instrumentation  Problem  Arguments to kernel functions can contain pointers to module functions  Granary needs to regain control when those pointers are executed  Solution  Route control through a kernel function wrapper  Wrapper changes pointers to module functions into pointers to shadow module functions

Exiting Instrumentation - Example 50  A pointer to a struct device_driver is passed as an argument to a kernel function int (*probe); int (*remove); int (*shutdown); int (*suspend); int (*resume); struct device_driver e1000_probe: push %rbp mov %rsp, %rbp … e1000_remove: … e1000_shutdown: … shadow(e1000_probe): attach_granary instrumented(e1000_probe)

Static Analysis 51  Static analysis of the kernel is used to automatically generate type policies  Static code generation automatically creates kernel function wrappers from type policies  Exposes rich type information for security enforcement struct device_driver {... int (*probe)(... ); int (*remove)(... ); void (*shutdown)(... ); int (*suspend)(... ); int (*resume)(... );... const struct dev_pm_ops *pm;... }; TYPE_WRAPPER(struct device_driver, { PRE { WRAP_FUNC(arg.probe); WRAP_FUNC(arg.remove); WRAP_FUNC(arg.shutdown); WRAP_FUNC(arg.suspend); WRAP_FUNC(arg.resume); } POST { WRAP_RECURSIVE(arg.pm); } })

Other Applications 52  Debugging  Detecting violations of data structure invariants  Out-of-bounds access  Testing  Fault injection  Guided control-flow

Architecture: mixed-mode execution Instrumented Mode Controlled by Granary Module code is dynamically translated to include instrumentation Instrumented code is stored in and executes from a code cache Native Mode Controlled by the kernel All non-module kernel code runs natively 53

Instrumented Mode Basic blocks of module code are dynamically translated and stored in a code cache. 54

Instrumented Mode When execution reaches the end of a basic block, the next block is looked up in the code cache and linked. 55

Instrumented Mode If the next basic block is not in the code cache, then Granary dynamically caches, stores, and links that basic block. transferring to module? YESNO 56

Instrumented Mode If the next basic block is not in the code cache, then Granary dynamically caches, stores, and links that basic block. 57

Instrumented Mode If the last basic block ends in a control-flow transfer to the kernel, then detach. transferring to module? NO Detach Switch to Native Mode YES 58