Provably Secure Execution Platforms - Lecture Four: A Simple - - PowerPoint PPT Presentation

provably secure execution platforms lecture four a simple
SMART_READER_LITE
LIVE PREVIEW

Provably Secure Execution Platforms - Lecture Four: A Simple - - PowerPoint PPT Presentation

Provably Secure Execution Platforms - Lecture Four: A Simple Separation Kernel and Its Verification Mads Dam KTH Royal Institute of Technology BISS spring school, Bertinoro 2018 The Goal Hypervisor Context switch: Fixed round-robin


slide-1
SLIDE 1

Provably Secure Execution Platforms

  • Lecture Four:

A Simple Separation Kernel and Its Verification

Mads Dam

KTH Royal Institute of Technology

BISS spring school, Bertinoro 2018

slide-2
SLIDE 2

The Goal

  • Context switch: Fixed round-robin scheduling, assume two

guests, statically allocated

  • Asynchronous message passing through hypercall (swi)
  • Paravirtualization

Hypervisor

Dam, Guanciale, Khakpour, Nemati, Schwarz: Formal Verification of Information Flow Security for a Simple ARM-Based Separation Kernel, CCS’13

slide-3
SLIDE 3

Kernel Basics

Q: What is a kernel? A: A set of event handlers and some data structures for support Three types of events:

  • Exceptions

– arise as result of a processor error conditions

  • Software interrupts

– arise when a user program wants to invoke some service

  • Hardware interrupts

– Arise when a piece of hardware (e.g. USB device, NIC, …) wants to invoke some service

slide-4
SLIDE 4

Kernel Basics

Upon an event a handler routine is invoked, user state stored on stack and privilege level is raised Upon return user state is restored – In some suitable form Parameters transferred in registers – When applicable … Results returned in registers – When applicable … During handler execution, exceptions and interrupt may be disabled or not – Non-preemptive kernel: No nesting of interrupts Our kernel is preemptive

slide-5
SLIDE 5

Ideal Model

Describes the abstract functionality of the system, here:

  • CPUs are virtual, with only user

level functionality

  • All privileged execution replaced

by ideal handlers

  • CPUs are ”physically separated”
  • Only communication between

guests through communication and instruction cycle counting

CPU CPU

slide-6
SLIDE 6

Ideal Model

Context switching:

  • Only one of user CPUs active at any

time Sending a message:

  • Hypercall swi 1 causes content of

reg 0 to be written to msgbox Receiving a message:

  • If msgbox full on switch to receiver,

instead of restoring receiver invoke user level handler Restoring receiver:

  • Once message processing done

invoke swi 0 to restore receiver

CPU CPU

slide-7
SLIDE 7

: Normal sender execution : Message processing : Send hypercall : Resume hypercall : Normal receiver execution

Ideal Model: Scheduling

Scheduling round

Sender Receiver Scheduler

slide-8
SLIDE 8

Ideal model state:

  • : User CPU states
  • : Messaging data structures
  • : Elapsed time
  • : Activity flag

Messaging data structures:

  • : Indicates if guest i is ready to receive a message
  • : User context pointer used to switch

between message processing and normal execution

  • : message box

Ideal Model

slide-9
SLIDE 9

Context fields are stored consecutively in memory is field accessor is field update Also use tuple notation:

  • Records and Contexts
slide-10
SLIDE 10

Initial state :

  • : Initial states with

– Registers zeroed – initialized to make the user address spaces disjoint and not contain the vector jump addresses – suitably initialized within user address space – initialized to suitably large number (return to that)

  • Message data structures initialized with

, for suitable

  • Ideal Model, Initial State

These are defined later

slide-11
SLIDE 11

User step: User step, symmetric case: Many symmetric cases below, mostly omitted

Ideal Model, Transitions

slide-12
SLIDE 12

Guest switch, message processing in progress:

  • : Pop context from stack, return to user mode
  • : Fixed number of cycles for handler, to be set later
  • Similar transition rule for

Ideal Model, Transitions

slide-13
SLIDE 13

Guest switch, no message pending:

  • cycles for handler
  • Similar transition rule for

Ideal Model, Transitions

slide-14
SLIDE 14

Some helper functions:

  • restoreUser, restoreCtx
slide-15
SLIDE 15

Guest switch, receive message:

  • , :

Entry points for guest 0/guest 1 message handlers

  • Ideal Model, Transitions
slide-16
SLIDE 16

Guest resume:

  • + symmetric rule, as always

Ideal Model, Transitions

slide-17
SLIDE 17

Guest send:

  • + symmetric rule
  • Note: Up to guests to implement flow control

Ideal Model, Transitions

slide-18
SLIDE 18

