You are on page 1of 27

Int J Softw Tools Technol Transfer

DOI 10.1007/s10009-011-0195-9

VSTTE 2009-2010

Formal methods for security in the Xenon hypervisor


Leo Freitas · John McDermott

© Springer-Verlag 2011

Abstract This paper reports on the Xenon project’s use of ported products by Citrix, Oracle, Virtual Iron, and Novell.
formal methods. Xenon is a higher-assurance secure hypervi- Conventional Xen has a relatively good security record
sor based on re-engineering the Xen open-source hypervisor. against typical adversaries and is thus a good basis for a
The Xenon project used formal specifications both for assur- higher-assurance hypervisor. Higher-assurance hypervisors
ance and as guides for security re-engineering. We formally like Xenon provide robust information flow control, tamper-
modelled the fundamental definition of security, the hyper- resistance, and self-protection for communities of users that
call interface behaviour, and the internal modular design. We share execution on a single piece of hardware. To date, only
used three formalisms: CSP, Z, and Circus for this work. one vulnerability has been found in the hypervisor per se. All
Circus is a combination of Standard Z, CSP, with its seman- other reported vulnerabilities have been in the guest operat-
tics given in Hoare and He’s unifying theories of program- ing systems.
ming. Circus is suited for both event-based and state-based The primary goal of the Xenon project is to investi-
modelling. Here, we report our experiences to date with using gate issues in re-engineering an open source software prod-
these formalisms for assurance. uct into higher security assurance than conventional open
source [24]. In this paper, we present some results from
Keywords Xenon · Circus · Theorem proving · Formal our modelling of part of the Xenon API for event channel
modelling · Separation kernel · Virtualisation (i.e., virtual interrupts) communication across guest domains
(i.e., contexts for the virtual machines provided to guest OSs)
1 Introduction and virtual instruction set processors.
Xen is neither safety-critical, nor formally defined. The
Xenon is a higher-assurance hypervisor derived from the con- relative high quality of the existing Xen source code makes
ventional Xen hypervisor [3,5,31] with an emphasis on secu- this re-engineering an interesting research topic, though. That
rity. Conventional Xen was initially developed as a research is because most of the Xen code is relatively easy to mod-
platform by the University of Cambridge Computer Labo- ify into higher-assurance Xenon form, given Xen’s modu-
ratory. Currently, conventional Xen has been implemented lar, self documenting, and simple architecture. For design
on x86, Itanium, ARM, and Power PC processors, on scales recovery, we use a program slicing and inspection tool called
ranging from individual mobile devices to entire cloud archi- CodeSurfer. Our use of CodeSurfer is reported in [22]. The
tectures and supercomputers. Conventional Xen remains an CodeSurfer tool provides deep general understanding that
open-source product but has grown to commercially sup- facilitates discovery of the designer’s intent, but does not
capture the intent as specifications; it provides navigational
L. Freitas (B) facilities for code investigation. This paper reports how we
School of Computing Science, capture and formalise the original designer’s and/or program-
Newcastle University, Newcastle upon Tyne, UK mer’s intent from available source code, using a formal nota-
e-mail: leo.freitas@newcastle.ac.uk
tion. Thus, capturing intent here means formally specifying
J. McDermott what the designer’s code behavioural intent is. Obviously
Naval Research Laboratory, Washington, DC, USA one can make mistakes in such capture, in a similar manner

123
L. Freitas, J. McDermott

that one could mistaken interpret some elicited requirement sor’s external interface. Given Xenon’s scale (e.g., even after
into a formal specification. The point here is that the captured simplifying the Xen code into its Xenon form there will still
intent becomes “the” specification of Xenon for further proof be over 200 hypercalls), we report here part of the work, in
analysis. We rely on NRL’s expertise on Xen and our exper- particular our approach to specifying and verifying security
tise in formal modelling for the accuracy (and usefulness) of for a representative subset of the hypercall interface.
such process. Once this concrete specification of the code’s It would be unwise to construct a complete formal spec-
intent is analysed, various design decisions get properly doc- ification of all the Xenon hypercalls, literally thousands
umented and some times modified due to counter examples of pages, without first using our automated tools to verify
arising from failed proofs. the intended security properties for a representative sub-
We are at a point where most of the Xenon code for virtual set. Verification of such a large interface requires efficient
interrupts has been processed. We envisage applying refine- proofs, which in turn require delicate choices of specification
ment calculation techniques from this concrete specification approach. Automated verification of a representative subset
in order to reach the code, now with rigour in the code gener- provides critical insight into potential difficulties and reveals
ation process gained through the proof scrutiny of the intent approaches that should be avoided. The complete specifi-
captured as the concrete specification. In the use of formal cation can then be constructed by repeating the success-
modelling it is important to distinguish safety-critical from ful pattern developed in the automated verification of the
security-critical software, as they are not equivalent, and we representative subset. This paper reports a successful spec-
are concerned here with security. For instance, a fire-alarm ification pattern and shows how proof revealed the changes
that never works (e.g., is deadlocked) is secure in the sense it needed for verification of the larger specification.
does not leak any confidential information, yet it is not safe First, we describe our approach to applying formal meth-
in the sense it does not do anything useful. ods within the Xenon project, as well as the notion of intent
In the Xenon project, we used formalisms to capture within the open-source software. Next, in Sect. 2 we define
(code’s) intent, define security, and describe the hypervisor’s Xenon’s notion of security, which is an extension of a similar
external interface, i.e. its hypercalls [5]. This formalism is notion for CSP, as well as presenting the formalism used,
Circus, a combination of Z, CSP, and the refinement calcu- namely Circus. In Sect. 3 we present our approach to con-
lus (see Sect. 2, and the next two subsections). The security structing the specification and verification pattern we will use
we are concerned with is strict isolation or separation of host for hypercall behaviour: it contains an example of how the
execution of the virtual machines, i.e., separation of domains. rest of our model for the Xenon hypercall interface will be
The most common abuse cases that we seek to rule out are constructed and verified. We also summarise findings from
the hypervisor becoming the path of least resistance for one theorems proved along the formalisation process using the
guest operating system to attack another; and the hypervisor Z/Eves theorem prover and the CZT Circus tools1 in Sect. 5.
becoming the path of least resistance for an intruder on one After that, we present our non-interference definition of secu-
network to gain access to another network. rity within Xenon in Sect. 4. Finally, we present some conclu-
We can summarise this in terms of the events that take sions in Sect. 6. This work is a joint effort between the Naval
place in the domains. Informally, the Xenon security policy Research Laboratory (US), and Newcastle University (UK).2
is that no untrusted domain should be able to cause, enable,
or prevent any event in another domain. Conceptually, events 1.1 Applying formal methods in the Xenon project
include not only the host execution of instructions but also
traps, exceptions, and interrupts. The practical implication of Understanding all possible behaviours, as well as uncovering
this is that we rule out not only externally induced crashes or hidden and/or mistaken assumptions about requirements or
lockups, administrative control of guest operating systems, the environment are the reason we apply formal methods to
and direct copies of information between guests but also the problem of higher assurance software security. Without
exploitation of hypervisor features to indirectly leak infor- formal methods, we believe it is not feasible to even attempt
mation between guest operating systems. The policy does understanding of this scale. Currently, there are two practical
not apply to hardware, so we are not addressing side channel ways to apply formal methods to higher assurance software
attacks. Also, our policy applies to host execution, not net- security. The first is on a product that is designed and con-
work security. Like its parent Xen, the Xenon hypervisor per structed using formal methods throughout its lifecycle. The
se does not handle network processing or security. Network alternative is to apply them to a suitable product that has been
features are implemented by guest operating systems. developed without formal methods, but is widely used and
In this paper we report on our current work with not only
capturing Xenon’s intent with formal modelling but also 1 http://czt.sourceforge.net.
using Circus and the Z/Eves theorem prover to develop a 2 Some of modelling work also took place while the first author worked
specification pattern for verifying the security of the hypervi- at the University of York (UK).

123
Formal methods for security in the Xenon hypervisor

thus merits the additional effort. The Xenon project is taking security properties (see [23]), which we want to prove that
the latter approach and, as we will explain shortly, has also the Xenon code conforms to.
been taken by two other significant related projects.
Practical systems, constructed with or without formal
Xenon. In the Xenon project, we used formal methods to
methods, even those of high-quality that have very few flaws,
both define security and to specify what that definition means
lack consistency and security checks and contain complex
for the hypercall interface to Xenon. The rest of this paper
constructions that are difficult to verify. Even in high-quality
reports our experiences to date with these applications. The
software, the checks must be omitted and complexity added,
application of formal methods is expensive, too expensive
for performance reasons. Practical formal methods must be
to be applied to a large product that may not achieve signif-
able to cope with both of these realities.
icant market share. For this reason, refining a new product
from correct formal modelling over its complete life cycle is
Related work. The seL4 project [18] has demonstrated
unlikely to result in anything that is used on a practical basis,
that it is possible to use formal methods to show that the cor-
hence our reporting of its key aspects here.
ner cases relating to the omitted checks never happen [17].
We constructed specifications for the external visible
The seL4 project is a formally verified microkernel targeted
behaviour of hypercalls using Circus [26,27,33], as it is suit-
at mobile and embedded devices. The implementation of
able for reasoning with both state-based description of hyper-
seL4 is manually developed high-performance C, running
calls, as well as describing and reasoning about concurrency,
on the ARM processor, a much simpler target than the full
locking, and race conditions. Circus is also suitable for con-
x86 64 instruction set architecture targeted by Xenon. (Con-
structing an unwinding theorem for our refinement of the
ventional Xen supports many processors besides the x86,
security properties (see Sect. 3). Circus allows us to bypass
not only ARM processors but also the IA64 instruction set
unwinding theorems whilst retaining our definition of secu-
architecture. This introduces additional complexity that the
rity [23], and to use its refinement calculus to establish the
Xenon project must address.) It is also important to under-
link between this definition of security and our model.
stand that the seL4 project uses a much simpler definition
of security, the take-grant model [20], and does not enforce
information-flow security. The seL4 approach is both similar Grand Challenge. In applications of formal methods to
and different from the Xenon project. Unlike the Xenon pro- security, an interface specification is not just an intermedi-
ject, the seL4 project designed its microkernel using formal ate refinement on the path to secure code. It also serves as a
methods from the beginning and applied them all the way standalone means of ruling out design insecurities. Practical
down to the source code. However, the seL4 microkernel is examples of this are found in the formal treatment of network
actually a re-implementation of the open-source L4 micro- security protocols [30], where apparently simple network
kernel, which has been implemented many times before. So interfaces have been shown to be vulnerable to attacks based
the seL4 project is in fact working with previously developed on race conditions or interleaving. These practical attacks
open source that has been shown to be very practical. Like the are effective without regard to any flaws in the code level
Xenon project, the final step in constructing the operational implementation, that is, they are design flaws. In our case,
seL4 microkernel is manual development of C source code. we use the formal hypercall interface specification in a simi-
Unlike the Xenon project, the seL4 project has verified all lar manner. We want to be sure that the defined behaviour of
of the implementation of the lowest level of the microkernel the complete set of hypercalls cannot be exploited in some
source code. Since the Xenon software is an order of mag- source-code-independent manner. This is essential for a large
nitude larger than seL4, complete verification of the infor- complex hypercall interface like Xenon. Furthermore, var-
mation-flow security policy over all source is not practical, ious general theories and reusable lemmas, like those for
even though the Circus formalism can be carried down to the pointer, injective functions, and set partitioning have been
source code by refinement, for any subset of practical size. created as a result of this work. A simple (and abstract) the-
Another related project that worked from the source code, ory of security is also discussed. This shows the great ben-
rather than having started from formal methods like seL4, is efits of such a large case-study. For instance, some of these
the Microsoft Hypervisor [19]. From the low-level C source lemmas have been reused in other projects within the Grand
code, they constructed a specification using the verifying C Challenge in software verification [11].
compiler (VCC). It is used as a code-level extended static Given the significant market share of Xen, we believe
analysis tools that handles both behavioural aspects of under- it is worthwhile pursing formal verification and certifica-
lying data structures, as well as concurrency issues. Their tion of a higher assurance form. Furthermore, given its sheer
effort is similar to ours in the sense that it is an attempt to size (potentially 4500 pages of Circus in its final form), the
formally document the code’s intent. It is different from ours underlying complexity and intricacy is self-evident, hence
in the sense that we want to have a more high-level notion of justifying formal modelling.

123
L. Freitas, J. McDermott

Common Criteria evaluation. The Xenon project is not and high-quality modular structure. For example, the source
planning for a Common Criteria evaluation [8]. There are file xen/.../multi.c actually contains 16 distinct
several reasons for this. First, conducting an actual evalua- modules.
tion is expensive and beyond the scale of the available fund- The intent that is most challenging to capture is the
ing. A significant portion of this expense is the cost of the intended behaviour of the software. We have used Dot dia-
independent evaluation staff and the cost of providing full- grams and natural language recorded in several formats,
time internal project staff to interact with the evaluators. Of including both a custom web-based tool and the open-source
even greater importance is the fact that the higher Evaluation Trac project management system. This paper reports how
Assurance Levels [7] (EALs) 5, 6, and 7 of the Common we also use formal methods to capture the behaviour of the
Criteria are not comparable over different nations. So, for Xenon source code. The most abstract behaviour to be cap-
example, an EAL of 5 achieved under US evaluation does tured, for software systems that have security properties, is
not necessarily compare to an EAL 5 achieved under UK the overarching meaning of security. In addition to this, we
evaluation. Furthermore, there are no published protection have also captured the behaviour of the hypercall interface.
profiles for EAL 5, the most likely Evaluation Assurance
Level for Xenon. Because of its size, an evaluated version of
Xenon is unlikely to satisfy an EAL above 5. 2 Background

