30
kGuard Lightweight Kernel Protection against Return-to-user Attacks Vasileios P. Kemerlis Georgios Portokalidis Angelos D. Keromytis Network Security Lab Department of Computer Science Columbia University New York, NY, USA USENIX Security Symposium [email protected] (Columbia University) kGuard Usenix Security ’12 1 / 30

kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

kGuardLightweight Kernel Protection against Return-to-user Attacks

Vasileios P. Kemerlis Georgios PortokalidisAngelos D. Keromytis

Network Security LabDepartment of Computer Science

Columbia UniversityNew York, NY, USA

USENIX Security Symposium

[email protected] (Columbia University) kGuard Usenix Security ’12 1 / 30

Page 2: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Outline

OverviewKernel securityProblem statementContribution

Design & ImplementationInline monitoringCode diversificationImplementation

Results & DiscussionTestbedE↵ectivenessPerformanceSummary

[email protected] (Columbia University) kGuard Usenix Security ’12 2 / 30

Page 3: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Overview Kernel security

Kernel vulnerabilitiesCurrent state of a↵airs

0

20

40

60

80

100

120

140

160

180

200

220

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

# of

vul

nera

bilit

ies

Year

Kernel vulnerabilities per year

Linux alone had � 140 assigned CVE numbers in 2010!

I 12 privilege escalation exploits

I 13 bugs that can be triggered remotely

I kernel memory leaks, auth{entication, orization} bypass, DoS, ...

[email protected] (Columbia University) kGuard Usenix Security ’12 3 / 30

Page 4: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Overview Kernel security

Kernel vulnerabilities (cont’d)Why care?

Kernel attacks are becoming more common

I High-value asset ! Most privileged piece of code• Responsible for the security of the OS ! Reference monitor

I Large attack surface (syscalls, device drivers, pseudo fs, ...)• Big codebase ! More bugs?

I Exploiting privileged userland processes has become harder !canaries+ASLR+NX+Fortify source+RELRO+BIND NOW+Ptr. mangle+, ...

[email protected] (Columbia University) kGuard Usenix Security ’12 4 / 30

Page 5: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Overview Problem statement

Return-to-user (ret2usr) attacksAttacking the Core

Traditional kernel exploitation

I Kernel-level memory corruption code-injection, code-reuse (ROP)

Return-to-user (ret2usr) attacks

I Kernel-level memory corruption run userland code

I Attacks against OS kernels that have shared address spacesI Overwrite kernel-level control data with user space addresses

• return addresses• dispatch tables• function pointers

I Facilitate privilege escalation (arbitrary user-provided code execution)7 http://www.exploit-db.com/exploits/20201/ released last week!

[email protected] (Columbia University) kGuard Usenix Security ’12 5 / 30

Page 6: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Overview Problem statement

Return-to-user (ret2usr) attacksWhy do they work?

Weak kernel/userland separation

I Shared process/kernel model ! Performance

I Kernel entrance is hardware-assisted ! The opposite is not true

I While executing kernel code complete and unrestricted access to allmemory and system objects is available

I The attacker completely controls user space memory(both in terms of contents & perms.)

[email protected] (Columbia University) kGuard Usenix Security ’12 6 / 30

Page 7: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Overview Contribution

kGuardVersatile & lightweight protection against ret2usr

I Defensive mechanism that builds upon inline monitoring andcode diversification

I Cross-platform solution that enforces address space separationbetween user and kernel space

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

I Non-intrusive & low overhead

Goal

X Cast a realistic threat ine↵ective

[email protected] (Columbia University) kGuard Usenix Security ’12 7 / 30

Page 8: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Design & Implementation Inline monitoring

kGuard designControl-flow assertions (key technology #1)

I Compact, inline guards injected atcompile time

• Two flavors ! CFA

R

& CFA

M

I Placed before every exploitable controltransfer

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

kernel

.textkernel

.text

Original code

branch

branch

Instrumented codebranch

branch

CFA

CFA

I Verify that the target address of an indirect branch is always insidekernel space

I If the assertion is true, execution continues normally; otherwise,control is transfered to a runtime violation handler

[email protected] (Columbia University) kGuard Usenix Security ’12 8 / 30

Page 9: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Design & Implementation Inline monitoring

kGuard design (cont’d)CFA

R

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)