Ideal Model, Exercises

Exercise 1: Convince yourself that the transition semantics makes sense by mentally executing a few simple scenarios (and report to me any bugs you find!) Exercise 2: Prove some simple sanity properties, such as:

  • For any reachable state (state

reachable from the initial state): – At most one of is in privileged state – If is in privileged state then ’s program counter is jump vector address – Stack pointers differ from their initial values only when one

  • f the guests are in privileged state
  • To prove such properties use a suitable invariant
slide-19
SLIDE 19

Ideal Model, Exercises

Exercise 3: Does the transition semantics pose any constraints on the choice of ? Exercise 4 (harder): Devise a ”single-sided” semantics in which

  • nly one guest is executing, sending and receiving data through

transition labelled IO. States would have the shape . For transitions we would have a user transition: For privileged transitions, e.g.:

slide-20
SLIDE 20

Ideal Model, Exercises

Exercise 4, continued: Show that for each trace of the ideal system there exists a corresponding pair of traces in the single-sided system such that the sequence of words exchanged in the ideal system trace corresponds to the sequence of words input, respectively

  • utput, in the single-sided trace.
slide-21
SLIDE 21

Ideal Model, Exercises

Exercise 5: Propose an ideal model transition rule for exceptions. You may assume a pair of guest exception handler entry points fooo , . The exception handler needs to receive as parameter in register 0 the address of the offending instruction.

slide-22
SLIDE 22

Real Model

Task:

  • Use only single processor
  • No ideal functionality (the

handlers)

  • Handlers explicitly

represented as code executing at privileged level

  • Data structures (e.g.

channels, stacks) to be explicitly represented in memory

  • Code store in memory

Hypervisor

slide-23
SLIDE 23

Memory Layout

Two partitions/guests Execute in disjoint memory regions

  • Guest

is active when Kernel memory regions

  • Vector region

– Contains exception and interrupt jump addresses

  • Kernel region

– Contains kernel code and data structures ,…: Kernel addresses holding the corresponding values

slide-24
SLIDE 24

Guest Memory

Guest entry points: – – Guest message handlers: – – Guest exception handlers: – –

slide-25
SLIDE 25

