Dune: Safe User-level Access to Privileged CPU Features - - PowerPoint PPT Presentation

dune safe user level access to privileged cpu features
SMART_READER_LITE
LIVE PREVIEW

Dune: Safe User-level Access to Privileged CPU Features - - PowerPoint PPT Presentation

Dune: Safe User-level Access to Privileged CPU Features Adam Belay, Andrea Bi>au, Ali MashAzadeh, David Terei, David Mazires, and Christos Kozyrakis


slide-1
SLIDE 1

Dune: ¡Safe ¡User-­‑level ¡Access ¡to ¡ Privileged ¡CPU ¡Features ¡

Adam ¡Belay, ¡Andrea ¡Bi>au, ¡Ali ¡MashAzadeh, ¡David ¡Terei, ¡ David ¡Mazières, ¡and ¡Christos ¡Kozyrakis ¡ Stanford ¡University ¡

slide-2
SLIDE 2

The ¡power ¡of ¡privilege ¡

  • Privileged ¡CPU ¡features ¡are ¡fundamental ¡to ¡

kernels ¡

  • But ¡other, ¡compelling ¡uses: ¡

– Speed ¡up ¡garbage ¡collecAon ¡(Azul ¡C4) ¡

  • Page ¡tables ¡provide ¡memory ¡access ¡informaAon ¡

– Privilege ¡separaAon ¡within ¡a ¡process ¡(Palladium) ¡

  • MMU ¡hardware ¡isolates ¡compartments ¡

– Safe ¡naAve ¡code ¡in ¡web ¡browsers ¡(Xax) ¡

  • System ¡call ¡handler ¡intercepts ¡system ¡calls ¡

2 ¡

slide-3
SLIDE 3

Should ¡we ¡change ¡the ¡kernel? ¡

  • Problem: ¡stability ¡concerns, ¡challenging ¡to ¡

distribute, ¡composability ¡concerns ¡

CPU ¡ Kernel ¡ App ¡

Patch ¡ PTEs ¡ PGTBL ¡ Root ¡

3 ¡

slide-4
SLIDE 4

What ¡about ¡an ¡Exokernel? ¡

CPU ¡ Exokernel ¡ App ¡ Garbage ¡CollecAon ¡Library ¡OS ¡

  • Problem: ¡must ¡replace ¡enAre ¡OS ¡stack ¡

4 ¡

slide-5
SLIDE 5

What ¡about ¡a ¡virtual ¡machine? ¡

CPU ¡ Hypervisor ¡ JVM ¡ Browser ¡ GC ¡Kernel ¡ Linux ¡

  • Problem: ¡virtual ¡machines ¡have ¡strict ¡parAAoning ¡

5 ¡

slide-6
SLIDE 6

Dune ¡in ¡a ¡Nutshell ¡

  • Provide ¡safe ¡user-­‑level ¡access ¡to ¡privileged ¡CPU ¡features ¡
  • SAll ¡a ¡normal ¡process ¡in ¡all ¡ways ¡(POSIX ¡API, ¡etc) ¡
  • Key ¡idea: ¡leverage ¡exisAng ¡virtualizaAon ¡hardware ¡(VT-­‑x) ¡

CPU ¡ Kernel ¡ App ¡

Host ¡Mode ¡ Guest ¡Mode ¡

6 ¡

POSIX ¡

slide-7
SLIDE 7

CPU ¡ Kernel ¡ App ¡

Host ¡Mode ¡ Guest ¡Mode ¡ Guest ¡Page ¡ Table ¡ Host ¡Page ¡ Table ¡ PTEs ¡ PTEs ¡

  • SoluAon: ¡control ¡the ¡page ¡table ¡directly ¡within ¡

a ¡process ¡

Garbage ¡collecAon ¡in ¡Dune ¡

7 ¡

slide-8
SLIDE 8

Outline ¡

  • Overview ¡
  • Design ¡
  • EvaluaAon ¡

8 ¡

slide-9
SLIDE 9

Available ¡CPU ¡features ¡

9 ¡

  • Privilege ¡Modes ¡

– SYSRET, ¡SYSEXIT, ¡IRET ¡

  • Virtual ¡Memory ¡