1.2 Capturing intent in open-source software We chose the Circus formalism [26,27,33] to define secu-
rity, i.e., what it means for the Xenon hypervisor to be secure.
The key characteristic of higher-assurance software is we Xenon enforces information-flow security. Most formal def-
have greater confidence it satisfies some specific properties initions of information flow security are not preserved by
[16], such as information-flow security. Properties are a more refinement. Our first choice of formal security definition
precisely defined instance of “intent”: what the software is was chosen from the family of CSP-based4 independence
supposed to do, as opposed to what it actually does. definitions of Roscoe, Woodcock, and Wulf [29] as fur-
Open source typically does not capture intent, and the ther developed by Roscoe [28], since it preserves refine-
Xen hypervisor is no exception. By intent here we mean the ment. Definitions of information flow are subtle and are not
designer’s objectives when making decisions, which can be addressed simply, even in a powerful notation like CSP. The
(or here we claim usually is) not as accurate as intended. Open basic notion of non-interference is that events taking place
source assumes that cases where the code does not satisfy the in one domain should not flow/leak information into another
intent are so infrequent and obvious that it is not cost effective domain, via host execution on shared hardware. For a con-
to document. It is expected in conventional open source best crete instance, a compromised guest operating system vir-
practice that there is a small group of developers who deeply tualised on an information-flow secure hypervisor should not
understand the intent of the code. This may give a (false) be able to leak medical records it processes, to another guest
intrinsic perception that there is no need for specification. operating system running in a different domain but virtua-
However, this is not sufficient for higher-assurance. Docu- lised on the same hypervisor. That is, the shared hypervisor
mented intentions and design decisions must be subjected to a should not become a path of least resistance for information
constructive but adversarial third-party review [1, Chap. 26], flow. Without this kind of security, an adversary could leak
for higher-assurance. For that, we see formal specification as information without violating network security, by exploiting
our best device. the shared execution environment. Information-flow security
Capturing intent is a key part of the Xenon project. We is of particular interest in cloud computing infrastructures,
have used a variety of means to accomplish this. Some where cloud users expect their virtual machines to be sepa-
intent has been captured using an informal Wiki format. We rated as though they were separate physical machines.
have used MoinMoin3 to capture both a security architec- In many cases, information-flow security disallows all
ture description and an assurance argument. Some intent information flows between all entities. An example would
has been recorded there as well, in the form of a module be cloud platforms that expect their computation to be kept
guide written in informal natural language, that explains separate from each other. However, there are applications of
the intended modularity of the implementation. The Xen information-flow security where some flows are allowed. In
implementation modules do not correspond to the source file these cases, the entities are considered to have a partial order
structure, i.e., there is nothing corresponding to the pack- defined for their information flow. Informally, if we have
age or class structure of an object-oriented language. Nev- entities x and y (for Xenon this would be domains) whose
ertheless, Xen (and its child Xenon) have a well-defined
4 Unless otherwise specified, this paper is referring to Roscoe’s CSP
3 http://moinmo.in. semantics [28].

123
Formal methods for security in the Xenon hypervisor

information flow policy is x < y then information is allowed events, and L = F \ H is the set of Low CSP events, then the
to flow from x into y but not vice-versa. When discussing stable-failures lazy-abstraction of S with respect to H will
a general case, we refer to entity x as “low” and entity y as have the form
“high”. The “high” entity’s information has “higher” sensi-
tivity than the “low” entity. In many cases, the partial order
is defined to be a lattice, with the system software being at
LH (S) = (S
F
|| HCHAOSH ) \ H (1)
the bottom of the lattice [9].
What we are trying to achieve here is extending an elegant Given this lazy abstraction, we can define the CSP inde-
notion of noninterference through refinement. The original pendence definition of security as the deterministic lazy
paper [29] discusses non-interference in CSP, which encom- abstraction of the system S with respect to High,
passes (concurrent) behaviour over simple states, whereas
our specification uses Circus, which includes both cur-
rent behaviour and state-rich and trace-rich specifications of LH (S) det (2)
abstract data types used by the concurrent system.
where the equivalence is a stable-failures equivalence, and
2.1 Defining security the notation P det means the process P is deterministic. Fol-
lowing [28,29], a CSP process is deterministic when
From this family of definitions, we have chosen a defini-
tion based on the stable failures model of CSP. That is, we
s a ∈ traces(P) ⇒ (s, {a}) ∈ failures(P) (3)
consider neither divergences nor infinite traces. These dif-
ferences do not matter for our application of independence
to Xenon. There are three reasons for this choice: (1) lazy because we are using the stable-failures and trace models of
abstractions (see below) can introduce infinite nondetermin- CSP, Eq. 3 does not mention freedom from divergence.
ism through hiding, and we wish to avoid this theoretical Informally, the interesting part of this definition is the use
complexity; (2) because we will ultimately carry this defi- of failures to define security. A trace approximates a sequence
nition of security into the state-rich Circus formalism, thus or history of events that a system has already performed; the
introducing state complexity into our model, and we wish to failures of a trace are the events that a system is not prepared
minimise trace complexity in practice; and (3) for practical to do, at each point in the trace. So our definition says that
engineering reasons we assume that any attempts to flow security can be violated by disabling or temporarily denying
information in an unauthorised manner, via divergences or a service or feature. This failure-based definition of security
infinite traces, will be easily detected in a hypervisor. In other has a built-in means of addressing attacks based on faults or
applications of independence, this may not be the case. Yet, crashes, in addition to attacks based on successful requests.
for the hypervisor, divergence or infinite traces will manifest The best explanation of Eq. 1’s definition can be found in
themselves as a malfunction, which is then investigated by Chap. 12 of Roscoe’s text [28]. This definition “subsumes”
the user, and hence game over for the attacker: he has been the High user (guest operating system) with the CSP constant
discovered. Again, remember the difference between secu- CHAOSH that not only can perform all possible sequences of
rity and safety (e.g., it is perfectly safe to do nothing, albeit High events, i.e., including event sequences a well-behaved
useless), and our emphasis on the former. user would not generate, but also can arbitrarily refuse to per-
This CSP-based definition of Xenon security defines sep- form any of them as well. If this kind of arbitrary behaviour
aration between Low and High as the independence of Low’s by the High part of the system cannot cause the Low part of
view from anything High might do, where Low and High are the system to behave in a non-deterministic way, then High
just sets of possible events from the hypervisor (Low) and cannot influence what Low sees and no information flows
the user OS domain (High) that are disjoint, and partition from High to Low.
the whole set of visible events (F). In the context of Xenon This CSP based independence definition is a good one
(or Xen), Low and High are hypervisor domains [3,6,31] for practical information-flow security, but it is difficult to
that contain the guest operating systems hosted by Xenon relate it to the state-rich implementation of an actual hy-
(or Xen). So the formal definition says that events caused pervisor. For this reason, we chose an alternative formalism
or observed by a Low guest operating system are indepen- that can express independence definitions in a natural way,
dent of (or not influenced by) events caused by a High guest while providing for a state-rich implementation of concur-
operating system. In CSP, we express our definition of secu- rent behaviour formally. In this context the choice for Circus
rity as follows: if S represents the hypervisor and its guest is quite natural, given it already is a state-rich extension of
operating systems as a (composite) CSP process, where F is CSP with similar notions of refinement, traces, and failures.
the complete set of visible events, H is the set of High CSP Circus is explained in more detailed next.

123
L. Freitas, J. McDermott

2.2 Circus The cookie machine is a process with state as follows:

Circus is a combination of (ISO Standard) Z [15], impera-


process CookieMachine =
 begin
tive5 CSP [13,28] and the refinement calculus [2]. Like Z,
Circus models are formed by a sequence of paragraphs that
define types, sets, relations, and schemas. Unlike Z, Circus it contains the amount of cookies the machine has, which is
paragraphs may not only be Z paragraphs, but also chan- bounded, and the amount of money entered by the user.
nel, channel set, or process paragraphs, which are CSP
constructs. Channels organise the events of Circus spec- State
ifications. An event in Circus is a (<name>, <value>) quantity, money : N
pair; <value> gives the value communicated by the event
over a channel <name>. All channels must be named and quantity ≤ MAX QUANT
their types specified using Z expressions (generic channels
are also allowed). Previously defined channels may be col-
lected into channel sets. Process paragraphs define Circus The state is local to the process CookieMachine and is not
processes that may contain Z-style (private) state declara- accessible from other processes.
tions, actions, guarded actions, communication prefix, and
other actions. Each process must end with a nameless “main” state State
action that defines behaviour of the process. Actions and
whole processes may be operated on by CSP-style opera-
tors, such as parallel (x), external choice (), etc. Next, we define two state operations for cookie delivery as
Readers familiar with Z or CSP will find Circus mod- Z schemas, which are labelled records with invariants, where
els to be nearly “self-documenting”. For Circus, the next new lines represent conjunction. It is often used to repre-
example shows a specification of the a state-based vending sent a relational view of the state as before (x) and after (x  )
machine6 for cookies. In what follows, we explain both the values. OutputCookieOk returns on output variable o!7 the
Z and CSP aspects of this example in detail. We assume the cookie delivery status. It is ok, providing there is at least as
reader is somewhat familiar with both Z [32] and CSP [28] much money as the cookieVal constant (e.g., the user pro-
when discussing the Xenon model later on. First, we define vided enough coins), and the quantity of cookies is not 0
bounds for the price and amount of cookies available as a (e.g., the machine is not empty). It then reduces the money
natural number by this value, and quantity by one. The Δ means both State
and State are in context, where State is a copy of State with
all variables and invariants dashed.
cookieVal, cookieQuant, MAX QUANT : N
cookieQuant ≤ MAX QUANT
OutputCookieOk
ΔState
We also add a status flag determining if a cookie was dis- o! : COOKIE
pensed or not.
money ≥ cookieVal
COOKIE ::= ok | notok money = money − cookieVal
quantity > 0
quantity = quantity − 1
There are three channels: channel in synchronises with the
o! = ok
user process when inputing money; channel out gives the
cookie request status; and channel change returns to the user
the amount of change involved.
If these conditions are not met, i.e., if either there is not
enough money (money < cookieVal) or the machine is empty
channel in, change : N (quantity = 0), then State remains unchanged (as given by
channel out : COOKIE ΞState, which includes ΔState and that quantity = quantity
and money = money ), and o! returns a not okay status.
5 Processes may contain guarded commands, e.g.,

if a > 0 −→ x , y := a, b fi . 7 Like in Z, output variable names have a shriek (!) in their name by
convention. Similarly, input variable names have a question mark (?) in
6 The classic CSP example, here augmented with state. their name.

123
Formal methods for security in the Xenon hypervisor

OutputCookieNotOk is false. This communication at channel in affects the trace


ΞState of the process visible outside the process. Another guarded
o! : COOKIE action needed is about the cookie status output, providing
there is enough money. Because all input and output variables
One can also add comments.
in Z must be in context, we define a local variable o, which
money < cookieVal ∨ quantity = 0
is bound to o! in OutputCookie executed next. It updates
o! = notok
the state and terminates (e.g., behaves like Skip). This is
followed by sequential (action) composition to the output
The overall OutputCookie operation is the disjunction of communication over channel out the calculated cookie sta-
these two operations. One can imagine this as an API function tus in o!. After that, change is returned to user, even if zero,
that computes successful and error cases. and the action successfully terminates.

OutputCookie =
 OutputCookieOk ∨  (money ≥ cookieVal)
Output =
OutputCookieNotOk (var o : COOKIE • (OutputCookie);
(out !o −→ change !money −→ Skip))
The state is initialised next using a schema. The visible (trace)
behaviour of a schema is just Skip (e.g., no event followed Finally, the main behaviour of process CookieMachine is
by termination), yet it changes the private/local state of the defined by the next main action, which follows from the (big-
process. It simply sets money to zero, and the quantity as spot) “•” token.
the fixed, yet underspecified, quantity within the maximum
bounds (cookieQuant ≤ MAX QUANT ). • InitState ; (µ X • (Input  Output) ; X)
InitState It initialises the state first, followed by a loop of an external
State  choice between input and output actions by the user or envi-
money = 0 ∧ quantity = cookieQuant ronment. Loops are specified using the usual µ construct,
and external choice means the process waits for the envi-
ronment on available events, rather than internally deciding
In Z, state initialisation usually comes right after state dec- which event to choose.
laration, but one can add it at any point after the state dec-
laration. Next, we define the state operation associated with end
the user inputing money: it is executed right after the user
communicates the input value x below, which is bound to x?, The process is then enclosed with end. Note the literate style
providing there is not enough money yet. of specification, where textual documentation and formal text
are intermixed: and the Circus and Z tools used in Xenon
InputMoney actually process the very LATEX where the specifications are
ΔState; x? : N created and documented (with English commentary).8 The
money ≤ cookieVal ∧ money = money + x? next step would be to model the user process or the environ-
ment requesting cookies and providing money, which is then
put in parallel with the CoockieMachine process given the
After declaring the state operations using Z schemas, we can right channels to synchronise; we leave this out.
define the behaviour of the process using Circus actions.
Action Input is a guarded input communication action: when- 2.3 Lazy abstraction in Circus
ever the guard about enough money available being true,
money input through in is read on x, and after that the Even though Circus incorporates CSP semantics, we can-
InputMoney schema is executed, where the x read is bound not (re-)use Roscoe’s CSP independence definition directly
to the x? input of InputMoney (see Eq. 1). The CSP definition of independence requires
the lazy abstraction of the separation hypervisor system to
 (money ≤ cookieVal)
Input = remain deterministic in the presence of a Chaos process at
in ?x −→ (InputMoney) High events. There is a Circus action named Chaos but it
has semantics that are unsuitable for our independence-based

As in CSP, guarded actions in Circus are deadlocked (as in 8Apart from the “informal” ellipsis (. . .), all else is recognised by the
process Stop that terminates refusing all events) if the guard Circus tools and Z/Eves prover.

123
L. Freitas, J. McDermott

