27
Seeing Through the Same Lens: Introspecting Guest Address Space at Native Speed Siqi Zhao*, Xuhua Ding*, Wen Xu , Dawu Gu * Singapore Management University Georgia Institute of Technology Shanghai JiaoTong University 1

Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Embed Size (px)

Citation preview

Page 1: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Seeing Through the Same Lens:

Introspecting Guest Address Space at Native

Speed

Siqi Zhao*, Xuhua Ding*, Wen Xu◆, Dawu Gu◇

* Singapore Management University◆ Georgia Institute of Technology◇ Shanghai JiaoTong University

1

Page 2: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Outline

• Problem

• Design

• Implementation

• Evaluations

2

Page 3: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Problem

• Considering introspecting kernel objects• Untrusted live VM

• VMI tool running outside of the VM

• The VMI tool and the target objects are in different address spaces.

• The VMI tool needs to perform a sequence of operations for every kernel object access.

3

Page 4: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Live Target VM

Problem

• Considering introspecting kernel objects • Untrusted live VM

• VMI tool running outside of the VM

• The VMI tool and the target objects are in different address spaces.

• The VMI tool needs to perform a sequence of operations for every kernel object access.

4

GPT

EPT

Physical Memory

task_structat 0xC0001000

VMI Tool

VA: 0xC0001000

GPA: 0x1000

HPA: 0xFE000

ptr = 0xFE000

task_struct at 0xFE000

Goal: res = task_struct

Page 5: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Inadequacy of Page Table Walk

• Page table walk lies at the heart of VMI

• Slow, compared to native address translation by MMU• A number of loads from memory

• An experiment to evaluate the slowness of software based page table walk• Periodically modifies one task->cred pointer

• Closely monitor the value of the pointer by repeatedly reading it from outside

• Cannot catch up with frequent transient guest state changes

5

Page 6: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Live Target VM

Inadequacy of Page Table Walk

• Mapping consistency with the target is not maintained• Uses any mappings: ample room for

the guest to present false mappings

• The target VM may also make transient changes to the page table

• Caching techniques that aim toenhance efficiency further deterioratethe situation, giving up consistency forefficiency.

6

GPT

EPT

Physical Memory

VMI Tool

VA: 0xC0001000

task_struct at 0xFE000

GPA: 0x1000

GPA Space

task_struct at 0x1000task_struct at 0x2000

task_structat 0xC0001000

Page 7: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Immersive Execution Environment (ImEE) Architecture• ImEE is essentially a special VM created on-

demand by VMI applications.• Scheduled by the hypervisor• Consists of only a vCPU and a small

amount of memory: code and data• ImEE hosts a piece of code called ImEEagent that actually performs introspection

• ImEE acts as a memory access engine for VMI applications• Only perform memory read• Native speed read• Page table is consistent with target at any

moment

7

Page 8: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Basic Idea

• An environment with a twisted address mappings• Cloned CR3 content

• Cloned EPT, with mappings from target EPT and restricted permission

• The result: a VA is translated to thesame HPA by the MMU in bothenvironments

8

CR3

Target frames

RONX

GPT

EPT

CR3

Target VMImEE

memory

memory

Cloned EPT

VA: 0xC0001000

VA: 0xC0001000

GPA: 0x1000 GPA: 0x1000

HPA: 0xFE000

Page 9: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Making it work

• Implementation issues:• Need room in the virtual address

space for• our own code

• exchanging data with VMI tool

• We want to avoid touching GPT

• What about the number of redirected pages?

9

CR3

Target frames

RONX

GPT

EPT

CR3

Target VMImEE

memory memory

EPTTEPTc

data code

Cloned EPT

Page 10: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Immersive Execution Environment (ImEE)

• Two address spaces in the ImEE

• Local address space is for theImEE agent to interact with theVMI application

• The idea ‘incarnates’ as the target address space in ImEE.

• Introspection is only performed in the target address space

10

CR3

Target frames

RONX

GPTLocal GPT

data code

EPTEPTTEPTCEPT

CR3CR3

Target address space

Local address space

Target VMImEE

memory memory

Page 11: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

CR3

Target frames

RONX

GPTLocal GPT

data code

EPTEPTTEPTCEPT

CR3CR3

Target address space

Local address space

Target VMImEE

memory memory

Target Address Space

• GPA space is split by the EPT• All address mappings are the same

as in the target VM, with read-only permission

• One page is redirected by EPT tothe agent’s code page, withexecute-only permission

• Two possible kinds of translation in the target address space:• Instruction fetch

• Memory read

11

Page 12: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Target Address Space

• Example:

12

CR3

Target frames

RONX

GPTLocal GPT

data code

EPTEPTTEPTCEPT

CR3CR3

Target address space

Local address space

Target VMImEE

memory memory

CR3

Target frames

RONX

GPTLocal GPT

data code

EPTEPTTEPTCEPT

CR3CR3

Target address space

Local address space

Target VMImEE

memory memory

mov (0x1000), %eax0xBFF0:

Page 13: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Local Address Space

• Minimizes the number of redirected page in the target address space

• Only two pages are mapped• All pages except one are mapped to