– MOV ¡CRn, ¡INVLPG, ¡INVPCID ¡

  • ExcepAons ¡

– LIDT, ¡LTR, ¡IRET, ¡STI, ¡CLI ¡

  • SegmentaAon ¡

– LGDT, ¡LLDT ¡

slide-10
SLIDE 10

Dune ¡architecture ¡

CPU ¡ Kernel ¡ ¡ ¡ Process ¡ ¡ ¡

Host ¡Mode ¡ Guest ¡Mode ¡ libDune ¡ Dune ¡Module ¡

  • Host ¡mode ¡-­‑> ¡VMX ¡root ¡mode ¡on ¡Intel ¡
  • Normally ¡used ¡for ¡hypervisors ¡
  • In ¡Dune, ¡we ¡run ¡the ¡kernel ¡here ¡

– Reason: ¡need ¡access ¡to ¡VT-­‑x ¡instrucAons ¡

slide-11
SLIDE 11

Dune ¡architecture ¡

CPU ¡ Kernel ¡ ¡ ¡ Process ¡ ¡ ¡

Host ¡Mode ¡ Guest ¡Mode ¡ libDune ¡ Dune ¡Module ¡

  • Guest ¡mode ¡-­‑> ¡VMX ¡non-­‑root ¡mode ¡on ¡Intel ¡
  • Normally ¡used ¡by ¡the ¡guest ¡kernel ¡
  • In ¡Dune, ¡we ¡run ¡ordinary ¡processes ¡here ¡

– Reason: ¡need ¡access ¡to ¡privileged ¡features ¡

slide-12
SLIDE 12

Dune ¡architecture ¡

CPU ¡ Kernel ¡ ¡ ¡ Process ¡ ¡ ¡

Host ¡Mode ¡ Guest ¡Mode ¡ libDune ¡ Dune ¡Module ¡

  • Dune ¡Module ¡(~2500 ¡LOC) ¡

– Configures ¡and ¡manages ¡virtualizaAon ¡hardware ¡ – Provides ¡integraAon ¡with ¡the ¡rest ¡of ¡the ¡kernel ¡in ¡order ¡to ¡support ¡a ¡ process ¡abstracAon ¡ – Uses ¡Intel ¡VT-­‑x ¡(could ¡easily ¡add ¡AMD ¡SVM) ¡

slide-13
SLIDE 13

Dune ¡architecture ¡

CPU ¡ Kernel ¡ ¡ ¡ Process ¡ ¡ ¡

Host ¡Mode ¡ Guest ¡Mode ¡ libDune ¡ Dune ¡Module ¡

  • libDune ¡(~10,000 ¡LOC) ¡

– A ¡uAlity ¡library ¡to ¡help ¡applicaAons ¡manage ¡privileged ¡hardware ¡ features ¡ – Completely ¡untrusted ¡ – ExcepAon ¡handling, ¡system ¡call ¡handling, ¡page ¡allocator, ¡page ¡table ¡ management, ¡ELF ¡loader ¡

slide-14
SLIDE 14

Providing ¡a ¡process ¡abstracAon ¡

  • Memory ¡management ¡
  • System ¡calls ¡
  • POSIX ¡Signals ¡

14 ¡

slide-15
SLIDE 15

Memory ¡management ¡in ¡Dune ¡

Host-­‑Physical ¡(RAM) ¡ Kernel ¡ Page ¡ Table ¡ Host-­‑Virtual ¡ EPT ¡ Guest-­‑Physical ¡ User ¡ Page ¡ Table ¡ Guest-­‑Virtual ¡ Dune ¡Process ¡ Kernel ¡

15 ¡

  • Configure ¡the ¡EPT ¡to ¡

provide ¡process ¡memory ¡

  • User ¡programs ¡can ¡then ¡

directly ¡access ¡the ¡page ¡ table ¡

slide-16
SLIDE 16

System ¡calls ¡in ¡Dune ¡

  • SYSCALL ¡will ¡only ¡trap ¡back ¡into ¡the ¡process ¡
  • Use ¡VMCALL ¡(i.e. ¡a ¡hypercall) ¡to ¡perform ¡