definition of information-flow security. In Circus, the action concurrency, locking, and race conditions. This was one rea-
Chaos is defined [26] as Chaos =  R(false true), a reactive son we abandoned this approach and switched to the Circus
process that providing the impossible (false), may do any- tool chain for a second interface-level specification. Since
thing (true) at any point in its execution, including diverge.9 Circus contains ISO-Standard Z, as well as CSP, it is well
Chaos as used by [28,29] is a process that can do anything suited as the target formalism to use.
but diverge, namely ChaosA = Stop (?x : A −→ ChaosA ). The other reason for switching to Circus was the difficulty
We define in Circus Balagan10 that has the desired in constructing an unwinding theorem for our refinement of
divergence-free behaviour. Circus process Balaganc is pre- the security properties. Since our definition of security is
pared to engage in any possible sequence of events within the trace-based, we need an unwinding theorem or unwinding
type T of channel c (c?x), or (nondeterministically, ) block rules that show how the trace-based definition applies to indi-
(Stop) instead. The µ operator represents recursion over X, vidual states and state transitions. This can be awkward when
whereas the first (big) spot (“•”) marks the starting point of mapping from an event-based formalism (the original CSP
the process main action. The second spot opens the scope for model) to a state-based formalism (Z). Use of the Circus for-
the recursive definition using µ. malism allows us to bypass unwinding theorems but retain
our definition of security, also in Circus [23], and to use its
channel c : T refinement calculus to establish the link between this defi-
process Balaganc = begin nition of security and our model. To clarify, we present an
• (µX • (c?x −→ X) Stop) example unwinding rule (a simplified example, not a rule we
end claim applies to any Xenon specification). Recall our defi-
nition of security is given in Eq. 3 and is based on traces.
If we denote channel set F as the set of all channels used in a One needed unwinding rule defines an equivalence relation
(composite) secure process S, and channel set H as the set of on states (rather than traces) that calls two states equivalent
channels used by the High part of process S, we can define a when both states, with the High parts left out, have the same
lazy abstraction for Circus in lieu of Eq. 1 as possibilities for transition into a future state. Here, instead of
the failures over trace of events, we have refusals associated
 (S  H  BalaganH ) \ H
LazyAbstractionH = with a specific state. Informally, refusals are the input, next
state, output combinations that would not happen in a given
Just as in the CSP lazy abstraction, this definition subsumes state of a process.
the High process with a Circus process that can perform arbi-
trary sequences of events on the applicable channels as well ∀ Qi , Qj : States • Qi ≈ Qj ⇒
refusals(Qi ) \ H = refusals(Qj ) \ H
as deadlock. It cannot, however, interfere with the system
Low events.

This one unwinding rule (Qi ≈ Qj ) probably would not suf-


3 Defining secure hypercall interface behaviour fice by itself. We would have to show that the collection of
rules is sound for all of the language features we use in our
In the Xenon project, we constructed two interface specifi- specifications for Xenon.
cations of the hypervisor, i.e., a specification describing the Our second, Circus-based specification, is about the same
visible behaviour of the hypercall interface. The first spec- size as the Z-based specification, but also describes concur-
ification was constructed using Standard Z in the Oxford rency. That is because we reuse almost all the Z model, but
Style [32]. It did not document the precise structure of the add process-algebraic features from CSP to describe how
implementation but did describe its externally visible behav- the Xenon state is to change. If we tried to accomplish this
iour. The resulting model would be significantly smaller than description of state transitions in Z alone, we would need to
the internal design-level specification. We estimated its final define concurrency explicitly in our specification, including
size as about half the size of the internal design specifica- theories about traces, parallel execution, and interleaving.
tion (to be described in the next section), that is 4500 pages Since the second specification represents a significant
of ISO-Standard Z, including English commentary. We also industrial use of Circus, we describe it in some detail. The
encountered difficulties in describing and reasoning about complete specification is quite large, so we only present
selected portions of it. For the most part, our presentation
9 Its semantics expanded is interpreted as if wait then Π else tr ≤ tr  ,
follows the order of presentation in the specification itself.
which means if the process is waiting, nothing changes and it is in The Circus tool suite allows the natural language to be
deadlock; else, anything can happen and the trace history is preserved. interspersed with the formal specifications, like in literate
10 A modern Hebrew word for chaos. programming. We shorten the example by omitting parts of

123
Formal methods for security in the Xenon hypervisor

the specification. In Sect. 5, we present a summary of the these top-level sections themselves inherit other smaller sec-
effort involved. tions, which are the ones closely related to the underlying C
code file structure. These last three sections define both the
3.1 Specification sections organisation specific hypercalls and the supporting structures needed to
define overall hypervisor behaviour.
From its Standard Z heritage, Circus inherits the concept
that allows us to organise the specification in sections. This 3.2 Capturing key relationships
sectioning resembles the underlying C code directory struc-
ture. Textually, they are just markers with a name and a list We want to not only verify security from our abstract
of parent sections. We omit them here to save space, yet we model [23], but also identify problems with the implementa-
briefly discuss the (transitive and acyclic) parenting relation- tion, so our specification is organised to capture some of the
ship between these sections. essential relationships of the implementation. We are work-
Our specification begins with some of the definitions from ing from the code upwards to a concrete Circus specifica-
the Xen Security Modules (XSM) subsystem: in Xenon they tion, which we are currently proving refinement with respect
are used to characterise allowable information flows. When to a previously published abstract specification for security
Xenon is configured to allow some information flows, then through non-interference already mentioned.
XSM defines the “high” and “low” partial order relation of Foremost of these is the triangular dependency between
the allowed flows. Security enforcement in Xenon, like its the three major entities from the Xenon state space: virtual
parent Xen, is largely inherent in the virtualisation, rather contexts for guest domains, virtual instruction set processor
than being in some specific security module. The design of VCPUs, and virtual interrupts or event channels. These three
Xen enforces a “no flows allowed” policy, without any use of entities depend on and refer to each other. For example, a
XSM. However, XSM encapsulates additional logic to define specific domain contains “tables” that “manage” the VCPUs
“some flows allowed” policies on top of this inherent mech- and event channels of that domain—the implementation even
anism. Once some information flows are allowed, we need allocates space for event channels through their domain struc-
to not only prove that XSM provides the correct definition ture. So it would seem natural to make domains the defin-
of allowable flows, but that it also does not introduce nonde- ing entity. However, in the implementation, event channels
terminism and thus violate the fundamental noninterference refer to VCPUs and domains. VCPUs refer to domains as
security policy. well. This mutual dependence between key components is a
We also partially present the Xenon programmer’s model common feature within kernel design (e.g., a similar depen-
defining concepts of the underlying hardware and compilers dency exists for the seL4 kernel). Some hypercalls do not
and hence giving a modular structure to the whole specifi- have a parameter for the applicable domain, but determine
cation. In a hypervisor, what is usually considered low-level it internally, from the scheduler. We have tried to reflect this
hardware detail becomes instead the principal abstraction to structure in the specification as much as possible, as they are
be exported. For example, in Xenon the page dirty bit is not to essential relationships to be captured.
be hidden but instead manipulated and exported as an exter- The first step in doing this is to define identifiers for
nally visible abstraction. The abstraction lies in whether a domains, VCPUs, and event channels. Then we define for
particular page dirty bit is a virtual page dirty bit or a real each specific component state schemas name as: Domain,
hardware page dirty bit. So we need to talk about bits, bytes, VCPU, and Evtchn. Triangular references, e.g., VCPU to
and machine words early on and they never really disap- domain to event channel to VCPU, are addressed by hav-
pear. We borrow the term programmer’s model from the Intel ing identifiers to the appropriate entity in the referring state
assembly language programming guides [14]. schema. These specific state space schemas are then pro-
Both these sections inherit the Circus toolkit section moted (e.g., using Z state promotion [32, Ch. 13]) into a
containing an extension of the Standard Z mathematical tool- general state space schema HypState containing functions
kit. Next, a section for Xenon defines basic types and con- dmns, vcpus, and evtChns that uniquely identify the respec-
stants that are provided by the Xenon implementation. It tive entities for the hypervisor. Such mutual dependence is
inherits both the XSM and programmer’s model sections quite common in kernel design, since we are mostly always
and hence (transitively) the Circus toolkit as well. Next we working without recourse to any defined entity.
have the hypervisor section containing the various parts of An interesting complication occurs because a specific
the local/global state and their operations, as well as a guest Domain state must contain “tables” of event channels and
domain section including the guest OS specification. The VCPUs, from the global state. Update of a specific local state
hypervisor section inherits Xenon, whereas the guest section then appears to be changing the global state, e.g., evtchn =
inherits the hypervisor section. Finally, the system is the com- evtchn ⊕ {p! → local evtchnID }. That is, the after state
bination of the whole of these sections. Notice that some of of the event channel table (evtchn ) is the original state

123
L. Freitas, J. McDermott

(evtchn) updated on a nondeterministically chosen mapping require signed words.


between a port number p!, which is also an output, and the
(local evtchnID ) local event channel id. On the other hand,
BIT == 0 . . 1
from local operation schema on event channels, it appears to
WORD == { w : N →
 BIT | ∃ n : N • dom w = 0 . . n }
be updating global state since the function evtchn maps to
event channel identifiers from the global state. However, at
this local level, no more is said than necessary about event With this definition, which is close enough to the Z definition
channel identifier. Conditions relating the specific operations for sequences, we prove useful rewrite rules like
on a specific state’s evtchn function to the global state are
given in the corresponding framing or generalisation schema, WORD ∈ N →
  BIT
as usual in Z promotion, when these local state operations ∀ w : WORD • dom w = 0 . . # w − 1
update the global state where they belong. For instance, a
typical example of promotion is a system like a simple mail That is, a word is a finite partial function (→)
  with domain