code• The remaining one is mapped to

data• Allowing the agent to be executed

almost anywhere, because we do not know the load address beforehand

13

CR3

Target frames

RONX

GPTLocal GPT

data code

EPTEPTTEPTCEPT

CR3CR3

Target address space

Local address space

Target VMImEE

memory memory

Page 14: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Local Address Spaces

• Example:

14

CR3

Target frames

RONX

GPTLocal GPT

data code

EPTEPTTEPTCEPT

CR3CR3

Target address space

Local address space

Target VMImEE

memory memory

mov %eax, (0x2000)0xBFFA:

Page 15: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

The ImEE Agent

• The ImEE agent is the only code that runs inside ImEE• Reside within one page, self-contained

• Position independent

• Granted ring 0 privilege

• Initially, the agent is loaded at a page whose VA is mapped as executable in the guest page tables.• The hypervisor uses the page that the current IP points to

15

Page 16: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

The ImEE Agent

• The agent’s execution straddles between the two address spaces.

• Simplified pseudo-code:

1. eax = data[request]

2. cr3 = target_cr3 /* switch to target address space */

3. xmm0 = *eax

4. cr3 = imee_cr3 /* switch to local address space */

5. data[result] = xmm0

16

Page 17: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Other Issues

• Blind spot• The code page in the target GPA

space is redirected

• Any virtual address mapped to this GPA cannot be read

• Cannot be eliminated

• Only detected when introspection is on the blind spot• Relying on EPT mappings

• Relocate agent once detected

17

CR3

Target frames

GPT

code

EPTEPTTEPTC

CR3

Target VMImEE

memory

VA: 0xC0001000

GPA: 0x1000

HPA: 0xBFF0

HPA: 0xFE000

Page 18: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Advantages

• Native speed• Address translation is performed at native speed by hardware.

• Consistency• Page table used is kept consistent with the current one in the target.

• CR3 is synchronized

18

Page 19: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Implementation

• We implemented a prototype of ImEE• Hypervisor changes: modified KVM module

• Consists of around 1400 SLOC

• Two new IOCTLs as interface to user space

• Optimized code path that handles ImEE specific VM exit

• Agent: specially crafted assembly code• Within one page, a few tens of instructions

• Position independent

• One data page for exchange data with VMI tool

19

Page 20: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Evaluation

• We use LibVMI as the base line.• LibVMI: the only open source tool

• Serves as building block for various other tools such as Volatility

• Experiment setup:• Hardware: Intel Core i7-2600, 4GB DDR3 RAM

• Guest VM: 1GB RAM and one vCPU

20

Page 21: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Evaluation

• ImEE Overhead• Launch time: time taken for the hypervisor to prepare relevant data such as the EPT

• Activation time: time for a launched, but not running, ImEE to begin execute the agent code

21

ImEE LibVMI Speedup

Launch time 97 μs 100 ms 1031 times

Activation time 3.2 μs -

Page 22: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Evaluation

• Guest access speed• We measure the time take to read a number of bytes from the target

• LibVMI’s translation cache is on, data cache off

22

# of Bytes ImEE LibVMI (μs) Speedup

4 0.353 18.4 52 times

64 0.358 18.5 52 times

128 0.389 18.4 47 times

512 1.643 18.9 11 times

1024 1.715 38.1 22 times

Page 23: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Tools

• syscalldmp: dumps totally 351 entries of the guest’s system call table

• pidlist: lists all process identifiers in the guest.

• pslist: lists all tasks’ identifiers and task names stored in task struct.

• credlist: lists all tasks’ credential structures referenced by the task struct’scred pointer.

23

Page 24: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Evaluation

• We ran our four tools in four setups: ImEE, kernel, LibVMI on KVM and LibVMIon Xen

• Measure time taken to complete the task

• Results:• Comparable to kernel

• Significant speedup compared to LibVMI

24

Kernel (μs) LibVMI / KVM (μs) LibVMI / Xen (μs) ImEE (μs) Speedup (KVM) Speedup (Xen)

syscalldmp 0.2 28.2 43 2.9 9 times 15 times

pidlist 10 5887 2180 31.6 186 times 68 times

pslist 10.4 8319 1477 38.6 215 times 38 times

credlist 25.3 8234 2274 25.6 321 times 88 times

Page 25: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Evaluation

• Scanning multiple VMs• We setup four VMs and measure:

• Time to scan every VM

• Time to switch scan target

• Results:

25

LibVMI ImEE Speedup

Scanning all VMs 561 ms 377 μs 1400 times

Switching target VM 19 ms 4.4 μs 4300 times

Page 26: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Conclusion

• ImEE is a novel memory access engine for out-of-VM introspecitonapplications for live VM.

• Based on hardware virtualization, ImEE shows remarkable speed up compared to existing approaches.

• ImEE maintains mapping consistency during introspection. Complemented by its high speed, ImEE is suitable for security sensitive VMI applications.

26

Page 27: Seeing Through The Same Lens: Introspecting Guest Address ... · Seeing Through the Same Lens: Introspecting Guest Address Space at Native ... GPT EPT Physical Memory VMI ... Seeing

Questions?

27