Secure Address Space Protection in a Multi-hosts Environment

24
Secure Address Space Protection in a Multi-hosts Environment V1. Sep 22, 2012 V2/V3. Sep 24, 2012 Cheng-Chun Tu 1

Transcript of Secure Address Space Protection in a Multi-hosts Environment

Page 1: Secure Address Space Protection in a Multi-hosts Environment

Secure Address Space Protection in a Multi-hosts Environment

V1. Sep 22, 2012

V2/V3. Sep 24, 2012

Cheng-Chun Tu

1

Page 2: Secure Address Space Protection in a Multi-hosts Environment

Architecture Overview

Cheng-Chun Tu

2

PCIe switch

PF VF VF

SR – IOV NIC

NTB/LUT

MH’s Physical Addr

CPU

MMU

IOMMU

MH

IOMMU

Dom0

MMU

VM

MMU

GPT

CH’s Physical Addr

CH1

NTB/LUT

IOMMU

Dom0

MMU

VM

MMU

GPT

CH’s Physical Addr

CHx

Page 3: Secure Address Space Protection in a Multi-hosts Environment

Outline

¤  What kinds of hosts and devices in the PCIe network?

¤  What kinds of address spaces in the PCIe network?

¤  What components do we use to translate among addresses space?

¤  How does the each address space being translated?

Cheng-Chun Tu

3

Page 4: Secure Address Space Protection in a Multi-hosts Environment

Hosts and Devices

¤  MH (Management Host) ¤  The host that extends its own PCI hierarchy into the PCIe

switch fabric.

¤  CH (Computer Host): host behind a NT virtual side. ¤  VCH (Virtualized CH): host with SW/HW supports for running

virtual machines.

¤  NVCH (Non-virtualized CH): host which runs single OS with IOMMU

¤  Devices ¤  Normal PCI device

¤  SR-IOV

Cheng-Chun Tu

4

Page 5: Secure Address Space Protection in a Multi-hosts Environment

Address Spaces in Hosts

¤  MH and NVCH ¤  Physical address space

¤  Virtual address space

¤  Device virtual address space

¤  VCH ¤  Host physical address space

¤  Host virtual address space

¤  Guest physical address space

¤  Guest virtual address space

¤  Device virtual address space

Cheng-Chun Tu

5

Page 6: Secure Address Space Protection in a Multi-hosts Environment

Address Space in Devices

¤  IOMMU provide each device its own device virtual address space

¤  IOMMU translates a device’s virtual address into physical address by looking up the device’s corresponding page table

Cheng-Chun Tu

6

¤  Host relies on IOMMU to isolation physical address range a device can access so that malicious device won’t access privileged memory

Page 7: Secure Address Space Protection in a Multi-hosts Environment

Translation Components

Cheng-Chun Tu

7

Comp. Identifier input Output

PT Process ID Host virtual addr. Host phys addr

GPT Process ID Guest virtual addr. Guest phys addr

EPT Domain(VM) ID Guest phys addr. Host phys addr

IOMMU Device ID Dev virtual addr. Host phys addr

LUT Part of Device ID Device ID Device ID

NTB BAR addresses Physical Address at one side

Dev virtual addr. at the other side

PT: Page Table GPT: Guest Page Table EPT: Extended Page Table LUT: Look Up Table NTB: Non-Transparent Bridge

Page 8: Secure Address Space Protection in a Multi-hosts Environment

NTB Address Mapping

¤  NTB maps from <the primary side to the secondary side>

¤  Mapping: <addrA at prim. side to addrB at the secondary> ¤  addrA = Dev1 BARn, addrB = {RAM | Dev2 BARn} ¤  Dev1: {NT-Link | NT-Virtual} ¤  Dev2: {any device on the other side} ¤  Actually addrB could target any secondary side physical address

¤  One-way Translation: ¤  Read/write at addrA == read/write addrB ¤  Read/write at addrB does not translated to addrA

¤  Type ¤  addrA = {physical addr.} ¤  addrB = {device virtual addr.}

Cheng-Chun Tu

8

Page 9: Secure Address Space Protection in a Multi-hosts Environment

MH’s Physical Address Space

Address Translation to MH

Cheng-Chun Tu

9

CPU

PT

NTB

IOMMU

1. CH’s CPU

hpa

hva

dva

-> host physical addr. -> host virtual addr. -> guest virtual addr. -> guest physical addr. -> device virtual addr.

hpa

hva

dva

gva

gpa

CPU

GPT

EPT

NTB

IOMMU

2. VCH VM’s CPU

hpa

dva

gva

gpa

CPU

PT

DEV

IOMMU

MH’s CPU MH’s device

dva hva NTB

IOMMU

DEV

IOMMU