normal ¡kernel ¡system ¡calls ¡

16 ¡

CPU ¡ Kernel ¡

Host ¡Mode ¡ Guest ¡Mode ¡

Process ¡

Syscall ¡ Handler ¡ Syscall ¡ Handler ¡ VMCALL ¡ SYSCALL ¡

slide-17
SLIDE 17

But ¡SYSCALL ¡is ¡sAll ¡useful ¡

  • Isolate ¡untrusted ¡code ¡by ¡running ¡it ¡in ¡a ¡less ¡

privileged ¡mode ¡(i.e. ¡ring ¡3 ¡on ¡x86) ¡

  • Leverage ¡the ¡‘supervisor’ ¡bit ¡in ¡the ¡page ¡table ¡

to ¡protect ¡memory ¡

17 ¡

Process ¡ (ring ¡0) ¡ Untrusted ¡ Code ¡ (ring ¡3) ¡

Syscall ¡ Handler ¡

slide-18
SLIDE 18

Signals ¡in ¡Dune ¡

  • Signals ¡should ¡only ¡be ¡delivered ¡to ¡ring ¡0 ¡
  • What ¡happens ¡if ¡process ¡is ¡in ¡ring ¡3? ¡
  • Possible ¡soluAon: ¡have ¡the ¡Dune ¡module ¡

manually ¡transiAon ¡the ¡process ¡to ¡ring ¡0 ¡

– Works ¡but ¡slow ¡and ¡somewhat ¡complex ¡

  • Our ¡soluAon: ¡deliver ¡signals ¡as ¡injected ¡

interrupts ¡

– Hardware ¡automaAcally ¡switches ¡to ¡ring ¡0 ¡ – Can ¡use ¡CLI ¡and ¡STI ¡to ¡efficiently ¡mask ¡signals ¡

18 ¡

slide-19
SLIDE 19

Many ¡implementaAon ¡challenges ¡

  • Reducing ¡VM ¡exit ¡and ¡VM ¡entry ¡overhead ¡
  • Pthread ¡and ¡fork ¡were ¡tricky ¡to ¡integrate ¡with ¡

the ¡Linux ¡kernel ¡

  • EPT ¡does ¡not ¡support ¡enough ¡address ¡space ¡
  • Check ¡the ¡paper ¡for ¡details ¡

19 ¡

slide-20
SLIDE 20

Outline ¡

  • Overview ¡
  • Design ¡
  • Evalua-on ¡

20 ¡

slide-21
SLIDE 21

EvaluaAon ¡

  • How ¡much ¡overhead ¡does ¡Dune ¡add? ¡
  • What ¡potenAal ¡does ¡Dune ¡create ¡for ¡
  • pAmizaAon? ¡
  • What ¡is ¡Dune’s ¡performance ¡in ¡end-­‑to-­‑end ¡

use ¡cases? ¡

21 ¡

slide-22
SLIDE 22

Overhead ¡analysis ¡

(cycles) ¡ Getpid ¡ Page ¡fault ¡ Page ¡walk ¡ Linux ¡ 138 ¡ 2,687 ¡ 36 ¡ Dune ¡ 895 ¡ 5,093 ¡ 86 ¡

  • Two ¡sources ¡of ¡overhead ¡

– VMX ¡transiAons ¡ – EPT ¡translaAons ¡

slide-23
SLIDE 23

OpAmizaAon ¡analysis ¡

(cycles) ¡ ptrace ¡ (getpid) ¡ trap ¡ Appel ¡1 ¡ (TRAP, ¡PROT1, ¡ UNPROT) ¡ Appel ¡2 ¡ (PROTN, ¡TRAP, ¡ UNPROT) ¡ Linux ¡ 27,317 ¡ 2,821 ¡ 701,413 ¡ 684,909 ¡ Dune ¡ 1,091 ¡ 587 ¡ 94,496 ¡ 94,854 ¡

23 ¡

  • Large ¡opportuniAes ¡for ¡opAmizaAon ¡

– Faster ¡system ¡call ¡interposiAon ¡and ¡traps ¡ – More ¡efficient ¡user-­‑level ¡virtual ¡memory ¡manipulaAon ¡