server, where the global state control system-wide opera- from 0 to its size minus 1. These lemmas are very important
tions regarding user mailboxes like creation of a new user to make proofs about WORD smooth.
account, whereas the local state are user-level operations on Fundamental data types from the x86 64 hardware and
their mailboxes like sending or receiving an email. Thus, C programming language are defined as words of specific
when a user-level operation is promoted into the global state, size. (Recall that Xenon code is restricted to 64-bit imple-
it gets “framed” into the specific user mail box. A similar, mentations.) We also define a type Bound to be used in places
yet slightly more complicated approach, is taken here to pro- where the implementation is using boolean-valued functions
mote VCPUs and event channel updates within Domain and for decision making.
the global hypervisor state—in a way, Xenon has a kind of
double-layered promotion.
As in the Xenon implementation, the operations on a Byte == { w : WORD | # w = 8 }
specific state are not cleanly organised into operations on Word == { w : WORD | # w = 16 }
either VCPUs, event channels, or domains. Instead, for each Doubleword == { w : WORD | # w = 32 }
hypercall, an operation on the specific state affected by that Quadword == { w : WORD | # w = 64 }
hypercall is built up from local-state schemas partially defin- Unsigned == Doubleword
ing each aspect of the operation. This state-specific hypercall UnsignedLong == Quadword
is then promoted or generalised, to relate it to the general state Bound == {0, 1}
of the hypervisor process, accordingly.
Other functions about least and most significant bits for
3.3 Programmer’s model endianness calculations are also defined, and omitted here
for simplicity.
This section contains types and other definitions for the
underlying hardware, as seen by the Xenon programmer. It
3.4 Hypercall interface
also provides types and definitions for constructs and arte-
facts provided by the C programming language, as defined
The hypercall interface is modelled using Circus channels.
by gcc 4.4 using the std=gnu99 flag. This program-
Like its parent Xen, the Xenon hypervisor interface has a
mer’s model defines the hardware details that are exported to
“signature” comprising a collection of hypercall operation
the hypervisor interface. As we discussed earlier, all of the
codes and hypercall parameter structures. The hypercalling
bits, bytes, and words provided by an x86 64 instruction set
domain is an implicit parameter, defined by the VCPU cur-
processor must be exported to the “user” interface, i.e., the
rently scheduled to run.
hypercall interface. Rather than define these as we go, we
The first step in defining the Circus channels of the
encapsulate them into the programmer’s model section, to
hypercall interface is to define the types of the values that are
increase modularity in our specification. We shorten some of
communicated by the Circus channel events.12 The val-
the specification names in the paper to save space.
ues communicated through the hypercall interface include
We begin with basic bit and byte-level data types. A
domain identifiers, VCPU identifiers, and event channel port
unsigned word is defined as a partial function (→), rather
than as sequence, so that the least significant bit (LSB) is
at position 0.11 This version of the specification does not 12 Xen virtual interrupts are called event channels, whereas Circus
channels are modelling devices used for synchronisation purposes
11 Z sequences have 1-based indexes. between guests and the hypervisor processes.

123
Formal methods for security in the Xenon hypervisor

numbers. The hypercall interface also includes “operation MAX EV TCHNS, DOMID SELF : N
codes” or “sub-command” names. For example, there is only MAXdomID, MAXvcpuID : N
one hypercall covering event channels, but each event chan- MAXevtchnID, MAXhypercallOP : N
nel hypercall has a parameter that determines the specific
MAX EV TCHNS = 4096
operation that is performed by the event channel hypercall,
DOMID SELF = 32752
e.g., allocate an event channel, close an event channel, send
MAXdomID ≥ 2 ∧ MAXvcpuID ≥ 6
on an event channel, etc.
MAXevtchnID ≥ MAX EV TCHNS ∗ MAXdomID
We define unique identifiers for domains (i.e., Xen and
MAXhypercallOP ≥ 11
Xenon term for virtual machine), VCPU’s (i.e., a virtual
machine can have more than 1 VCPU), and event chan-
nels. In the implementation, VCPU identifiers are not unique We define “types” for the domain, VCPU, and event channel
outside of a specific domain, but we do not specify that. identifiers, and hypercall operation codes. We add constants
DOMID SELF is a constant for self-reference when the for specific VCPU identifiers to be used in renaming. We also
hyper-caller does not know its domain ID. The value of define the port number type, based on MAX EVTCHNS.
this constant is taken from the implementation; no domain
has this value as its recorded domain identifier. We have an DomID == 0 . . MAXdomID
axiom about the lower bound of domain ids (MAXdomID), VCPUID == 0 . . MAXvcpuID
since we need to have at least three domains. Domain0 EvtchnID == 0 . . MAXevtchnID
(dom0) is a trusted guest outside the hypervisor that serves HypercallOP == 0 . . MAXhypercallOP
as the management interface to the actual hypervisor. It is PortNumber == 0 . . MAX EV TCHNS − 1
allowed to perform security privileged hypercalls. That is,
any hypercall made by dom0 will be allowed access, whereas and some specific operation codes
some hypercalls made made by unprivileged guests will
be disallowed. Unprivileged guests (or user domains, say doEvtchnAllocUnbound : HypercallOP
dom1 . . domMax) are for user operating systems. In prac- doEvtchnBindInterdomain : HypercallOP
tice, the number of guests is an important factor for the sca-
lability of the technology and its importance to industry. For
3.5 Error codes
example, dom0 can make event channel hypercalls to cre-
ate and link event channels to arbitrary domains, including
Xen and Xenon hypercalls use error codes based on the
itself. Unprivileged domains can only send and receive via
Linux definitions. We also follow the Linux/Xen practice
their event channels. Domain zero is created by hand, so to
of reporting success as the “error” rcok. We include some
speak, in the Xen boot code. Other domains are then cre-
of them here to support documentation of errors reported by
ated by dom0, as requested through its trusted user inter-
the hypervisor interface. This definition assumes values as
face.
found in the header file errno.h. A complete discussion
We establish the maximum number of event channels
of what file precisely constitutes the effective errno.h is
per-domain here because event channels are referenced in
beyond the scope of this specification.
the domains by their port number, thus making event ids
known to the hypervisor only. Notice that even though
the maximum number of event channels for a domain is RC ::= rcok | eperm | enoent | esrch | enomem
defined as MAX EVTCHNS, we need at least that many | eexis | einval | enospc | emediumtype
event channels for each domain because port numbers are | xsmAccessDenied
not unique outside a domain. That is, the same port num-
ber 1 . . MAX EVTCHNS can be used in more than one This version of the specification combines XSM error codes
domain, but the event channels in each domain are unique to with the error codes in errno.h.
that domain. Duplex communication between two domains
requires two event channels, one for each direction, where a 3.6 Hypercall parameters
per-domain port number is associated with each end of each
channel. Each domain’s view of its channel’s remote port Hypercall parameters are passed as “lists”, and they are
number must be consistent with the remote domain’s view described by finite functions. Each hypercall has its own
of its local port number for that same channel. To repeat for specific parameter structure. We use a single parameter list
clarity, the hypervisor can “see” the two event channels, with type to simplify the channel structure. Since Xenon has well
one event channel in each domain, but the domains can only over 200 hypercalls, per-hypercall channel types would be
see the port numbers. unwieldy.

123
L. Freitas, J. McDermott

Since each hypercall will contain different types (e.g., (local-)state updates. We are working on a version of the
domain IDs, port numbers, grant table handles, memory allo- specification to include a scheduler that faithfully captures
cation sizes, etc.), in different positions on the list, we do not implementation issues in the scheduler. Xen Security Mod-
want to apply too much type structure to the parameter list ules is a policy decision point in the Xenon internals; if Xenon
elements per se. We do limit the size of the possible parame- is configured to allow some information flows, it checks a
ters, yet present them here with a specific limit to the size of requested hypercall to see if the it should be denied, accord-
parameter lists. ing to the configured information-flow partial order. XSM
supports complex configurable policies. A complete speci-
MAX HCParam : N fication would model this. In our specification, XSM has a
MAX HCParamList : N fixed policy, as described in Sects. 3.7.1, 3.7.2, and 3.7.3.
Recall that Xenon (and its parent Xen) by default enforce a
MAX HCParamList = 128
strong no-flow policy, without XSM. We need to add XSM
to not only check that allowable flows happen as configured
Given a bound, we define the type.
but also that the XSM mechanism does not introduce nonde-
HCParam == 0 . . MAX HCParam terminism. In practical systems, the introduction of a secu-
rity feature can, through unintended consequences, make the
The current Xen/Xenon code uses no more than five param- overall system less secure. Formal methods help to rule out
eters for a hypercall, but a formal specification may need these unintended consequences.
auxiliary parameters. We define the “parameter list” type as The security properties of the specification depend on
a finite function, with a maximum list size of 128. We used being able to partition events into classes between which no
(p = ∅) instead of (# p > 0) to avoid finiteness proofs information should flow. Following tradition and with no loss
involving set cardinality (#). of generality, we name these classes High and Low. Part of
our scaffolding is the free type PROOF LABEL that defines
HCParamDom == 0 . . MAX HCParamList these labels.
HCParamList ==
{ p : HCParamDom →
  HCParam | p = ∅ } PROOF LABEL ::= Low | High

The implementation’s evtchn_alloc_unbound.c Values of type PROOF LABEL are used as types of chan-
hyper call has three parameters: the local domain and remote nels, to label the (Circus) events of our specification, which
domain IDs as input, and the number of the allocated event will form the system traces.
channel port as an output We define these parameters as spe-
cific “lists”. As these lists are reused across various points, AllLbl, HighLbl : P PROOF LABEL
we have a general type to represent all of them, followed by
appropriate type-aliases. AllLbl = {Low, High} ∧ HighLbl = {High}

evtchnParamIN == 0 . . 1 → HCParam Security labels do not appear in the hypercall parameters of


evtchnParamOUT == 0 . . 0 → HCParam the implementation, but are implicit. These labels are part
evtchnAllocUnboundParamOUT == evtchnParamOUT of the communication protocol through the hypervisor chan-
evtchnAllocUnboundParamIN == evtchnParamIN nels. We make them explicit in the specification because they
are used later for proofs about security.

3.7.1 Xen security modules


3.7 Xenon security modules
Xen Security Modules (XSM) provides a substantial portion,
Besides the proof labels used to show that high informa- but not all of the security enforcement mechanisms for both
tion does not flow into low domains, there are two signifi- Xenon and its parent Xen. XSM offers a choice between two
cant structures: the scheduler schemas, and the Xen Security mechanisms: XSM proper, which functions like the secu-
Modules (XSM) functions. The scheduler does not model rity enhancements of SE Linux; and Access Control Module
a complete Xen scheduler, but merely generates the com- (ACM), which functions like security models such as the Chi-
plete set of Circus traces. Xenon’s actual scheduler is com- nese-walls model or a type-enforcement non-discretionary
plex; too complex for this initial version where our chief access control model [31]. XSM policy decisions are imple-
concern is discovering a way to verify the security of the mented as C function calls at key points in the Xenon imple-
interface with respect to non-interference in the context of mentation. There is one function for each security decision

123
Formal methods for security in the Xenon hypervisor

that must be made inside the hypervisor. Security (yes-or- 3.7.2 XSM check allocate unbound event channel
no) decisions are based on the (usually pairs of) identifiers
of the domains involved in a request. Our specification fol- For the allocation of unbound event channels, defined later
lows the same approach, defining one function for each policy in Sect. 3.14 (see schema EvtchnAllocUnboundSuccess), the
decision that must be checked. This function-based approach XSM policy permits the hypercall (e.g., returns 1) if the
can model either IBM’s Access Control Module [31], or requester is either domain ID zero, the hypervisor itself, or
NSA’s Xen Security Module [6]. Instead of defining a func- the request is for a loopback channel (i.e., a domain request-
tion directly, as one would do in a HOL-like theorem prover, ing a virtual interrupt for itself). For every other domain
we use a relational space approach, which is more tuned to known within this XSM security policy space, the hypercall
the set-theoretical notions in Z and the Z/Eves prover, as this request is denied (e.g., returns 0). A request for an unpriv-
makes proof easier (e.g., descriptions are closer to what the ileged domain to allocate an unbound channel destined for
tool at hand handles well). We begin our (fixed) example another unprivileged domain is denied. What we want is a
description of security by defining a space of domain identi- partial order over all domains except domain zero, such that
fiers of interest. These are all the reflexive domains (i.e., secu- none of the domains are related (x < y), as in the example in
rity is not breached by a domain requesting a virtual interrupt Sect. 2). Essentially, this is XSM duplicating here a built-in
for itself); all the domains can make requests to the security policy. Apart from domain zero, no two domains are allowed
priviledged control domain (dom0). Finally for the sake of to flow information. This is a good configuration for proving
our explanation, we make our notion of security for other that XSM, as a mechanism, does not introduce nondeter-
allowed domains quite lenient: it only imposes that between minism. In the definitions presented here, only the dom0 is
two different domains, the target domain (t) is not the privi- considered a privileged domain. Other security policies may
leged control domain (dom0), as this already covered by the want to relax that restriction by defining appropriate domain
basic domains. These are composed together using set the- relation spaces accordingly. We define a function space for
ory to make the minimum relationships of domains covered this policy below
by the XSM as the enabled (basic and reflexive) domains,
together with other domains. This abstract notion of security
XSM EV TCHN ALLOC UNBOUND ==
gets rather trickier at (high-performance) C code-level!
{xsm : DomID × DomID →  Bound |
MIN XSM ⊆ dom xsm
REFLEXIVE == (λ s : DomID • s)
∧ (∀ src : DomID • xsm(src, src) = xsm(src, 0) = 1)
BASIC == (λ s : DomID • 0)
∧ (∀ pair : dom xsm ∩ OTHER • xsm pair = 0)}
ENABLED == REFLEXIVE ∪ BASIC
OTHER == {s, t : DomID | s = t ∧ t = 0}
MIN XSM == ENABLED ∪ OTHER Now we can use the function space to axiomatically define
our XSM decision point for allocating an unbound event
Now we can define spaces of valid XSM security policy deci- channel as one of such functions, so long as it covers at least
sion functions, one space for each XSM security decision the minimal XSM domains of interest.
check, where such functions must cover at least the (rather
larger) minimum number of XSM domain pairs related. They
xsmEvtchnAllocUnbound :
are all those (boolean-)functions from a pair of domain to
XSM EV TCHN ALLOC UNBOUND
the configured security policy decision space, i.e., 0 or 1;
the requested operation is either not permitted or is per- MIN XSM ⊆ dom xsmEvtchnAllocUnbound
mitted. An alternative, even more set-theoretical version of
these functions could be constructed by having sets alone,
For these definitions we prove a theorem that such instances
instead of boolean-functions (xsmFcn (d0, d1) ∈ { 0, 1 }),
exists. For that it is enough to show that they are non-empty,
where set membership ((d0, d1) ∈ xsmFcn) could dic-
which is trivially true given the definitions.
tate whether the given pair of domains are allowed or not.
Although this would make proofs in Z easier (e.g., mostly
because one does not need to worry about function appli- 3.7.3 XSM check bind inter-domain event channel
cation within their allowed inputs), it would diverge too
much from the implementation that does use boolean-func- In this version of the interface specification, we do not
tions and hence we keep them here. To circumvent the extra model the full bind interdomain check because it is so com-
proving incurred by this, we need to add a collection of plex, i.e., the actual code-level function has a signature of
rewrite rules, which are quite simple easy, if laborious to DomID × PortNumber × DomID × PortNumber →  Bound.
prove. Temporarily, for the purposes of our explanation, we describe

123
L. Freitas, J. McDermott

it with the same check as the functionality for unbound compound Circus processes.
channels above.
channel hyp : AllLbl × HypercallOP × HCParamList
channel highhyp : HighLbl × HypercallOP × HCParamList
XSM EV TCHN BIND INTERDOM ==
channel ret : AllLbl × RC × HCParamList
XSM EV TCHN ALLOC UNBOUND
channel highret : HighLbl × RC × HCParamList
channelset HCInterface == {| hyp, ret |}
Similarly, now we can use the function space to axiomatically channelset HighHCInterface == {| highhyp, highret |}
define our XSM decision point for binding an inter-domain channelset HypervisorInterface ==
event channel. HCInterface ∪ cpuChanSet
channelset HighHypervisorInterface ==
HighHCInterface ∪ cpuChanSet
xsmEvtchnBindInterdomain :
XSM EV TCHN BIND INTERDOM
MIN XSM ⊆ dom xsmEvtchnBindInterdomain 3.9 Parameter schemas

Given our set of channels, we need to connect them to the rich


Again, we need a proof that such choices are significant encapsulated state of the Circus processes that drive them.
(e.g., these spaces are not empty). In the Xenon specification, we use schemas as parameter
sets for hypercalls in order to organise large specifications,
where parameters have certain expected restrictions and co-
3.8 Hypervisor channels relations (i.e., a precondition characterised by the parameter
schemas invariants). Parameter schemas are similar to the
The actual Circus channels that organise the events of the framing schemas of Z [32, Ch. 13], used to promote local
Xenon interface specification provide both synchronisation state. Instead of promoting specific operations to the global
and hypercalling. Synchronisation is provided by a spe- state, by schema conjunction, parameter schemas relate the
cial channel that marks the advancing computation of the global process-encapsulated state of a Z operation schema to
hypervisor. This scheduling channel is not part of the hy- the Circus channels of its enclosing Circus process. As in
pervisor implementation, which advances computation via the case of promotion, schema conjunction is used to connect
the hardware clocks of its CPU’s, but a construction that the parameter schemas to their processes.
allows us to make the interleaving of the hypervisor and its Hypercall parameters are “passed” in and out by the
guests visible. Hypercalling is modelled using the types we parameter “list” variables. The channel parameters schema
have just described above. The scheduling channel cpu will below describes the relationships between external Circus
be used to “control” or define when a guest is executing. action variables and the internal Z variables of the hypervisor
In the description of the guests, actions will be restricted state. Local and remote domain identifiers are passed in; the
to only have an effect when the value of cpu matches their port number is passed back and a result code is “returned”.
own domain ID. We define a channel set for the scheduling Values of param in and param out are set deterministically
channel to facilitate organising the synchronisation proto- by actions of the appropriate parameterised guest process
col of top-level compound Circus processes of our specifi- Guest (d) (see Sect. 3.16). The value of result code will be
cation: it characterises all communications through channel established deterministically by an internal hypercall oper-
cpu (e.g., cpu.dom0, . . . , cpu.n). ation schema of the Hypervisor process (see Sect. 3.10).
A concrete example from the Xenon specification is given
next to clarify this.
channel cpu : DomID
channelset cpuChanSet == {| cpu |}
paramsEvtchnAllocUnbound
lDomID?, rDomID? : DomID
There are two hypercalling channels, hyp to model “passing param in : evtchnAllocUnboundParamIN
in” opcodes and IN parameters and another, ret, to model p! : PortNumber; result code, rc! : RC
“returning” a status code and the OUT parameters. Both param out : evtchnAllocUnboundParamOUT
hyp and ret have corresponding “sub-channels” for High
lDomID? = param in 0 ∧ result code = rc!
as highhyp and highret. These channels are organised into
rDomID? = param in 1 ∧ param out 0 = p!
corresponding channel sets for construction of the top-level

123
Formal methods for security in the Xenon hypervisor

A guest wishing to allocate an unbound event channel passes ECS ::= ECS FREE | ECS RESERVED
in a local and a remote domain ID as param in, via channel | ECS UNBOUND | ECS INTERDOM
hyp, and the hypervisor returns the port number of the newly | ECS PIRQ | ECS VIRQ | ECS IPI
allocated event channel via channel ret, as param out. For the
internal operation, the parameter schema relates param in to Now we define the event channel (or virtual interrupt) state
the internal variables lDomID? and rDomID?. The parameter space. All kinds of event channels have some common state
schema establishes a similar relationship for the result code space: a unique identifier for event channels (evtchnID); the
and param out. port number of this event channel (portNumber); the event
channel (ECS) state; a couple of (boolean) flags about the
3.10 Hypervisor process channel being used to send events to the hypervisor or
not (consumerIsXen), and if the channel is supposed to
Once its channels are defined for external communication, notify a VCPU other than the first VCPU of a Xen domain
we can specify the state-rich internals of the hypervisor pro- (notifyVCPU); and two remote IDs used by the other end of
cess. In the process definition shown here, we depart from an attached channel for the port number (remotePort) remote
the order used in the specification. In the specification, the domain (rDomid).
part represented by the first ellipsis (…) is several pages of Z
specifications of the hypervisor internal state, as we will pres-
ent shortly. Near the end of the process definition, as organ- Evtchn
ised in the specification, we would find the Circus action evtchnID : EvtchnID; notifyVCPU : VCPUID
Run, as defined immediately below. Action Run synchronis- state : ECS; consumerIsXen : Bound
es on a cpu “tick” (e.g., a communication of channel cpu in remotePort : PortNumber
the process’ trace), then schedules another guest operating rDomid : DomID
system to perform one hypercall. Finally, the effects of the remotePort ≤ MAX EV TCHNS − 1
requested hypercall are given by the external choice action
with the second ellipsis. Next in our paper’s presentation we
see the main anonymous action (following the •), in this case Note that port numbers are not unique to the hypervisor,
(startXenon) ; Run. but unique to a given domain, where in the implementation
event channels are distinguished by domain and port number
process Hypervisor =  begin
pairs. In the specification, they are distinguished by unique
. . . Run =

evtchnID, which is to be refined into such pairs later. Some
cpu.currDom −→ ( Schedule ); hypercalls operate on more than one event channel at a time.
( doEvtChnAllocUnbound  To clarify the behaviour of these hypercalls, we provide a
doEvtChnBindInterdomain  shorthand for the local channel and a second schema, to play
. . . doNMIop ) • (startXenon) ; Run the role of the remote channel. For example, we have
end
The main action, characterising the process behaviour, initi- localEvtchn =  Evtchn[ localEvtchnID/evtchnID,
alises the state,13 then executes Run, which offers an exter- localState/state, localRemotePort/remotePort,
nal choice of the hypervisor’s interface to guest domains or localConsumerIsXen/consumerIsXen,
scheduling of VCPUs. All these actions in turn call back to localNotifyVCPUID/notifyVCPU,
Run recursively. localRemoteDomid/rDomid ]
Now that we have an overview of where we are going; we
return to the normal order of exposition as used in the specifi- We have a similar renamed schema for remoteEvtchn. We
cation. Following typical Circus practice, we define internal introduce the specific virtual CPU (VCPU) state space next.
state and internal actions14 for the hypervisor process. We Xenon uses its VCPU state space to virtualise CPUs for its
introduce the event channel state space first. Event channels guests. Currently, we do not model the entire VCPU state,
are managed on a per-domain basis, by including event chan- but only a subset necessary to represent event channel oper-
nels in the state space of Xen domains. We describe the states ations, as described in this paper. Like its parent Xen, Xenon
an event channel can be in as its event channel states (ECS). supports up to 32 virtual CPU’s per domain. The scheduling,
or run states of a VCPU are also explicitly given.
13Recall that schemas can be “casted” as actions. This is syntactically
marked by the fat-parenthesis around startXenon.
14 Circus actions are just like CSP processes, but local to the process MAX VIRT CPUS == 32
they are defined in. Runstate == 0 . . 3

123
L. Freitas, J. McDermott

There are four VCPU states as either: running, runnable (or EvtchnID forms a partition15 within all known domains, and
ready), blocked (or suspended), and offline. A specific VCPU this requires extra constraints per domain in the hypervisor.
contains the following state: the identifier of the VCPU To increase proof modularity and reuse, we separate each
(vcpuID); the (vcpuDomain) domain corresponding to this constituent part of a Domain using the Z schema calculus, and
VCPU; the run state of a VCPU (runstate); the polling status later prove the compartmentalised version to be equivalent to
as positive number indicating a single port is being polled, the complete expanded definition. This is important to make
zero indicating no polling, and a negative number indicat- proofs about event channel operations within a domain with
ing multiple ports might be polled; and a couple of sets of respect to the hypervisor global state (i.e., the specification
port number used by the hypervisor (evtchnUpcallPending) refactoring performed is tailored for proofs, yet represents the
or the guest (evtchnUpcallMask). The first set is used by the same artefact). Without such refactoring, proofs get consider-
hypervisor to tell the guest that a virtual event is pending. ably large (e.g., about 40 page-long formulae!) with too much
This occurs by placing the relevant port number in the set. A (unnecessary) details exposed. We expect such “specification
guest would “clear” the event by removing the port number pattern” (or refactoring) to be a post-facto device created by
from the set. Similarly, the evtchnUpcallMask set is used by a proof experts, rather than the programming-expert team mod-
guest to block or mask off virtual events for a particular event elling Xenon at first. That is, Xenon engineers are expected
channel: when the port number appears in the set, the hyper- to come up with something close to the DomainExpanded
visor (VCPU) will not perform any upcall to the domain for schema described below, and only when necessary (likely
that virtual event. because of unwieldy proofs), a theorem proving expert—or
indeed the engineer herself—would apply such refactoring.
VCPU Thus, the equivalence proof between each version is impor-
vcpuID : VCPUID; vcpuDomain : DomID tant to make sure expert attempts at easing the burden proof
isRunning : Bound; runstate : Runstate do not compromise the artefact being proved.
pollEvtchn : {−1, 0, 1} For ease of explanation we present this process the other
evtchnUpcallPending : P PortNumber way round by presenting the refactored Domain state at first.
evtchnUpcallMask : P PortNumber We start with the Domain state components, as described
above, but now with their types.

Some the state components are hidden; these include the DComponents
hardware CPU that this VCPU has “affinity” for, a struc- domID : DomID; pollMask : Unsigned
ture that records guest notification state for events, a set of isHVM, isPrivileged : Bound
corresponding Xen domain per VCPU (implemented in Xen evtchn : PortNumber  EvtchnID
and Xenon as a list), and so on. evtchnInfo : EvtchnID →  Evtchn
Next, we introduce the specific state of a Xenon domain portnoInfo : PortNumber →  Evtchn
(or a virtual machine or OS), again from the various mem- vcpu : VCPUID →   VCPU
bers of its underlying C implementation. A domain contains
the following: a unique domain identifier (domID); a couple The table of events (evtchn) is a total injective function ()
of tables for VCPUs (vcpu) and event channels (evtchn); a mapping all ports to specific EvtchnID, uniquely. The num-
couple of flags determining if the domain is privileged ber of event channels is fixed to the number of ports, since the
(isPrivileged) or if the domain is running as a “hardware evtchn map is a total injection from PortNumber. This ensures
virtualised machine” (HVM) for the guest (isHVM), which event channel IDs are unique per domain, yet port numbers
has consequences on what hypercalls and instructions are may be reused across domains. For ease of proof later, we add
allowed; and a pollMask used to record the VCPU’s that are a redundant component to the specification in order to extract
currently polling. Note that the privileged flag is not part Evtchn state information given a PortNumber (portnoInfo)
of the Xen Security Modules (XSM) state. As for VCPU, rather than EvtchnID as partial functions (→);
 this indirection
some components are hidden here, such as a record of the is present at the implementation using pointers to correspond-
number of pause operations that have been applied to this ing structures. Similarly, to keep event channel information
domain, and so on. Event channels are kept in domains, rather known to this domain we have evtchnInfo, which maps known
than VCPUs because events may be sent to more than one EvtchnIDs to their corresponding Evtchn state. This redun-
VCPU, and because event channel policies are enforced on dancy came up during proofs involving hypervisor domains
a per domain basis, and hence are part of the Domain state
invariant. On the other hand, domain ID uniqueness and other 15 A partition of a (finite) set of sets ensures that each element is pair-
scheduling features are system-wide and hence specified as wise disjoint with all other sets in the partition (e.g., no set has elements
part of the hypervisor global state, where the overall set of in common), and that their distributed union covers all elements.

123
Formal methods for security in the Xenon hypervisor

and event channel ports, since various event channel opera- DVCPUProperties
tions within domains depend on port numbers, which is what DComponents
the user knows, rather than EvtchnID that are internal to the
∀ vID : dom vcpu • (vcpu vID).vcpuID = vID
hypervisor. We are currently working on a model for point-
∧ (vcpu vID).vcpuDomain = domID
ers that would characterise this indirection more precisely.
This is a nice example where taking up a proof exercise of
this scale promote general solutions for other problems. The
table of VCPUs is specified as a finite partial function (→).
 For all VCPUs, this links each VCPU to its domain of
All maps are finite in the implementation, yet we keep use and hence establish consistency between VCPU and
these explicit at the specification only when necessary dur- Domain ids. Moreover, the invariant enforces uniqueness of
ing proof. Otherwise, one could get unnecessarily more com- VCPUIDs across domains (e.g., VCPU state is injective on
plicated proof obligations. In this sense, the specification is their VCPUID field only) and allows us to prove the fol-
weaker than the implementation and hence easier to achieve. lowing consistency lemma as a rewrite rule: assuming these
If during the modelling we need to use finiteness proper- domain properties for VCPUs, all VCPU states with the same
ties, it would require a stronger specification where the prop- VCPUID are identical.
erty is would then be necessarily explicit, like in the case Theorem disabled rule lDomainVCPUConsistency
of VCPUs. With the state components, the basic properties ∀ DVCPUProperties • ∀ i, j : dom vcpu •
about domains are given next. They include trivial restrictions i = j ⇒ vcpu i = vcpu j
over DomID, and the number of VCPUs a domain can map.
We need a similar property mapping for Evtchn state
within domains and their internal Evtchn.evtchnID. A set of
DBasic similar rewrite rules as above is also proved. They are crucial
DComponents in order to perform proofs about event channels and VCPU
domID = DOMID SELF information for domain operations in the hypervisor. More-
dom vcpu ⊆ 0 . . MAX VIRT CPUS over, the VCPUs that require notification (e.g., notifyVCPU)
by that event must be known within the VCPUs of a domain.
and similarly for the Evtchn.remotePort of an event within
The hypervisor never assigns the DOMID SELF value to a
the evtchnInfo map. That is, we need to define the healthy
domain identifier. The special value DOMID SELF is used
relationship between the notifyVCPU member of an event
by hypercallers (i.e., guest OS outside the hypervisor) when
channel and the VCPUs of the general state. The notify
they want a hypercall to apply to themselves and they do
VCPU field of an event channel must be from the domain
not know their own internal identifier. An example for event
VCPU set (dom vcpu), so that event channels are part of
channels would be a hypercall to make an event channel
some “containing” domain. Similarly, we establish consis-
loop back to the same domain, as an interdomain connec-
tency for all remote event channels that maybe connected
tion. The number of virtual CPU’s is bounded and hence
within a domain, with respect to the event channel state
the need for it to be finite. We avoided using set cardinal-
(evtchn). Finally, we specify the definition of Evtchn infor-
ity as in # vcpu = MAX VIRC CPUS because this leads
mation given a port number, rather than an event chan-
to much more complicated (inductive) proof obligations, yet
nel id. That is possible because evtchn is injective and
represents (a weaker version of) the invariant needed that
total.
vcpu is bounded. When performing some proofs later, we
make the bound smaller, say to two VCPUs rather than
MAX VIRT CPUS (or 32) per domain as in the implemen- DEvtchnProperties
DComponents
tation, so that existential-quantifier witnesses are simpler for
the vcpu table, like vcpu = {3 → vcpuX, 7 → vcpuY }. Every port association has event channel information

We need to enforce VCPU state properties regarding dom evtchnInfo = ran evtchn
mutually agreeable identifiers, given included domain com- Evtchn ids, notifyVCPU, and remotePort consistency
ponents. That is, all VCPU ids mapped in a Domain must ∀ eID : dom evtchnInfo •
have the same internal VCPU.vcpuID; and all domain id (evtchnInfo eID).evtchnID = eID
of a VCPU must match the current domain id. That means ∧ (evtchnInfo eID).notifyVCPU ∈ dom vcpu
VCPUs are unique per domain and that dom vcpu collects ∧ (evtchnInfo eID).remotePort ∈ dom evtchn
all VCPU ids under consideration. Also, all mapped VCPUs Evtchn state access via a port

“know” which domain they are coming from via the consis- portnoInfo = (evtchnInfo ◦ evtchn)
tent VCPU.vcpuDomain as the current domID.

123
L. Freitas, J. McDermott

The complete state is given as the conjunction of these def- We prove the initialisation theorem for Domain that estab-
initions. We add DComponents explicitly to the definition lished that its invariant has a model: it is feasible and not
in order to facilitate type-correctness proofs about the state over-constraining. We prove such theorem for all schemas
components. That is, we do not need to expand it in order to representing state parts. For Domain, the proof requires a
access type-related information. witness for each component, such that all the invariants
hold at the initialised state. The complete proof is not very
Domain =
 (DComponents ∧ DBasic ∧ interesting, yet quite long because of the various layers of
DVCPUProperties ∧ DEvtchnProperties) structuring involved (e.g., Evtchn, VCPU, Domain, etc.). The
point, or warning, is that at some stage there is the need to
As mentioned, these and other specification patterns are re-structure the specification in order to tailor it for proof.
very important for ease of proof, yet not so important for That was when we refactored the expanded Domain. Nev-
capturing the Xenon design intent. We actually produce ertheless, such refactoring must preserve the original inten-
this specification in two stages: first, one given by Xenon tions, unless a problem is discovered in the process. Thus,
specification-oriented programmers, and a second (mostly equivalence theorems between these state schemas are also
equivalent) version by a formal modelling expert. Other con- proved everywhere. This is not specific to this case study.
straints over port number and VCPUID across domains are
enforced by the hypervisor global state. To ensure the modu-
larised, easier-to-do-proof-with version is right, we prove it 3.11 Scheduler state space
equivalent to the following expanded version. Some hyper-
calls operate on more than one domain at a time. To clarify We provide an abstract rudimentary, but not fully functional
the behaviour of these hypercalls, we provide an alias for the scheduler. This scheduler is just “scaffolding” for proofs
local and remote domain by renaming components accord- involving security, our major concern. It serves to define a
ingly, similarly to what we have used in localEvtchn. We plausible set of traces that can be used to prove the security
introduce the domain identifier for the privileged dom0 that of the defined hypercalls. It does not allow domains to be
acts as a control plane for the hypervisor. We also introduce removed or even paused. In a future version of this specifica-
two unprivileged domains domU1 and domU2, for use as tion, a faithful model of the real scheduler will be constructed.
witnesses in the proofs of security. The scheduler provides strict round-robin execution, because
it is covert channel free [1]. A covert channel is anything that
is being misused to flow information the wrong way. The
dom0 == 0 domU1 == 1 domU2 == 2
canonical example is to use a file lock. Malicious software
in a High domain that wishes to leak High information to a
The hypervisor scheduler state takes care of uniquely queued Low domain, will lock a shared file that Low can also access.
VCPUIDs, as well as the current VCPU and corresponding Each time Low tries to access the shared file but is refused
Domain. We omit them here. because of the lock there is the transmission of one bit of
information. No bits of Low’s state space are modified, but
DomainExpanded the lock refusal is visible to Low and thus leaks one bit.
domID : DomID; pollMask : Unsigned Covert channels can be used to leak sensitive information in
isHVM, isPrivileged : Bound otherwise strongly protected systems. Covert channels typ-
evtchn : PortNumber  EvtchnID ically leave no audit trail, hence can be used undetected, to
evtchnInfo : EvtchnID →  Evtchn leak large amounts of information over an extended period
portnoInfo : PortNumber →  Evtchn of time. Practical covert channels in a hypervisor can flow
vcpu : VCPUID →   VCPU information at rates comparable to a USB connection. We
want to build a formal model to avoid exactly these kind of
domID = DOMID SELF
covert channel attacks.
dom vcpu ⊆ 0 . . MAX VIRT CPUS
Scheduling is by VCPU as well as by domain, one rea-
∀ vID : dom vcpu • (vcpu vID).vcpuID = vID
son a VCPU has to “know” its domain. In our specifi-
∧ (vcpu vID).vcpuDomain = domID
cation, scheduling is by VCPU only, but there is still a
dom evtchnInfo = ran evtchn
need to refer to the domain of the current VCPU, in order
∀ eID : dom evtchnInfo •
to make sure the scheduler is not deadlocked or inconsis-
(evtchnInfo eID).evtchnID = eID
tent. A practical example of this in the implementation is
∧ (evtchnInfo eID).notifyVCPU ∈ dom vcpu
a virtual or real interprocessor interrupt within the same
∧ (evtchnInfo eID).remotePort ∈ dom evtchn
domain.(e.g., there is always something scheduled). We omit
portnoInfo = (evtchnInfo ◦ evtchn)
other parts here.

123
Formal methods for security in the Xenon hypervisor

MINvcpuPerDom : N HypScheduler
HypComps
Scheduler
schedule : iseq VCPUID currVCPU ∈ dom vcpus
currVCPU : VCPUID; currDom : DomID ∀ v : ran schedule • v ∈ dom vcpus
MINvcpuPerDom ≤ # schedule ≤ MAXvcpuID
currVCPU ∈ ran schedule Given domain uniqueness, all VCPU-state known to the
hypervisor can be collected as the set of VCPU mappings
within the known domains in the hypervisor state dmns func-
The invariant bounds the amount of VCPUs by given con- tion, that is the value of (dmns dID).vcpu. The identifiers of
stants, and say that the VCPU currently running must be CPU in a domain vcpu table must match the identifier used
scheduled. As an injective sequence (iseq), there can be no to look them up from a domain operation: VCPUs within a
repeated VCPUIDs for scheduling. domain must agree that this is indeed the domain which owns
the VCPU. That is, vcpu returns a function from VCPUIDs
3.12 Hypervisor state space to VCPU states for every known DomID in the hypervisor.
On this set of functions we apply distributed union in order
Given the specific state space components of event chan- to flatten them into a single relation, which we later proved to
nels, VCPUs, and domains, we can now define the global be injective (e.g., vcpus belong to VCPUID   VCPU). What
state for the hypervisor process. It adds constraints that makes vcpus a function is that all the VCPUIDs within each
relate the hypervisor state to its specific components. Like dom (dmns dID).vcpu are disjoint,16 as enforced by schema
with Domain, we modularise the global state as well. First, DVCPUProperties as part of Domain above.
we have the components as the Scheduler plus the various
mapping functions collecting information per domain. Func- HypCollectedVCPUS
tion dmns lays out the promotion for future operations over HypDomainUniqueness
domains: that is, from a given ID, the corresponding Domain 
vcpus = { m : dom dmns • (dmns m).vcpu }
modification is framed back into the global state.
disjoint (λ i : dom dmns • dom ((dmns i).vcpu) )

HypComps
Scheduler; dmns : DomID → Domain This ensures no sharing of VCPUIDs across domains can
vcpus : VCPUID ↔ VCPU happen; hence the hypervisor state vcpus is indeed a func-
evtChns : EvtchnID ↔ Evtchn tion. Similarly, we have the same property projecting out all
event channel information within dmns. Moreover, all event
channel remote domain ids must be known globally within
Next, we have two relations (i.e., ↔ as sets of pairs) collect- dmns. Otherwise, we would have virtual interrupt requests
ing all VCPUs and Evtchn per each domain known—these are from domain ids unknown to the hypervisor.
projections over domains. Later, we prove that they are injec-
tive functions and give add them as rewrite rules. We leave HypCollectedEvtchns
them here as relations in order to avoid complex proofs about HypDomainUniqueness
injective function later when domain updates take place. This 
is possible because, unlike with Domain.evtchn, which is evtChns = { n : dom dmns •
declared as injective, we do not have explicit need to use (dmns n).evtchnInfo }
that fact in the hypervisor’s invariant. Like for VCPU within disjoint (λ j : dom dmns •
Domain, we have that globally Domain.domIDs are unique. dom ((dmns j).evtchnInfo) )
∀ eEvtchn : ran evtChns •
HypDomainUniqueness eEvtchn.rDomid ∈ dom dmns
HypComps
∀ dID : dom dmns • (dmns dID).domID = dID As before for Domain, the complete HypState is the conjunc-
tion of all its parts, where we again explicitly add HypComps

Also, the scheduled VCPUs must be known within the col- 16The predicate involving disjoint says each set of VCPUID from the
lected VCPUs per domain. This includes all mapped vcpus, Domain’s vcpu table domain (dom ((dmns i).vcpu)), for every known
as well as the currently scheduled VCPU. domain id in dmns are pairwise-disjoint, hence share not elements.

123
L. Freitas, J. McDermott

in order to make proofs about the global state component It says, given the global state and any known Domain state
types easier. d from dmns, it is indeed mapped through its domID in the
known hypervisor domain states. With these lemmas at hand,
HypState =
 (HypComps ∧ HypScheduler we can start modelling the operations, both for domains and
∧ HypDomainUniqueness ∧ HypCollectedVCPUS the hypervisor globally. These proofs are crucial as they
∧ HypCollectedEvtchns) establish all the necessary features we need Xenon to have
when collecting available VCPUs and Evtchn in Domains,
The expanded state is given next, which is proved equivalent such that all required constraints are observed. Before show-
to the modular version. ing an example hypercall operation, we first need to set up the
promotion schemas. They will promote local state updates to
their global correspondent. For instance, VCPU and Evtchn
HypStateExpanded
updates get promoted within the Domain state they belong to.
schedule : iseq VCPUID; currVCPU : VCPUID
That domain update then gets promoted into the hypervisor
currDom : DomID; dmns : DomID →  Domain
global state as well. And similarly for local and remote event
vcpus : VCPUID ↔ VCPU
channels. Some of it is presented next.
evtChns : EvtchnID ↔ Evtchn
currVCPU ∈ dom vcpus 3.13 Promoting event channels
∀ v : ran schedule • v ∈ dom vcpus
∀ dID : dom dmns • The hypervisor state does not have local (or remote) event
(dmns dID).domID = dID channels; they come from each of the hypervisor’s domains.

vcpus = { m : dom dmns • (dmns m).vcpu } So, to promote event channel operations within the hyper-
disjoint (λ i: dom dmns • dom ((dmns i).vcpu) ) visor state, we must first describe how they are promoted
evtChns = { n : dom dmns • at the level of domains with the next schema. It includes
(dmns n).evtchnInfo } before and after states for both domain and event channel.
disjoint (λ j : dom dmns • Note this enforces the intricate invariant for event channels
dom ((dmns j).evtchnInfo) ) mapped within domains, like remotePort and notifyVCPU,
∀ eEvtchn : ran evtChns • within event channel state as related to other Domain compo-
eEvtchn.rDomid ∈ dom dmns nents. We also have two inputs for local and remote domain
ids, and two outputs for port number and operation return
code. These are pretty much like in the hypercall implemen-
Besides proving equivalence between the two versions of the tation. For the visible components involved, we use a com-
global state, we also prove a feasibility (or initialisation) the- mon Z pattern that says all after state elements of Domain
orem for the hypervisor. This theorem is important because remain constant (ΞDomain), except evtchn and evtchnInfo,
it ensures that, even though the global state imposes a series which may change as a result of the operation.
of restrictions over Domain, which imposes a series of fur-
ther restrictions over VCPU and Evtchn states, the HypState  ΞDomain \ (evtchn, evtchnInfo)
EvtchnDomProm =
invariant is feasible. We can find a existence-witness; hence
our set of constraints is permitting some (if many) imple-
mentations. EvtchnPromotedInDomain
Now we have the complete global state invariant, we con- ΔDomain; ΔEvtchn; EvtchnDomProm; rc! : RC
centrate in proving various properties of interest it satisfies. lDomID?, rDomID? : DomID; p! : PortNumber
They include containment of domain information within the
hypervisor, like VCPUs and Evtchn. These lemmas are some- p! ∈ dom evtchn
what easy to prove, since the hypervisor state is constructed evtchn (p!) = evtchnID = evtchnID
by collecting them together. More interesting are the proofs evtchnInfo (evtchnID) = θ Evtchn
within the hypervisor state that dmns, vcpus, and evtChns evtchn = evtchn ⊕ { p! → evtchnID }
are injective on the known DomIDs. We have that within evtchnInfo = evtchnInfo ⊕ { evtchnID → θ Evtchn  }
Domain, vcpu and evtchnInfo are also injective. The impor- (lDomID?, rDomID?) ∈ dom xsmEvtchnAllocUnbound
tant aspect of these injectivity proofs is that they enable con-
sistency proofs about the hypervisor state like:
The port number p! returned by the event channel opera-
Theorem lHypStateDomIDEquiv tions must be known within the table of event channel ids per
∀ HypState • ∀ d : ran dmns • dmns (d.domID) = d port (evtchn) in a domain. This also means that the EvtchnID

123
Formal methods for security in the Xenon hypervisor

this port is mapped to (i.e., evtchn p!) has Evtchn information scheduled only, since this is the domain id (rDomID!) han-
associated with it via the mapping from ids to event channel dling the event channel hypercall. This value is output as
state (evtchnInfo (evtchnID)). For the event channel states, the domain id of the current VCPU (currVCPU) sched-
we fix their ids to the id mapped within Domain(evtchn p! = uled in the hypervisor. It is used as input to other pro-
evtchnID), and their values to what is in evtchnInfo of moted schemas defining what to do with the hypervisor’s
Domain, i.e., (evtchnInfo (evtchnID) = θ Evtchn). In Z, selected domain rDomID!. The global state invariant guar-
θ-expressions are like self or this in the object-oriented antees that the domain id for the currently scheduled VCPU
programming: it references the actual instance of the before is known and comes from dmns. Also, when combined with
or after state at a particular point—it refers to the current EvtchnPromotedInDomain, there could be a relation between
schema binding, or actual values within the labelled record. the input domain ids and the domain id rDomID! handling
The promotion of the event channel operation port number the hypercall request. Following the same pattern, we con-
returned (p!), as well as the updated event channel (after-) struct layered promotion schemas for VCPU updates within
state (θ Evtchn  ) into Domain, are performed by updating Domain and its corresponding update within HypState, as
each domain mapping accordingly using relational overrid- well as specialisation of event channel promotion for local
ing (⊕). That is, evtchn p! = evtchnID ; hence no update in and remote hypercall requests. These are similar and omitted
event channel id happens through this promotion schema, here.
whereas event channel information does change to whatever
values θ Evtchn  has, given some event channel state oper- 3.14 Example hypercall operation schema
ation using this promotion (i.e., event channel operations
cannot change event ids). The domain id input parameters Like in Xen, the Xenon hypervisor has over 200 hypercalls in
(lDomID?, rDomID?) enforce the security policy for what its interface. These hypercalls are used to control domains,
local and remote domains can do with event channel hyper- manage the MMU, virtualise interrupts, manage VCPU’s,
calls. This mapping is kept at the xsmEvtchnAllocUnbound manage the grant table inter-domain communication mech-
function defined earlier (see Sect. 3.7.1). The XSM policy anism, and other hypervisor features. Here, we provide an
permits the hypercall to allocate an unbound channel des- example of one hypercall that is used to manage event chan-
tined for dom0, or the request is for a loopback channel on nels. The event channel state update gets promoted into the
DOMID SELF. A request for an unprivileged domain to allo- domain state, which in turn gets promoted to the hypervisor
cate an unbound channel destined for another unprivileged state, thus giving a complete characterisation of its effect of
domain is denied. That is, event channel connections between event channel operations on the hypervisor’s behaviour.
unprivileged domains (e.g., domU1, domU2, etc.) are set up Event channels “virtualise” the functions provided by
by the trusted guest domain running in dom0. hardware interrupts, for virtual CPU’s. For example, instead
The next aspect of the promotion is to bring this event of an interrupt notifying a hardware CPU that a device has
channel state update from Domain into to the hypervisor data ready, Xenon uses events to notify selected VCPU’s in
global state. It is defined with the next schema containing a domain. Technically, event channels are an asynchronous
a copy of the corresponding before and after states for the communication mechanism for notifications from Xenon to
hypervisor and domain, where only dmns and evtChns may its guests or from one guest to another. Event channels are
change in the hypervisor. similar to Unix signals, but it is also possible to poll for
events that were delivered while event notification was dis-
 ΞHypState \ (dmns, evtChns)
EvtDomHypProm = abled. Events delivered by event channels can correspond to
physical interrupts (PIRQ events), virtual interrupts (VIRQ
events), or events sent between domains. Domain events can
EvtchnPromotedInHypervisor be interdomain, such as events communicated by paravirtu-
ΔHypState; ΔDomain; EvtDomHypProm alised devices, or intradomain, such as events used as virtual
rDomID! : DomID inter-processor interrupts on a multicore CPU.
rDomID! ∈ dom dmns ∧ Event channels are indexed by a port number. Each chan-
rDomID! = (vcpus (currVCPU)).vcpuDomain ∧ nel has two bits of state: PENDING and MASK. When the
dmns (rDomID!) = θ Domain ∧ hypervisor sets PENDING, the Xen domain is notified of
dmns = dmns ⊕ { rDomID! → θ Domain } a pending event. A guest in the Xen domain may clear
PENDING. The MASK bit is only changed by the guest oper-
ating system. If MASK is clear when the hypervisor sets
PENDING from a cleared state, an up call to the guest
The invariant clarifies that any operation using this pro- will be scheduled. The Xenon hypervisor interface provides
motion schema will be for the domain id of the current VCPU a hypercall named do_event_channel_op with 11

123
L. Freitas, J. McDermott

sub-commands; so there are really 11 event channel hyper- to send events to itself. To do this, Xenon uses the current
calls. For our example, we show the specification of one VCPU state (vcpuDomain) to find the actual domain ID of
of these sub-commands: evtchn_alloc_unbound. This the hypercalling domain. Next, is the Xen Security Modules
hypercall sub-command allocates an event channel bound to (XSM) check. The XSM security check is a security pol-
the requester, with the remote-port free for later binding. icy decision about allowing a connection from local domain
This form of the do event channel op hypercall is lDomID? to remote domain rDomID? If the value of function
made by passing a pointer to a struct that gives the requesting xsmEvtchnAllocUnbound is 1, then the operation is permit-
domain, the remote domain, and space for the port number of ted. Finally, we have the output return code for successful
the allocated event channel. The typical use case for this hy- execution and the update on the event channel state compo-
percall is for the privileged guest domain in dom0, to use the nent. Note that during promotion, the right port number (p!)
sub-command to set up an event channel from dom0 to one will get assigned to this state change by finding one within
of the unprivileged domains. This unbound channel is later the evtchn mapping of port numbers. All other event channel
bound to the unprivileged domain, again via domain dom0. local state is unchanged.
As usual with Z, operations are defined by splitting (dis- Next we define one of various possible hypercall error
joining) successful with error cases. In normal processing, cases. If the XSM security policy check fails, then the hyper-
this hypercall results in the requesting domain having its call has no effect on the event channel state; hence any effect
first available event channel port set to the unbound event through the promotion schemas will lead to a unchanged
channel state. The available free ports are updated to show θ Evtchn  because of the ΞEvtchn used.
that the allocated port number is no longer available, and we
model it with the next schema, given the event channel state EvtchnAllocUnboundXSMNo
change within the domain it belongs to. This domain will be ΞEvtchn; lDomID?, rDomID? : DomID; rc! : RC
bound to the before state of Domain in the promotion schema
(lDomID?, rDomID?) ∈ dom xsmEvtchnAllocUnbound
EvtchnPromotedInDomain above.
xsmEvtchnAllocUnbound (lDomID?, rDomID?) = 0
rc! = xsmAccessDenied
 ΞEvtchn \ (state, rDomid)
EvtchnAllocSuccCmp =

There are other error cases. For instance, attempting to allo-


EvtchnAllocUnboundSuccess cate an unbound event channel when we cannot get a free port
Domain; ΔEvtchn; EvtchnAllocSuccCmp will cause an error. That is, there is no port with a ECS FREE
rc! : RC; lDomID?, rDomID? : DomID state in the domain’s evtchn “table”. The error report is passed
back to the hyper-caller as rc! = enospc.
((rDomID? = DOMID SELF ∧ rDomid  = domID) ∨
(rDomID? = DOMID SELF ∧ rDomid  = rDomID?))
EvtchnAllocUnboundGetPortNoPort
(lDomID?, rDomID?) ∈ dom xsmEvtchnAllocUnbound Domain; ΞEvtchn; rc! : RC
xsmEvtchnAllocUnbound (lDomID?, rDomID?) = 1
rc! = enospc
state = ECS FREE ∧ state = ECS UNBOUND ¬ (∃ freePort : PortNumber •
rc! = rcok (∃ e : localEvtchn • freePort ∈ dom evtchn
∧ e.localEvtchnID = evtchn freePort
∧ ( e.localState = ECS FREE )))
This schema models the choice between a domain’s request
to loop an event channel back to itself, or to start a connection
to another domain. Domain identifier lDomID? is the id of the All error cases are assembled with disjunction as
local domain requesting the creation of the unbound channel,
where no restrictions are placed on which domain may play EvtchnAllocUnboundFailure =

the role of local domain. The hypervisor always performs EvtchnAllocUnboundXSMNo ∨
the requested operation on behalf of the requested (remote) EvtchnAllocUnboundGetPortNoPort
domain. Domain identifier rDomID? is also an input vari-
able, but again, its relation to the general state is through the where the complete operation before promotion includes the
event channel “table” (function evtchn). If the input remote successful case with the error ones.
domain ID is not the special value indicating “self”, then
the request is not for a loopback and the unbound connec- EvtchnAllocUnbound =
tion is set up for the remote domain requested (rDomID?). EvtchnAllocUnboundSuccess ∨
The alternative is a loopback channel, i.e., the guest needs EvtchnAllocUnboundFailure

123
Formal methods for security in the Xenon hypervisor

This is the operation we promote into the domain and global hypervisor process state, which is marked with the state key-
hypervisor state next. It existentially quantifies the before word.
and after states of both domain and event channels, which
get captured by their declarations in the schemas involved. It
also includes the domain id (rDomID!) of the currently run- state (HypState ∧ paramsEvtchnAllocUnbound . . .)
ning VCPU in the hypervisor, which gets used as the input
domain for the the promotion of Evtchn into Domain, and
With the process state defined we can proceed to the Circus
the promotion of Domain into HypState. In that way, all pos-
actions that model the event channel hypercalls behaviour.
sible domain and event channel states that satisfy the overall
For this paper, we only provide an example action cor-
invariant characterise the global (promoted) operation.
responding to the event channel hypercall for operation
schemas presented above. Usually, the CSP within Circus
HypEvtchnAllocUnbound = 
processes provide beside the (concurrent) trace behaviour
(∃ ΔDomain; ΔEvtchn; rDomID! : DomID •
of the system and also a controller for the possible state
EvtchnAllocUnbound[rDomID!/rDomID?] ∧
update behaviour. The next step is to have a state initiali-
EvtchnPromotedInDomain[rDomID!/rDomID?]
sation schema that would satisfy the overall process state
∧ EvtchnPromotedInHypervisor)
invariant, which is feasible as we have its existence proof.
Yet, it is also possible to leave state initialisation (i.e., or in
This completes our example of how we describe the state
practice, hypervisor loading) under or weakly specified, thus
effects of key parts of single specific hypercall sub-command.
allowing the most varied possible implementations.
This specification can look deceptively simple. If one
The allocate unbound event channel hypercall action gets
expands all definitions and invariants, both of operations and
an operation code and an input parameter list from its envi-
underlying state, the schema is rather large. That necessi-
ronment. Then it allocates new unbound channel state as
tates a lot of house keeping theorems and rewrite rules about
defined by the evtchnAllocUnbound Z operation schema.
individual schemas, which is part of our model as well, yet
Finally, the action returns a result status report as variable
not as interesting to add to this explanation. The full spec-
result code (understanding that success, rcok, is one pos-
ification would have over 200 of these operation schemas,
sible result), and an output parameter list. Notice that the
and we have completed this refactoring and housekeeping
returned value has a proof label, indicating whether the action
of some of them. Another important aspect regarding proof
is High or Low. In the end, after the necessary traces and
would be to try and have free promotions [32, p. 196] when-
state updates, the action recurses back to the Run action
ever possible, as these make proofs much easier: in a free
defined above (see Sect. 3.10, and again below). This is
promotion one can prove individual schemas and the proof
important in the notion of security through non-interfer-
of their combination above is “for free” because there are no
ence extended for Circus. The parameters not related to the
inter-state dependencies. This is not the case for this example,
schema inputs/outputs are kept by other actions and state
unfortunately.
operations not presented here.
3.15 Hypervisor event channel actions
doEvtChnAllocUnbound = 
We are now ready to complete the definition of the hyper- hyp?proof label.doEvtchnAllocUnbound.param in−→
visor process. The key advantage of the Circus formalism ((evtchnAllocUnbound );
is its natural way of combining descriptions of internal state (ret!proof label.result code.param out −→ Run))
behaviour with externally visible (concurrent) trace behav-
iour. The trace behaviour of each hypercall will be defined
as an action of the Hypervisor process that will ultimately At this point in the specification, we would define the rest of
update the hypervisor state. The hypervisor state defines the hypercall actions. Instead, we proceed to the point where
the variables and schemas used by the process actions. It we define the main action that drives our hypervisor process.
also defines the parameter schemas that relate the exter- Run defines the principal structure of the hypervisor pro-
nal Circus action parameters to the Z parameters of the cess. It first schedules a domain and then waits for and per-
internal hypervisor state. The hypervisor state is defined by forms a hypercall request of, the current domain. The event
the HypState schema above (see Sect. 3.12), together with cpu.currDom has the effect of “running” the current guest,
(by conjunction of) any extra parameterisation schemas, like as the corresponding guest process actions (see Sect. 3.16)
paramsEvtchnAllocUnbound above (see Sect. 3.9). Techni- always start with a synchronisation on their own domain
cally, these could be process parameters, but since we have ID. As explained near the beginning of our description of
extra invariants over them, we add them as part of the state the hypervisor process, the external choice action selects the

123
L. Freitas, J. McDermott

appropriate hypercall necessary state changes. A well-behaved guest always requests itself as the local
domain. Notice that the hypercall uses currVCPU to decide
Run =
 which domain applies. The remote domain counter
cpu.currDom −→ ( Schedule ); (rDomIDcounter) is used to request the next remote domain.
( doEvtChnAllocUnbound 
doEvtChnBindInterdomain  DomUallocUnboundChooseParams
doNMIop ) ΔEvtchnAllocUnboundGuestState
vcpuDomain? : DomID
We complete the process definition with its main action that param in 0 = vcpuDomain?
initialises the hypervisor state and then Run’s. param in 1 = rDomIDcounter
rDomIDcounter < MAXdomID ⇒
• (startXenon) ; Run rDomIDcounter  = rDomIDcounter + 1
rDomIDcounter = MAXdomID ⇒
rDomIDcounter  = 0
end

3.16 Guests We need the corresponding guest action for each hypercall.
For our running example, we present the allocate unbound
We need a collection of Circus processes to model both event channel action of the guest
dom0 “control plane” (privileged) guest, and the untrusted
domUn (unprivileged) guests that perform computation for hypercallEvtchnAllocUnbound =
the end users. cpu?d −→ ((DomUallocUnboundChooseParams);
We need an untrusted guest process that is parameterised (hyp!Low.doEvtchnAllocUnbound.param in−→
on its domain ID. This simplifies any additions to the number ret?Low.result code.param out −→ Run))
of untrusted guests.
Each untrusted guest cycles through all possible requests that
 d : DomID • begin
process Guest = it can make for itself in a similar guest GRun action.

The guest will need a corresponding state changing operation GRun = hypercallEvtchnAllocUnbound
schema and matching hypercall action trace to synchronise  hypercallEvtchnBindInterdomain  . . .
with the Hypervisor process. We provide a single example • (InitEvtchnAllocUnboundGuestState) ; GRun
of state for the allocate unbound event channel hypercall.
We use simple counters to have our guests cycle through all
possible domain and port values. end

EvtchnAllocUnboundGuestState The untrusted guests do not directly share events and


param in : evtchnAllocUnboundParamIN
param out : evtchnAllocUnboundParamOUT

hence the use of interleave ( ) over all possible domain
ids. This replicated process synchronises with the hypervi-
lDomIDcounter, rDomIDcounter : DomID sor process.
localPortCnt, remotePortCnt : PortNumber
result code : RC
process Guests =
  d : DomID • Guest (d)
The parameter lists and counters must be initialised. We also We model the collection of guests as an interleaving of
initialise the result code. parameterised guest processes by their domain id.

InitEvtchnAllocUnboundGuestState 3.17 Combined Xenon system


EvtchnAllocUnboundGuestState 
param in 0 = param in 1 = 0 The interleaved guests now communicate as allowed by the
lDomIDcounter  = rDomIDcounter  = 0 Hypervisor process.
localPortCnt  = remotePortCnt  = 0
process Xenon =

result code = rcok
Guests  HypervisorInterface  Hypervisor

123
Formal methods for security in the Xenon hypervisor

Events shared on the cpuChanSet channel set (part of abstraction: it is the parallel composition of the hypervisor
HypervisorInterface) have the effect of limiting guests to and guest OSs with the known event channels allowed to
only executing when a real CPU is allocated to them. behave chaotically in the non-interference setting of Eq. 1.
3.18 Balagan adversary
process LazyAbstraction =

(Xenon  HighHypervisorInterface  evtchnBalagan)
For the chaotic adversary, we have the process
\HighHypervisorInterface
process evtchnBalagan =
 begin
If we can show that this LazyAbstraction is deterministic,
We need a schema as the process state to provide parameter then our Xenon process is information-flow secure. We are
passing variables. working on this proof at the moment.
If LazyAbstraction is deterministic then the design of our
evtchnBalaganState hypercall interface cannot be exploited by a guest operat-
au param in : evtchnAllocUnboundParamIN ing system in one untrusted domain to crash, lockup, or
au param out : evtchnAllocUnboundParamOUT gain administrative control over another guest operating sys-
result code : RC tem in another domain, via shared host execution. Any of
these (compound) events could happen in the second (target)
guest, but not as a result of shared execution with the source
We make the schema as part of the process’ state. (attacking) untrusted guest. They would have to happen as
a result of failure within the target guest OS, as a result of
state evtchnBalaganState inputs to that guest from outside the hypervisor platform. If
LazyAbstraction is deterministic then the design described
The intent here is that the traces of process evtchnBalagan by our Circus specification will also prevent direct copies of
range over all possible sequences of input and output param- information from one domain to another, via shared host exe-
eters over each event channel hypercalls. Here we only cution and also indirect leaks due to exploitation of hypercall
show the one associated with allocate unbound. Notice that features. Either of these attacks, from an untrusted domain,
evtchnBalagan will not “run” unless the Hypervisor process would have to cause some kind of nondeterministic event
is prepared to engage in the event cpu.domBalagan. Also, it within the target Circus process.
might simply deadlock and refuse to communicate anything,
nondeterministically.
5 Evaluation summary
• µ X • cpu.domBalagan−→
(Stop As already mentioned, the whole model is over 4500 pages
hyp.High.doEvtchnAllocUnbound.au param in−→ of Circus, and this comes from the model extraction from the
(ret.High.result code.au param out −→ X)) code’s intent as also described earlier. This larger model has
been typechecked and verification conditions for parts of it
end had been generated. CZT, and Z/Eves, have a simple verifica-
tion condition generator for Z, which currently extending for
This completes our running example of the Xenon inter- Circus. Verification conditions are related to the specification
face specification for some event channel related hyper- in terms of its: (i) well-formedness or domain checks that
calls. functions are applied within their domains and ∃1 -predicates
This industrial example clearly shows the advantages of are satisfiable; and (ii) feasibility, or precondition calculation
Circus for describing software systems that have both com- for all operations as well as invariant satisfiability proof for all
plex state behaviour and complex (concurrent) trace behav- state (without after variables) schemas. It will include gener-
iour. The current specification does not model all of the ation of refinement proofs of adequacy in the near future. We
Xenon hypercalls, but it specifies more than we have been also include a series of housekeeping lemmas, which are tai-
able to show in this exposition. lored to make proof smooth within Z/Eves, where most of the
material reused here is already explained elsewhere [10,11].
4 Independence definition of security in Circus For the part processed by the theorem prover, that is the
hypercalls involving event channels, we have proved both
Next, we define the information flow security policy we want all generated proof obligations, as well as extra housekeep-
that needs to be proved. For that, we combine the Xenon ing for Z/Eves and properties of interest, as pointed out in
process with the chaotic evtchnBalagan process into a lazy various places in this paper (e.g., some state components of

123
L. Freitas, J. McDermott

the hypervisor are given as a set of pairs, yet we prove this served under refinement, unlike other trace-based definitions,
set of pairs are an injective, 1–1 function). The specification allows us to use the Circus refinement calculus directly,
presented in this paper has about 89 Z paragraphs and 38 without having to re-prove security for each refinement.
Circus constructs for CSP and their combination. This gen- The Xenon project’s hypercall interface specification is
erated about 30 domain checks proof obligations, as well as an industrial-scale application of the Circus formalism to
one feasibility proof obligation for every schema as either modelling an actual industrial hypercall interface. The use
precondition calculation (e.g., operation post states are fea- of Circus allows us to refine our security definition without
sible) of invariant satisfiability (e.g., existence proof that the the use of unwinding rules or theorems. Trace-based defini-
schema invariant for various state components above is fea- tions of information-flow security typically require the use of
sible). This does not include the various lemmas necessary these rules to apply the definition to state-based implemen-
for many of these proofs, some of which are from a cata- tations. Unwinding rules add complexity that is not inherent
log of proofs involving complex schemas started in [10], and in the security problem we are trying to solve. Unwinding
many other lemmas that are new, in particular those about rule complexity is caused by limitations in the chosen spec-
injective functions, which started in [11]. Lemmas for lay- ification language. Since Circus treats both traces and rich
ered promotion were also needed. We got inspiration (and state, the “unwinding issues” are addressed automatically by
reuse) from [4]. the definition of the language. Our specification shows how
Among proof obligations for the work presented here, the Circus provides a powerful and natural way to describe state-
most complex were the proof of separation of the hypervi- rich and trace-rich concurrent behaviour together in a single
sor state components, as well as the non-interference proof model that is amenable to refinement calculation.
for lazy abstraction. This took over half-man-year of effort We have introduced the concept of a Z parameter schema
spread over about one and half years. Since this is ongoing as a means of organising industrial scale Circus specifica-
work, we have not finished measuring the amount of time / tions. Like the concept of a Z framing schema used in pro-
effort involved in these proofs. It suffices to say that we are a motion [32, Chap. 13], a Z parameter schema is used as a
team of about two proof experts, and around 2–5 kernel engi- means of factoring and organising a large specification into
neers. NRL started work on Xenon a few years ago, yet we largely independent components. Unlike a framing schema,
got involved into formal modelling Xenon since late (about a parameter schema organises and isolates the details of how
October) 2008. Circus channel values are related to Z variables. Changes
to these details are thus localised in the parameter schema.
Of course, the parameter schema concept only applies to
6 Conclusions Circus, and not to Z specifications, since the latter does not
have channel communication.
The Xenon project is re-engineering the Xen open source
hypervisor into a higher-assurance form, with a focus on Future work
information-flow security. In the Xenon project, we use for-
mal specifications as both guides for re-engineering and for We already have an abstract notion of the Xenon security pol-
assurance that the actual hypervisor enforces the desired icy also specified in Circus and presented in [23]. The work
security policy. Our formal modelling of both the fundamen- reported here represents a concrete specification of the actual
tal definition of security and the hypercall interface behaviour Xenon code’s intent in the same formalism. We plan to apply
made beneficial contributions to the re-engineering effort. the Circus refinement calculus to these two models in order
We also constructed a partial internal design specification to achieve a complete top-down refinement from abstract
that was less successful, as we will explain momentarily. notion of security down to its code-level implementation, for
To our knowledge, the Xenon project’s formal definition at least key event-channel APIs. This will increase the levels
of security is the first application of the Roscoe, Woodcock, of security in Xenon in the sense that security attacks (over
and Wulf [29] style of non-interference to kernel design. This the modelled and refined APIs) are ruled out by construction.
is significant not only because their notion is preserved by We plan to report the extent of this proof in due course. We
refinement, but also because it is a well-understood definition are also working on a proof for a model of pointers to be
of security that has undergone significant external review. used as a refinement target of the various tables used in state
The definition also subsumes the well-understood take-grant schemas above.
definition [20] used by seL4 and is similar to, but more
tractable than, the non-interference definition used by MILS Acknowledgments The first author is grateful for the financial sup-
port offered by Qinetiq Malvern and the National Physical Labora-
systems [12]. We chose this definition because of its rela- tory (NPL, UK) during some of the work with Xenon while at York.
tive simplicity in comparison to other trace-based definitions Having recently moved to Newcastle University, he is also grateful for
of information flow security [21,25]. The fact that it is pre- the support of Cliff Jones within the EPSRC funded AI4FM project

123
Formal methods for security in the Xenon hypervisor

at Newcastle, who made the later stages of this work possible. Both 18. Klein, G., Elphinstone, K., Heiser, G., Andronick, J., Cook, D.,
authors are grateful to Jim Woodcock for invaluable comments on the Derrin, P., Elkaduwe, D., Englehardt, K., Kolanski, R., Norrish,
extension of the CSP notion of non-interference for Circus. M., Sewell, T., Tuch, H., Winwood, S.: seL4: Formal verification
of an OS kernel. In: Proceedings of 22nd ACM Symposium on
Operating System Principles, Big Sky, MT, USA, October 2009
19. Leinenbach, D., Santen, T.: Verifying the microsoft hyper-v hyper-
References visor with vcc. In: Cavalcanti, A., Dams, D. (eds.) FM 2009: Formal
Methods. Lecture Notes in Computer Science, vol. 5850, pp. 806–
1. Anderson, R.: Security Engineering: A Guide to Building Depend- 809. Springer, Berlin (2009)
able Distributed Systems. 2nd edn. Wiley, New York (2008) 20. Lipton, R., Lawrence, S.: A linear-time algorithm for deciding
2. Back, R.-J., von Wright, J.: Refinement Calculus: A System- subject security. JACM 24(3), 455–464 (1977)
atic Introduction. Graduate Text in Computer Science. Springer, 21. Mantel, H.: The framework of selective interleaving functions and
New York (1998) the modular assembly kit. In: Proceedings of Formal Methods in
3. Barham, P., Dragovic, B., Fraiser, K., Hand, S., Harris, T., Ho, A., Security Engineering, Fairfax, Virginia, USA, November 2005
Neugebauer, R., Pratt, I., Warfield, A.: Xen and the art of virtual- 22. McDermott, J.: Fine-grained inspection for higher-assurance soft-
ization. In: Proceedings of 19th ACM Symposium on Operating ware security in open source. In: Proceedings of 43rd Hawaii Inter-
Systems Principles (SOSP-19), Bolton Landing, New York, USA, national Conference on Systems and Sciences, pp. 1–10, Kauai, HI,
October 2003 January 2010
4. Butterfield, A., Freitas, L., Woodcock, J.: Mechanising a formal 23. McDermott, J., Freitas, L.: A formal security policy model for
model of flash memory. Sci. Comput. Program. 74(4), 219–237 Xenon. In: Proceedings of Formal Methods in Security Engineer-
(2009) ing (FMSE ’08), October 2008
5. Chisnall, D.: The Definitive Guide to the Xen Hypervisor. Prentice- 24. McDermott, J., Kirby, J., Montrose, B., Johnson, T., Kang,
Hall, Englewood Cliffs (2008) M.: Re-engineering Xen internals for higher-assurance secu-
6. Coker, G.: Xen security modules. Xen Summit 2007 Presentation, rity. Inform. Secur. Tech. Rep. 13(1), 17–24 (2008)
April 2007. http://www.xensource.com/xen/xensummit.html 25. McLean, J.: A general theory of composition for trace sets closed
7. The Common Criteria Project Sponsoring Organizations.: Com- under selective interleaving functions. In: Proceedings of IEEE
mon Criteria for Information Technology Security Evaluation, Symposium on Research in Security and Privacy, Oakland, Cali-
v. 3.1, rev. 1 (edn.), September 2006. Also referred to as ISO 15408 fornia, USA, May 1994
8. The Common Criteria Project Sponsoring Organizations.: Com- 26. Oliveira, M., Cavalcanti, A., Woodcock, J.: A UTP semantics for
mon Methodology for Information Technology Security Evalua- Circus. Form. Asp. Comput. 21(1), 3–32 (2007)
tion, v. 3.1, rev. 1 (edn.), September 2006 27. Oliveira, M.V.M., Cavalcanti, A.L.C., Woodcock, J.C.P.: A de-
9. Denning, D.: A lattice model of secure information flow. Commun. notational semantics for Circus. In: Aichernig, B., Derrick,
ACM 19(5) (1976) J. (eds.) REFINE’2006, Eletronic Notes in Theoretical Computer
10. Freitas, L., Woodcock, J.: Mechanising Mondex with Z/Eves. Science, Elsevier, Amsterdam (2006)
Form. Asp. Comput. 20(1), 117–139 (2008) 28. Roscoe, A.: The Theory and Practice of Concurrency. Prentice-
11. Freitas, L., Woodcock, J.: A chain datatype in z. Int. J. Softw. Hall, Englewood Cliffs (1997)
Inform. 3(2–3), 357–374 (2009) 29. Roscoe, A., Woodcock, J., Wulf, L.: Non-interference through
12. Greeve, D., Wilding, M., Vanfleet, W.M.: A separation kernel for- determinism. In: Proc. ESORICS, Brighton, UK, November 1994
mal security policy. In: Proceedings of ACL2 Workshop, Boulder, 30. Ryan, P., Schneider, S.: Modelling and Analysis of Security
Colorado, USA, July 2003 Protocols. Addison-Wesley, Reading (2001)
13. Hoare, C.: Communicating Sequential Processes. Prentice- 31. Sailer, R., Jaeger, T., Valdez, E., Cáceres, R., Perez, R., Berger, S.,
Hall, Englewood Cliffs (1985) Griffin, J., van Doorn, L.: Building a MAC-based security archi-
14. IA-32 Intel Architecture Software Developer’s Manual: vol. 3A: tecture for the Xen open-source hypervisor. In: Proceedings of
System Programming Guide, part 1. Technical Report 253668- 21st Annual Computer Security Applications Conference, Tucson,
020US, Intel Corp., June 2006 Arizona, USA, December 2005
15. ISO/IEC.: ISO/IEC 13568: Information Technology—Z Formal 32. Woodcock, J., Davies, J.: Using Z: Specification, Refinement,
Specification Notation—Syntax, Type System and Semantics and Proof. International Series in Computer Science. Prentice-
(2002) Hall, Englewood Cliffs (1996)
16. Jackson, D.: A direct path to dependable software. Commun. 33. Woodcock, J.C.P., Cavalcanti, A.L.C., Gaudel, M.-C., Freitas,
ACM 52(4), 78–88 (2009) L.J.S.: Operational Semantics for Circus. Form. Asp. Comput.
17. Klein, G., Andronick, J., Elphinstone, K., Heiser, G., Cock, D., (2009, in press)
Derrin, P., Elkaduwe, D., Engelhardt, K., Kolanski, R., Norrish,
M., Sewell, T., Tuch, H., Winwood, S.: seL4: Formal verification
of an OS kernel. Commun. ACM 53(6), 107–115 (2010)

123

You might also like