3. CH’s device (P2P)

dva

dva

hpa

Page 10: Secure Address Space Protection in a Multi-hosts Environment

CH’s Physical Address Space

Address Translation to CH

Cheng-Chun Tu

10

CPU

PT

NTB

IOMMU

5. MH’s CPU

hpa

hva

dva

CPU

GPT

EPT

4. CH VM’s CPU

gva

gpa

CPU

PT

DEV

IOMMU

CH’s CPU CH’s device

dva hva

-> host physical addr. -> host virtual addr. -> guest virtual addr. -> guest physical addr. -> device virtual addr.

hpa

hva

dva

gva

gpa

NTB

IOMMU

DEV

IOMMU

6. MH’s device (P2P)

dva

dva

hpa

Page 11: Secure Address Space Protection in a Multi-hosts Environment

Summary 1

Cheng-Chun Tu

11

src\ dst MH memory / device CH memory / device

MH CPU MMU MMU+NTB+IOMMU

MH Dev IOMMU IOMMU+NTB+IOMMU

CH CPU MMU+NTB+IOMMU MMU

CH Dev IOMMU+NTB+IOMMU IOMMU

CH VM MMU+GPT+NTB+IOMMU

MMU+GPT

Device-to-device protection requires switch ACS and P2P support.

Page 12: Secure Address Space Protection in a Multi-hosts Environment

H2’s Physical Address Space

MH’s Physical Address Space

Inter-host Address Translation

Cheng-Chun Tu

12

CPU

PT

NTB

IOMMU

7. CH1’s CPU

hpa

hva

dva

NTB

IOMMU

dva

7. From CH1’s CPU to CH2’s RAM 8. From CH1’s Device to CH2’s RAM 9. From VM in CH1 to CH2’s RAM

CPU

GPT

EPT

NTB

IOMMU

9. VCH1 VM’s CPU

hpa

dva

gva

gpa

NTB

IOMMU

DEV

IOMMU

8. CH1’s device

dva

dva

hpa

Page 13: Secure Address Space Protection in a Multi-hosts Environment

Summary 2

src \ dst CH Memory Other CH memory

CH CPU MMU MMU + NTB + MH’s IOMMU + NTB + dst’s IOMMU

CH Dev IOMMU IOMMU + NTB + MH’s IOMMU + NTB + dst’s IOMMU

CH VM MMU + GPT MMU + GPT + NTB + MH’s IOMMU + NTB + dst’s IOMMU

Cheng-Chun Tu

13

Page 14: Secure Address Space Protection in a Multi-hosts Environment

Case Description

Case Description

1 CH accesses MH’s memory,

2 VM on CH accesses MH’s memory,

3 CH’s device accesses MH’s memory

4 CH’s VM access CH’s memory

5 MH’s CPU accesses CH’s memory

6 MH’s device accesses CH’s memory

7 CH1’s CPU accesses CH2’s memory

8 CH1’s device accesses CH2’s memory

Cheng-Chun Tu

14

Page 15: Secure Address Space Protection in a Multi-hosts Environment

PCI device ID translation

Cheng-Chun Tu

15

Root Complex

CH1’s ID domain

LUT

Root Complex

CHn’s ID domain

LUT

Root Complex

MH

DEV

MH’s PCI ID Domain

DEV DEV

1.  Each host (MH + CHs) has its own device id domain. 2.  LUT is responsible for ID translation from one host domain to another. 3.  IOMMU depends on ID to setup its access table.

Page 16: Secure Address Space Protection in a Multi-hosts Environment

LUT + IOMMU based protection

¤  Prevent unauthorized dev from accessing any memory area in other CHs such as CH2

¤  Solution strategies: ¤  LUT lookup fail or IOMMU lookup fail

¤  NTB translates dev’s ID space from MH to CH2 by LUT.

¤  Make sure ¤  Either LUT has no entry for dev’s <bus:dev> ¤  Or dev’s translated ID is forbidden in the

CH2’s IOMMU table.

Cheng-Chun Tu

16

Dev

SR – IOV Device

VM1 VM2

VF VF

CH2

VMM

IOMMU

NTB / LUT Lookup Fail!

Lookup Fail!

Page 17: Secure Address Space Protection in a Multi-hosts Environment

Examples

Cheng-Chun Tu

17

Page 18: Secure Address Space Protection in a Multi-hosts Environment

LUT translation example

¤  Each VF / NTB is uniquely assigned a DevID <BusNo : DevNo . FunNo>

¤  LUT entries consists of index : <BusNo, DevNo> ¤  LUT translation:

¤  <BusNo : DevNo. FunNo> translate to

¤  <NTB’s BusNo : matching index in LUT. FunNo>