slide-24
SLIDE 24

End-­‑to-­‑end ¡case ¡studies ¡

  • We ¡built ¡and ¡evaluated ¡three ¡systems ¡
  • ApplicaAon ¡sandbox ¡(~1300 ¡LOC) ¡

– Constrained ¡the ¡system ¡calls ¡performed ¡by ¡an ¡ untrusted ¡binary ¡

  • Garbage ¡collecAon ¡(less ¡than ¡100 ¡LOC ¡change) ¡

– Improved ¡dirty ¡page ¡detecAon ¡through ¡direct ¡access ¡ to ¡dirty ¡bits ¡

  • Privilege ¡separaAon ¡(~750 ¡LOC) ¡

– Supported ¡several ¡protecAon ¡domains ¡within ¡a ¡single ¡ process ¡through ¡use ¡of ¡mulAple ¡page ¡roots ¡(with ¡TLB ¡ tagging) ¡

24 ¡

slide-25
SLIDE 25

Sandbox: ¡SPEC2000 ¡performance ¡

−25 −20 −15 −10 −5 5 10 15 20 25 gzip vpr gcc mesa art mcf equake crafty ammp parser eon perlbmk gap vortex bzip2 twolf % Slowdown

Sandbox Sandbox w/ LGPG Linux w/ LGPG

25 ¡

  • Only ¡notable ¡end-­‑to-­‑end ¡effect ¡is ¡EPT ¡overhead ¡
  • Can ¡be ¡eliminated ¡through ¡use ¡of ¡large ¡pages ¡
slide-26
SLIDE 26

Sandbox: ¡ligh>pd ¡performance ¡

0 ¡ 5000 ¡ 10000 ¡ 15000 ¡ 20000 ¡ 25000 ¡ 30000 ¡ Linux ¡ Dune ¡Sandbox ¡ VMware ¡Player ¡

LighHpd ¡performance ¡(connec-ons ¡per ¡second) ¡

26 ¡

  • Slight ¡reducAon ¡in ¡throughput ¡(less ¡than ¡2%) ¡due ¡to ¡

VMCALL ¡overhead ¡

slide-27
SLIDE 27

Performance ¡of ¡other ¡use ¡cases ¡

  • Up ¡to ¡40% ¡improvements ¡in ¡garbage ¡

collecAon ¡performance ¡(less ¡than ¡100 ¡LOC) ¡

  • Privilege ¡separaAon ¡system ¡can ¡context ¡switch ¡

between ¡subdomains ¡3x ¡faster ¡than ¡Linux ¡can ¡ switch ¡between ¡processes ¡(750 ¡LOC) ¡

27 ¡

slide-28
SLIDE 28

Conclusions ¡

  • ApplicaAons ¡can ¡benefit ¡from ¡access ¡to ¡privileged ¡

CPU ¡features ¡

  • VirtualizaAon ¡hardware ¡allows ¡us ¡to ¡provide ¡such ¡

access ¡safely ¡

  • Dune ¡creates ¡new ¡opportuniAes ¡to ¡build ¡and ¡

improve ¡applicaAons ¡without ¡kernel ¡changes ¡

  • Dune ¡has ¡modest ¡performance ¡overhead ¡
  • Download ¡Dune ¡at ¡ ¡

h>p://dune.scs.stanford.edu ¡

28 ¡

slide-29
SLIDE 29

Xax ¡-­‑ ¡kernel ¡hack ¡

  • Implement ¡“picoprocess” ¡system ¡call ¡support ¡

Hardware ¡ Kernel ¡ App ¡ Monitor ¡

Patch ¡ Syscall ¡ Register ¡

29 ¡

Syscall ¡ Handler ¡

slide-30
SLIDE 30

CPU ¡ Kernel ¡

Host ¡Mode ¡ Guest ¡Mode ¡ Guest ¡Syscall ¡ Register ¡ Host ¡Syscall ¡ Register ¡

  • handle ¡system ¡calls ¡directly ¡within ¡a ¡process ¡

Xax ¡– ¡the ¡Dune ¡approach ¡