Contexts: – ref /* ”Normal” context for guest 0 – ref /* Do. For guest 1

Kernel Region: Task Switching

slide-26
SLIDE 26

Stack roots: – – – – Each stack assigned a memory region with delimiters in: – – – –

Kernel Region: Stacks

Size?

slide-27
SLIDE 27

Channels: – /* ? /* Resume context – –

Kernel Region: Channels

slide-28
SLIDE 28

In kernel memory: – – – – – In vector region: – – – –

Kernel Region: Handlers

slide-29
SLIDE 29

Initialisation

Processor initialised with: – Register 0,…,3, mode, time zeroed – – – , ??? – , –

  • as processor, but with

,

slide-30
SLIDE 30

Handlers

  • Handlers are now executed on the ”real” machine, using the

transition rules of lecture 3

  • Handler tasks:

– Extract state information:

  • Which guest? Not trivial since irq’s/exception’s can be
  • nested. Use the stack pointer memory region.
  • Which state? Need to figure some state information to

determine what action to take. – Update state: Channels, contexts – Prepare stack – Return from exception loads registers including pc in one atomic (!) step

slide-31
SLIDE 31

Show irq_entry.pseudo, swi1_entry (mask). (Find them in the course directory) Exercise 6. Give similar pseudo-code implementations of the

  • ther handlers.

Exercise 7. Find a suitable Hoare-style specification of the irq_entry routine. Use weakest preconditions to show that it holds, under the assumption that it is never preempted.

Handlers

slide-32
SLIDE 32

Handlers

Exercise 8. t_sw1, t_sw2, t_rcv, t_res, t_send: The ideal model transition rules leave these numbers unspecified. Explain how to calculate them, and estimate t_rcv. Exercise 9. t_max: We have also left t_max unspecified. Propose a lower bound. Exercise 10. Stacks: Stacks can grow in an unbounded fashion in pathological cases. Present a simple condition that will prevent stacks from growing larger than 2|ctx|.

slide-33
SLIDE 33

Verification

Goal: – Want to prove that, when running on top of the kernel, the two guest systems do not interfere in unintended ways. – What does ”interfere” mean? – What does ”in unintended ways” mean?

Hypervisor

slide-34
SLIDE 34

Noninterference

Proposal #1: Noninterference Can adapt definition of noninterference mod system variables, lecture 2, in the following way:

  • Variables:

– High variables – content of guest 1 memory – System variables – content of kernel memory – Low variables – content of guest 0 memory

  • Observations:

– Content of low memory + activity of guest

  • Recapping:

– Kernel (content of kernel memory) is NI, if whenever started in states s_0,s_1 for which kernel and low variables are identical, the observations are the same

When is a guest active?

slide-35
SLIDE 35

Noninterference

Pictorially:

  • Unfortunately this does not work
  • Why? Would declassification help? Why not?

Hypervisor Hypervisor

slide-36
SLIDE 36

Our Approach

  • Equivalence: Each guest “sees” the same observations
  • When guest G is active, the user mode observable parts of the

machine state are identical

Separation kernel CPU CPU CPU

slide-37
SLIDE 37

= Vanilla NI in Absence of Communication

Separation kernel CPU CPU CPU

  • CPU

CPU

  • Separation kernel

CPU (By ”our approach”) (By ”our approach”) (Since there is no communication)

slide-38
SLIDE 38
  • Pick an initial ideal model state
  • Pick an initial real model state
  • Need the states to be ”suitably related”, for instance:

– , , , , III , , etc. – , etc. – , whenever – (same for guest 1 memory) – , etc. – iff guest 0 scheduled in

  • Note: This holds when guest 0 is first scheduled in both ideal

and real model

Formally

slide-39
SLIDE 39

Trace of ideal model: Trace of real model: Show that:

Top Level Verification Goal

1 2 n n+1

. . . . . .

1 2 n n+1

. . . . . .

slide-40
SLIDE 40

Like the ”NI modulo system variables” notion from lecture 2 Define relation on states in ideal and real model as for the initial states: – iff – Observations of guest in = observations of guest in and the system states are suitably related – Guest is scheduled in iff guest is scheduled in IIIIIIII , the channel states in the guest systems are ”compatible”, etc. etc. Exercise 11: Propose a suitable definition of . In particular, what to do about time?

Proof Strategy

slide-41
SLIDE 41

Unwinding Relation

Identical:

  • User mode readable memory
  • User mode observable registers
  • Channels
  • Time
slide-42
SLIDE 42

Unwinding Relation

Ide Weak bisimulation

  • Per partition
  • User mode observations to be preserved
  • Weak handler transitions
slide-43
SLIDE 43

Unwinding Relation

Ide Weak bisimulation

  • Per partition
  • User mode observations to be preserved
  • Weak handler transitions
  • What about preemption?
slide-44
SLIDE 44

Ide Boot Lemma

  • Boot code terminates and establishes the relation for the initial

states

  • Establish hypervisor invariant
  • Machine code verification
  • Left out

Unwinding Relation

slide-45
SLIDE 45

Ide User Lemma

  • No infiltration/no exfiltration for user mode transitions
  • Independent of handler code, independent of guest code
  • Property of user mode execution in underlying machine

Unwinding Relation

slide-46
SLIDE 46

Ide Switch Lemma

  • No infiltration/no exfiltration for exceptions/interrupts
  • Independent of handler code, independent of guest code
  • Property of user mode execution in underlying machine

Unwinding Relation

slide-47
SLIDE 47

Ide Handler Lemmas

  • Handlers satisfy their contracts
  • Dependent on handler code, independent of guest code
  • Machine code verification

Unwinding Relation

slide-48
SLIDE 48

Switch Lemma

Suppose again Suppose that and are both in user mode Switch Lemma: if and is in privileged mode then in privileged mode and , and vice versa Exercise 13: Prove the Switch Lemma for one or two cases using again the relational method.

slide-49
SLIDE 49

Handler Lemma

Suppose again Suppose that and are both in privileged mode Let , if the execution of the handler invoked in ”returns to the state” IIIIII Handler Lemma: if and is in privileged mode then and IIII , and vice versa Exercise 13: Prove the Handler Lemma for irq_entry using the Hoare specification obtained in exercise 7 with some additional reasoning.

slide-50
SLIDE 50

The relation induces a bijective correspondence over paths in the ideal and real models Exercise 14. Show this. We obtain the following lemma: TEL Preservation Lemma. For each pair of points in the ideal and real models respectively, such that IIIII , if then . Exercise 15. Prove the TEL Preservation Lemma

Temporal Epistemic Justification

slide-51
SLIDE 51

In particular we can show:

  • Corollary. A temporal epistemic property is valid in the ideal

model if and only if it is valid in the real model Since we view TEL as a sort of canonical security logic the above corollary serves as the key justification for our approach. For instance, if we can show in the ideal model that no information dependent on any bit in some key K ever leaves guest 0, then the same holds for the real model.

Temporal Epistemic Justification

slide-52
SLIDE 52

The Missing Link

We glossed over preemption Preemption: An exception handler is interrupted by some other exception (This is avoided in most real kernels AFAIK) We have the following handlers: – irq, scheduling – swi0, resume – swi1, send – exn, exceptions

slide-53
SLIDE 53

Interrupts/Exceptions

Let if can preempt Who can preempt who? And when? – irq irq? – exn exn? – swi0 swi0? swi1 swi1? – exn swi0? exn swi1? exn irq? – swi0 exn? swi0 swi1? swi0 irq? swi1 exn? Etc? – irq exn? irq swi0? irq swi1? Some combinations can be ruled out using reasonable design goals What about the other cases?

slide-54
SLIDE 54

Linearisability

Show that: Behaves as if either: Or:

Guest 1 Guest 2 irq swi0 Guest 1 Guest 2 irq swi0 Guest 1 Guest 2 irq swi0

slide-55
SLIDE 55

How?

Identify linearisation points Points where call ”takes effect” Show that execution steps can be commuted

Guest 1 Guest 2 irq swi0 Guest 1 Guest 2 irq swi0

slide-56
SLIDE 56

How?

Identify linearisation points Points where call ”takes effect” Show that execution steps can be commuted

Guest 1 Guest 2 irq swi0 Guest 1 Guest 2 irq swi0

slide-57
SLIDE 57

How?

Identify linearisation points Points where call ”takes effect” Show that execution steps can be commuted

Guest 1 Guest 2 irq swi0 Guest 1 Guest 2 irq swi0

slide-58
SLIDE 58

How?

Identify linearisation points Points where call ”takes effect” Show that execution steps can be commuted

Guest 1 Guest 2 irq swi0 Guest 1 Guest 2 irq swi0

slide-59
SLIDE 59

How?

Identify linearisation points Points where call ”takes effect” Show that execution steps can be commuted

Guest 1 Guest 2 irq swi0 Guest 1 Guest 2 irq swi0

slide-60
SLIDE 60

How?

Identify linearisation points Points where call ”takes effect” Show that execution steps can be commuted Without affecting observations

Guest 1 Guest 2 irq swi0 Guest 1 Guest 2 irq swi0

slide-61
SLIDE 61

Proving Linearisability

Show irq_entry.pseudo and swi1_entry.pseudo as examples Exercise 16: Show linearisability of irq vs swi0. Will interrupt masking be needed?

slide-62
SLIDE 62

Processor Memory Input Device

Project: Input Device

Memory ”bus” Interrupt Input

slide-63
SLIDE 63

Project: Input Device

The task is to extend the model with an input device which uses an interrupt to signal the presence of new input, similar to a rudimentary unidirectional USB device. The device receives external input on a channel . We treat external input abstractly, and just assume a function that returns the next 32 bit word available on an unspecified input stream, which is not necessary to include in the model. The device delivers the input to the processor through Direct Memory Access (DMA), that is, the device is able to autonomously write its input to a preselected memory address. This is obviously highly dangerous in a virtualised context, which is why this exercise is of interest. The device will have one or more memory mapped registers

slide-64
SLIDE 64

Project: Input Device

The device is configured using memory mapped registers. I could imagine two such registers:

  • A memory-mapped register is accessed like a ordinary memory

location, but potentially with side effects that may cause the internal state of the device to change. Often, the memory- mapped locations are RO or WO. Here, you can ignore this and just assume, e.g., that a write to a naturally RO/WO register has no effect.

slide-65
SLIDE 65

Project: Input Device

Initially, the input device is disabled ( ). Enabledness status is changed by writing to the register. If the device finds an input available in the input stream and DMA is enabled, the device may choose to write the next input word to the address found in the register . Simultaneously, it will disable itself and interrupt the processor to signal the presence of a new input word. One of the two guest will own the device, i.e. its control registers will be located in the chosen guests memory area.

slide-66
SLIDE 66

Project: Input Device

The tasks are the following:

  • 1. Modify the processor semantics by adding a device operating

asynchronously with the processor itself. That is, progress in the processor should not be tied to the device nor vice versa. You may need a scheduler to resolve choices in your

  • semantics. Such a scheduler could be resolved by a suitable
  • racle, for instance as an infinite binary stream. Do not

forget that the existing SPM1 transition rules may have to be looked at again. The ambitious student might want to think about the granularity of your model: Memory accesses are not usually performed as atomic lookups, but instead by first exposing the address to the memory system and then reading the data.

slide-67
SLIDE 67

Project: Input Device

  • 2. Propose a strategy for virtualising the device. Remember that

it is the guest that should ”run” the device, not the

  • hypervisor. Propose two different ways of designing the

hypervisor-guest interface.

  • 3. Choose one of the designs, define the handler

functionality/functionalities, devise a proof strategy following the ideas presented in the lecture, and complete a reasonable portion of the proofs.