¤  Ex: VF1=<3:12.1>, VF5=<3:12.5>, NTB for VF5=<2:0.0>, LUT= 4 : <3:12> ¤  VF1 after translation: <2:4.1>, forbidden in IOMMU

¤  VF5 after translation: <2:4.5>, allow in IOMMU

Cheng-Chun Tu

18

Page 19: Secure Address Space Protection in a Multi-hosts Environment

Example1

Cheng-Chun Tu

19

MH’s Physical Address Space

¤  MMU -> NTB -> IOMMU->MH VF1’s CSR ¤  VF1’s CSR: 0xF4000000, ID=[3:11.1] ¤  MMU mapping 0xFF800000 -> 0xF6800000 ¤  NTB [2:0.0/4:0.0] mapping 0xF6800000 ->

0xFA800000 ¤  IOMMU: 0xFA800000 -> 0xF4000000

¤  ID translation ¤  Setup [0:0] at LUT index 0 ¤  CH2’s CPU ID = [0:0.0], ID translation: [0:0.0] ->

[4:0.0] ¤  setup IOMMU for [4:0.0]

VF1

CPU

PT

NTB/LUT

IOMMU

1. CH2’s CPU

hpa

hva

dva

From CH2’s CPU to MH’s Device VF1’s CSR

0xFF800000

0xF6800000

0xFA800000

0xF4000000

[2:0.0]: Virt [4:0.0]: Link

Page 20: Secure Address Space Protection in a Multi-hosts Environment

Example2

Cheng-Chun Tu

20

¤  VF1 -> IOMMU -> NTB -> IOMMU ¤  VF1[3:11.2] writes 0xFB800000 ¤  IOMMU: 0xFB800000 -> 0xF8800000 ¤  NTB[2:0.0] maps 0xF8800000 -> 0xFA800000 ¤  IOMMU mapping 0xFA800000 -> 0x6800000

¤  ID translation ¤  Setup first IOMMU for [3:11.2] ¤  Setup entry [3:11] at LUT index 3 ¤  ID translation: [3:11.2] -> [2:3.2] ¤  VF1’s ID at CH2 = [2:3.2], setup second IOMMU

for [2:3.2]

From VF1 to DMA CH2’s memory 0x6800000

CH’s Physical Address Space

NTB/LUT

IOMMU

Dev:VF1

IOMMU

6. MH’s device (P2P)

dva

dva

0xFB800000

0xF8800000

0xFA800000

0x6800000

[4:0.0]: Link [2:0.0]: Virt

hpa

Page 21: Secure Address Space Protection in a Multi-hosts Environment

Example3

Cheng-Chun Tu

21

From CH1’s CPU to CH2’s memory 0xA800000

CH2’s Physical Address Space

MH’s Physical Address Space

CPU

PT

NTB/LUT

IOMMU

7. CH1’s CPU

hpa

hva

dva

NTB/LUT

IOMMU

dva

0xFB800000

0xF8800000

0xFA800000

0xF4800000

0xF280000

0xA800000

¤  Let CH1 write to CH2 NTB’s address mapping range ¤  Same setup as example1, but write to

NTB instead of VF1

¤  Setup NTB to map 0xF48000000 -> 0xF2800000

¤  Setup IOMMU to map NTB’s ID for 0xF28000000 -> 0xA800000

¤  ID translation ¤  Setup first IOMMU for [4:0.0] (as in ex1) ¤  Setup entry [4:0] at right side LUT index 3 ¤  ID translation: [4:0.0] -> [2:3.0] ¤  Setup second IOMMU for [2:3.0]

[2:0.0]: Virt [4:0.0]: Link

[2:0.0]: Virt [5:0.0]: Link

hpa

Page 22: Secure Address Space Protection in a Multi-hosts Environment

End

Cheng-Chun Tu

22

Page 23: Secure Address Space Protection in a Multi-hosts Environment

Cheng-Chun Tu

23

MMU

DEV

NTB

DEV

IOMMU

CPU

IOMMU

CPU

MMU

CPU

MMU

NTB

CPU

MMU

EPT

NTB IOMMU

IOMMU

NTB

IOMMU

DEV

IOMMU

Page 24: Secure Address Space Protection in a Multi-hosts Environment

Translation Components

¤  PT (Page Table): ¤  Host virtual address -> host physical address

¤  GPT (Guest Page Table): ¤  Guest physical address -> Host physical address

¤  EPT (Extended Page Table):

¤  IOMMU: ¤  Device virtual address -> Host physical address

¤  NTB: ¤  Physical Address at one side of a host -> device virtual Address another side

of a host

¤  LUT: ¤  PCI device ID at one side of NTB -> PCI device ID at another side

Cheng-Chun Tu

24