Monitor ¡ ¡ ¡ App ¡

30 ¡

Syscall ¡ Handler ¡ Syscall ¡ Handler ¡

slide-31
SLIDE 31

Suppose ¡we ¡wanted ¡to ¡build ¡a ¡faster ¡ garbage ¡collector ¡

  • leverage ¡OS ¡virtual ¡memory ¡support? ¡
  • Technique: ¡memory ¡remapping ¡

– Problem: ¡mmap() ¡is ¡too ¡slow ¡(TLB ¡invalidaAons) ¡

  • Technique: ¡dirty ¡page ¡detecAon ¡

– Problem: ¡Linux ¡does ¡not ¡expose ¡dirty ¡page ¡ informaAon ¡

31 ¡

slide-32
SLIDE 32

ApplicaAon: ¡sandboxing ¡

! ! ! ! ! Sandbox! Untrusted!Process!

SYSCALL!

! ! Kernel! Dune!Module!

VMCALL!

Mini!ELF! Loader! Syscall! Filter! Checkpoint! System! ldBlinux!ELF! Loader!

32 ¡

slide-33
SLIDE 33

ApplicaAon: ¡garbage ¡collecAon ¡

! ! ! ! ! Applica(on! PGTBL! ! ! Kernel! Dune!Module!

VMCALL!

Garbage! Collector!

READ/CLEAR! DIRTY!BITS!

33 ¡

slide-34
SLIDE 34

Could ¡Dune ¡Run ¡in ¡a ¡VM? ¡

34 ¡

slide-35
SLIDE 35

What ¡about ¡Libra? ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡Hypervisor ¡

General ¡Purpose ¡OS ¡ ¡ ¡ ¡ ¡ ¡ Libra ¡(a ¡library ¡OS) ¡ Gateway ¡(9p ¡server) ¡ Shared ¡memory ¡ JVM ¡+ ¡App ¡

  • Works ¡but ¡very ¡complex ¡and ¡overhead ¡is ¡high ¡

VFS ¡ NET ¡ BLOCK ¡ VHBA ¡ VNIC ¡

35 ¡

slide-36
SLIDE 36

Why ¡Dune ¡is ¡Safe ¡

  • Two ¡key ¡ideas ¡

– Memory ¡protected ¡by ¡EPT ¡ – Privileged ¡state ¡protected ¡by ¡VT-­‑x ¡

36 ¡

slide-37
SLIDE 37

VT-­‑x: ¡shadows ¡privileged ¡state ¡

HW: ¡VMX ¡Root ¡Mode ¡(host) ¡ HW: ¡VMX ¡Non-­‑root ¡Mode ¡(guest) ¡ Dune ¡Process ¡

¡ ¡ ¡ ¡

Kernel ¡

¡ ¡ ¡ ¡

VM ¡Enter ¡ VM ¡Exit ¡ Host ¡ GDT ¡ Host ¡ IDT ¡ Host ¡ CR3 ¡ Guest ¡ GDT ¡ Guest ¡ IDT ¡ Guest ¡ CR3 ¡

37 ¡

1.) ¡save ¡guest ¡state ¡ 2.) ¡load ¡host ¡state ¡ 1.) ¡save ¡host ¡state ¡ 2.) ¡load ¡guest ¡state ¡

slide-38
SLIDE 38

SPEC2000 ¡-­‑ ¡different ¡sandboxing ¡ approaches ¡

Dune ¡ Linux ¡ LGPG ¡ Dune ¡ LGPG ¡ 32-­‑bit ¡ Linux ¡ 32-­‑bit ¡ NaCl ¡ 64-­‑bit ¡ NaCl ¡ KVM ¡ Strategy ¡ 3.1 ¡

  • ­‑4.3 ¡
  • ­‑4.1 ¡

12.7 ¡ 37.6 ¡ 23.7 ¡ 4.7 ¡

  • ­‑10 ¡
  • ­‑5 ¡

0 ¡ 5 ¡ 10 ¡ 15 ¡ 20 ¡ 25 ¡ 30 ¡ 35 ¡ 40 ¡ Slowdown ¡Percentage ¡

38 ¡