[email protected] (Columbia University) kGuard Usenix Security ’12 9 / 30

Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Page 10: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Design & Implementation Inline monitoring

kGuard design (cont’d)CFA

M

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)

[email protected] (Columbia University) kGuard Usenix Security ’12 10 / 30

Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Page 11: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Design & Implementation Inline monitoring

kGuard design (cont’d)CFA

M

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 CFA

M

guard (x86 Linux)

[email protected] (Columbia University) kGuard Usenix Security ’12 11 / 30

Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Vasileios P. Kemerlis
Page 12: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Design & Implementation Code diversification

Bypassing kGuardBypass trampolines

I CFAs provide reliable protection i↵ the attackerpartially controls a computed branch target

I What about vulnerabilities that allow overwritingkernel memory with arbitrary values?

Attacking kGuard

1. Find two computed branch instructions whoseoperands can be reliably overwritten

2. Overwrite the value (branch target) of the first withthe address of the second

3. Overwrite the value of the second with a user-spaceaddress

.textkernel

KER

NEL

SPA

CE

USER

LAND

pwn3

d!

branch

branch

CFA

CFA2

1

[email protected] (Columbia University) kGuard Usenix Security ’12 12 / 30

Page 13: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Design & Implementation Code diversification

CountermeasuresCode inflation (key technology #2)

IReshape kernel’s text area

• Insert a random NOP sled at the beginning of the text• Inject a NOP sled of random length before every CFA

I Each NOP sled “pushes” further instructions at highermemory addresses (cumulative e↵ect)

Result

I The location of each indirect control transfer israndomized (per build)

Important assumption

I Kernel text & symbols secrecy(proper fs privs., dmesg, /proc)

kernel.text

USERLAND

KERN

EL S

PACE

CFA1

CFA

branch2

NOPsled

branch

NOPsled

[email protected] (Columbia University) kGuard Usenix Security ’12 13 / 30

Page 14: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Design & Implementation Code diversification

Countermeasures (cont’d)CFA motion (key technology #3)

I Relocate the injected guards & protected branches

I Make it harder for an attacker to find a bypass trampoline

NOPsled

NOPsled

1st relocation

sled

NOPsled

NOP

2nd relocation

relo

catio

n w

indo

w

.textkernel

.textkernel

NOPsled

CFA

CFA

CFA

.textkernel

.textkernel

.textkernel

.textkernel

Initial build

branch

branch

branch

[email protected] (Columbia University) kGuard Usenix Security ’12 14 / 30

Page 15: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Design & Implementation Implementation

ImplementationkGuard as a GCC plugin

I Implemented kGuard as a set of modifications to the pipeline of GCC(“de-facto” compiler for Linux, BSD, Android, ...)

I Back-end plugin ! ⇠ 1KLOC in C

*.m, *.mi

*.java

*.cxx, *.cpp*.cc, *.c++

*.c, *.i

*.F, *.FOR

*.s

Objective−C

Fortran

...

GENERICJava

C

C++

Middle−end

GIMPLE

GIMPLEHigh

GIMPLELow

GIMPLESSA

Back−end

RTL

Front−ends

...kGuard

(NOP & CFA)

[email protected] (Columbia University) kGuard Usenix Security ’12 15 / 30

Page 16: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Results & Discussion Testbed

Evaluating kGuardTestbed & methodology

I Single host• 2.66GHz quad core Xeon X5500• 24GB RAM

I Debian Linux v6 (“squeeze” with kernel v2.6.32)

I GCC v4.5.1, MySQL v5.1.49, Apache v2.2.16

I NOP sled size [0 – 20]

I 10 repetitions of the same experiment

I 95% confidence intervals (error bars)

[email protected] (Columbia University) kGuard Usenix Security ’12 16 / 30

Page 17: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Results & Discussion E↵ectiveness

E↵ectiveness

Vulnerability Description ImpactExploit

x86 x86-64

CVE-2009-1897 NULL function pointer 2.6.30–2.6.30.1p

—CVE-2009-2692 NULL function pointer 2.6.0–2.6.30.4

p p

CVE-2009-2908 NULL data pointer 2.6.31p p

CVE-2009-3547 data pointer corruption 2.6.32-rc6p p

CVE-2010-2959 function pointer overwrite 2.6.{27.x, 32.x, 35.x}p

—CVE-2010-4258 function pointer overwrite 2.6.36.2

p p

EDB-15916 NULL function pointer over-write

2.6.34p p

CVE-2009-3234 ret2usr via kernel stack bu↵eroverflow

2.6.31p p

p: detected and prevented successfully —: exploit unavailable

[email protected] (Columbia University) kGuard Usenix Security ’12 17 / 30

Page 18: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Results & Discussion Performance

Macro benchmarks

App. (Bench.) x86 x86-64

Kernel build (time(1)) 1.03% 0.93%MySQL (sql-bench) 0.92% 0.85%Apache (ApacheBench) 0.01% 0.01%

Impact on real-life applications: 1%

[email protected] (Columbia University) kGuard Usenix Security ’12 18 / 30

Page 19: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Results & Discussion Performance

Micro benchmarks (1/3)Bandwidth (lmbench)

0

1000

2000

3000

4000

5000

6000

7000

8000

Socket (PF_INET)

Socket (PF_UNIX)

Pipe

Band

wid

th (M

B/s)

x86

vanillakGuard

0

1000

2000

3000

4000

5000

6000

7000

8000

Socket (PF_INET)

Socket (PF_UNIX)

Pipe

Band

wid

th (M

B/s)

x86-64

vanillakGuard

Arch. Slowdownx86 3.2% – 10% (avg. 6%)

x86-64 5.25% – 9.27% (avg. 6.6%)

[email protected] (Columbia University) kGuard Usenix Security ’12 19 / 30

Page 20: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Results & Discussion Performance

Micro benchmarks (2/3)Latency x86 (lmbench)

x86

0

0.1

0.2

0.3

0.4

0.5

syscall()read()

write()fstat()

sigaction()

Late

ncy

(µse

c)vanilla

kGuard

0

1

2

3

4

5

6

7

8

9

10

11

select ()-10 fds

select()-100 fds

open/close()socket()

pipe()

Late

ncy

(µse

c)

vanillakGuard

Overhead2.7% – 23.5% (avg. 11.4%)

[email protected] (Columbia University) kGuard Usenix Security ’12 20 / 30

Page 21: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Results & Discussion Performance

Micro benchmarks (3/3)Latency x86-64 (lmbench)

x86-64

0

0.1

0.2

0.3

syscall()read()

write()fstat()

sigaction()

Late

ncy

(µse

c)vanilla

kGuard

0

1

2

3

4

5

6

7

8

9

10

11

select ()-10 fds

select()-100 fds

open/close()socket()

pipe()

Late

ncy

(µse

c)

vanillakGuard

Overhead2.9% – 19.1% (avg. 10.3%)

[email protected] (Columbia University) kGuard Usenix Security ’12 21 / 30

Page 22: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Results & Discussion Performance

Translation overhead

Arch. Build time (inc.) Size (inc.)x86 0.3% 3.5%/0.43%

x86-64 0.05% 5.6%/0.56%

I Additional time needed for CFA-based confinement & Code inflation

I Kernel image/modules size increase

[email protected] (Columbia University) kGuard Usenix Security ’12 22 / 30

Page 23: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Results & Discussion Summary

Conclusion

kGuard

I Versatile & lightweight mechanism against ret2usr attacks

I Builds upon inline monitoring and code diversificationI Cross-platform solution

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

I Non-intrusive & low overhead• 11.4%/10.3% on syscall & I/O latency on x86/x86-64• ⇠ 6% on IPC bandwidth• 3.5% – 5.6% size overhead• 1% on real-life applications

Try it!

http://www.cs.columbia.edu/~vpk/research/kguard/

[email protected] (Columbia University) kGuard Usenix Security ’12 23 / 30

Page 24: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Bonus Slides

[email protected] (Columbia University) kGuard Usenix Security ’12 24 / 30

Page 25: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Current defencesIssues & limitations (1/2)

Restricting mmap

I Restricts the ability to map the first pages of the address space(typically 4KB – 64KB)

I Mitigation strategy ! Protection scheme against NULL ptr. exploits

I Does not protect against exploits that redirect control to memorypages above the forbidden region

I Breaks compatibility with applications that rely on having access tolow logical addresses

I Circumvented repeatedly

[email protected] (Columbia University) kGuard Usenix Security ’12 25 / 30

Page 26: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Current defences (cont’d)Issues & limitations (2/2)

PaX UDEREF/KERNEXEC

I Patch for hardening the Linux kernel against user space pointerdereferences & code execution

I In x86 it relies on memory segmentation

I In x86-64, where segmentation is not available, it resorts in user spaceremapping (temporarily)

I Requires patching, works only on x86/x86-64, incurs non-negligibleperformance overhead

[email protected] (Columbia University) kGuard Usenix Security ’12 26 / 30

Page 27: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Macro benchmarks

I Kernel build (time(1))

Arch. PaX (inc.) kGuard (inc.)x86 1.26% 1.03%

x86-64 2.89% 0.93%

I MySQL (sql-bench)

Arch. PaX (inc.) kGuard (inc.)x86 1.16% 0.92%

x86-64 2.67% 0.85%

I Apache (ApacheBench)

I PaX: 0.01% – 1.27%I kGuard: 0.01%

[email protected] (Columbia University) kGuard Usenix Security ’12 27 / 30

Page 28: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Micro benchmarks (1/3)Bandwidth (lmbench)

Arch. PaX kGuardx86 19.9% – 58.8% (avg. 37%) 3.2% – 10% (avg. 6%)

x86-64 21.7% – 78% (avg. 42.8%) 5.25% – 9.27% (avg. 6.6%)

0

1000

2000

3000

4000

5000

6000

7000

8000

Socket (PF_INET)

Socket (PF_UNIX)

Pipe

Band

wid

th (M

B/s)

x86

vanillaPaX

kGuard

0

1000

2000

3000

4000

5000

6000

7000

8000

Socket (PF_INET)

Socket (PF_UNIX)

Pipe

Band

wid

th (M

B/s)

x86-64

vanillaPaX

kGuard

[email protected] (Columbia University) kGuard Usenix Security ’12 28 / 30

Page 29: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Micro benchmarks (2/3)Latency x86 (lmbench)

PaX kGuard5.6% – 257% (avg. 84.5%) 2.7% – 23.5% (avg. 11.4%)

x86

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

syscall()read()

write()fstat()

sigaction()

Late

ncy

(µse

c)

vanillaPaX

kGuard

0 1 2 3 4 5 6 7 8 9

10 11 12 13 14

select ()-10 fds

select()-100 fds

open/close()socket()

pipe()

Late

ncy

(µse

c)

vanillaPaX

kGuard

[email protected] (Columbia University) kGuard Usenix Security ’12 29 / 30

Page 30: kGuard - Lightweight Kernel Protection against Return-to ... · I Patch for hardening the Linux kernel against user space pointer dereferences & code execution I In x86 it relies

Micro benchmarks (3/3)Latency x86-64 (lmbench)

PaX kGuard19% – 531% (avg. 172.2%) 2.9% – 19.1% (avg. 10.3%)

x86-64

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

syscall()read()

write()fstat()

sigaction()

Late

ncy

(µse

c)

vanillaPaX

kGuard

0 1 2 3 4 5 6 7 8 9

10 11 12 13 14

select ()-10 fds

select()-100 fds

open/close()socket()

pipe()

Late

ncy

(µse

c)

vanillaPaX

kGuard

[email protected] (Columbia University) kGuard Usenix Security ’12 30 / 30