Debian Codegraph @

docs/misc/xsm-flask.txt

raw
1 -----------------------
2 XSM/FLASK Configuration
3 -----------------------
4
5 Xen provides a security framework called XSM, and FLASK is an implementation of
6 a security model using this framework (at the time of writing, it is the only
7 one). FLASK defines a mandatory access control policy providing fine-grained
8 controls over Xen domains, allowing the policy writer to define what
9 interactions between domains, devices, and the hypervisor are permitted.
10
11 Some examples of what FLASK can do:
12 - Prevent two domains from communicating via event channels or grants
13 - Control which domains can use device passthrough (and which devices)
14 - Restrict or audit operations performed by privileged domains
15 - Prevent a privileged domain from arbitrarily mapping pages from other domains
16
17 Some of these examples require dom0 disaggregation to be useful, since the
18 domain build process requires the ability to write to the new domain's memory.
19
20 Security Status of dom0 disaggregation
21 --------------------------------------
22
23 Xen supports disaggregation of various support and management
24 functions into their own domains, via the XSM mechanisms described in
25 this document.
26
27 However the implementations of these support and management interfaces
28 were originally written to be used only by the totally-privileged
29 dom0, and have not been reviewed for security when exposed to
30 supposedly-only-semi-privileged disaggregated management domains. But
31 such management domains are (in such a design) to be seen as
32 potentially hostile, e.g. due to privilege escalation following
33 exploitation of a bug in the management domain.
34
35 Until the interfaces have been properly reviewed for security against
36 hostile callers, the Xen.org security team intends (subject of course
37 to the permission of anyone disclosing to us) to handle these and
38 future vulnerabilities in these interfaces in public, as if they were
39 normal non-security-related bugs.
40
41 This applies only to bugs which do no more than reduce the security of
42 a radically disaggregated system to the security of a
43 non-disaggregated one. Here a "radically disaggregated system" is one
44 which uses the XSM mechanism to delegate the affected interfaces to
45 other-than-fully-trusted domains.
46
47 This policy does not apply to bugs which affect stub device models,
48 driver domains, or stub xenstored - even if those bugs do no worse
49 than reduce the security of such a system to one whose device models,
50 backend drivers, or xenstore, run in dom0.
51
52 For more information see https://xenbits.xen.org/xsa/advisory-77.html.
53
54 The following interfaces are covered by this statement. Interfaces
55 not listed here are considered safe for disaggregation, security
56 issues found in interfaces not listed here will be handled according
57 to the normal security problem response policy
58 https://www.xenproject.org/security-policy.html.
59
60 __HYPERVISOR_domctl (xen/include/public/domctl.h)
61
62 All subops except the following are covered by this statement. (That
63 is, only the subops below are considered safe for disaggregation.)
64
65 * XEN_DOMCTL_ioport_mapping
66 * XEN_DOMCTL_memory_mapping
67 * XEN_DOMCTL_bind_pt_irq
68 * XEN_DOMCTL_unbind_pt_irq
69
70 __HYPERVISOR_sysctl (xen/include/public/sysctl.h)
71
72 All subops are covered by this statement. (That is, no subops are
73 considered safe for disaggregation.)
74
75 __HYPERVISOR_memory_op (xen/include/public/memory.h)
76
77 The following subops are covered by this statement. subops not listed
78 here are considered safe for disaggregation.
79
80 * XENMEM_set_pod_target
81 * XENMEM_get_pod_target
82 * XENMEM_claim_pages
83
84
85 Setting up FLASK
86 ----------------
87
88 Xen must be compiled with XSM and FLASK enabled; by default, the security
89 framework is disabled. Running 'make -C xen menuconfig' and enabling XSM
90 and FLASK inside 'Common Features'; this change requires a make clean and
91 rebuild.
92
93 FLASK uses only one domain configuration parameter (seclabel) defining the
94 full security label of the newly created domain. If using the example policy,
95 "seclabel='system_u:system_r:domU_t'" is an example of a normal domain. The
96 labels are in the same format as SELinux labels; see http://selinuxproject.org
97 for more details on the use of the user, role, and optional MLS/MCS labels.
98
99 FLASK policy overview
100 ---------------------
101
102 Most of FLASK policy consists of defining the interactions allowed between
103 different types (domU_t would be the type in this example). For simple policies,
104 only type enforcement is used and the user and role are set to system_u and
105 system_r for all domains.
106
107 The FLASK security framework is mostly configured using a security policy file.
108 It relies on the SELinux compiler "checkpolicy"; if this is available, the
109 policy will be compiled as part of the tools build. If hypervisor support for a
110 built-in policy is enabled ("Compile Xen with a built-in security policy"), the
111 policy will be built during the hypervisor build.
112
113 The policy is generated from definition files in tools/flask/policy. Most
114 changes to security policy will involve creating or modifying modules found in
115 tools/flask/policy/modules/. The modules.conf file there defines what modules
116 are enabled and has short descriptions of each module.
117
118 If not using the built-in policy, the XSM policy file needs to be copied to
119 /boot and loaded as a module by grub. The exact position and filename of the
120 module does not matter as long as it is after the Xen kernel; it is normally
121 placed either just above the dom0 kernel or at the end. Once dom0 is running,
122 the policy can be reloaded using "xl loadpolicy".
123
124 The example policy included with Xen demonstrates most of the features of FLASK
125 that can be used without dom0 disaggregation. The main types for domUs are:
126
127 - domU_t is a domain that can communicate with any other domU_t
128 - isolated_domU_t can only communicate with dom0
129 - prot_domU_t is a domain type whose creation can be disabled with a boolean
130 - nomigrate_t is a domain that must be created via the nomigrate_t_building
131 type, and whose memory cannot be read by dom0 once created
132
133 HVM domains with stubdomain device models also need a type for the stub domain.
134 The example policy defines dm_dom_t for the device model of a domU_t domain;
135 there are no device model types defined for the other domU types.
136
137 One disadvantage of using type enforcement to enforce isolation is that a new
138 type is needed for each group of domains. The user field can be used to address
139 this for the most common case of groups that can communicate internally but not
140 externally; see "Users and roles" below.
141
142 Type transitions
143 ----------------
144
145 Xen defines a number of operations such as memory mapping that are necessary for
146 a domain to perform on itself, but are also undesirable to allow a domain to
147 perform on every other domain of the same label. While it is possible to address
148 this by only creating one domain per type, this solution significantly limits
149 the flexibility of the type system. Another method to address this issue is to
150 duplicate the permission names for every operation that can be performed on the
151 current domain or on other domains; however, this significantly increases the
152 necessary number of permissions and complicates the XSM hooks. Instead, this is
153 addressed by allowing a distinct type to be used for a domain's access to
154 itself. The same applies for a device model domain's access to its designated
155 target, allowing the IS_PRIV_FOR checks used in Xen's DAC model to be
156 implemented in FLASK.
157
158 Upon domain creation (or relabel), a type transition is computed using the
159 domain's label as the source and target. The result of this computation is used
160 as the target when the domain accesses itself. In the example policy, this
161 computed type is the result of appending _self to a domain's type: domU_t_self
162 for domU_t. If no type transition rule exists, the domain will continue to use
163 its own label for both the source and target. An AVC message will look like:
164
165 scontext=system_u:system_r:domU_t tcontext=system_u:system_r:domU_t_self
166
167 A similar type transition is done when a device model domain is associated with
168 its target using the set_target operation. The transition is computed with the
169 target domain as the source and the device model domain as the target: this
170 ordering was chosen in order to preserve the original label for the target when
171 no type transition rule exists. In the example policy, these computed types are
172 the result of appending _target to the domain.
173
174 Type transitions are also used to compute the labels of event channels.
175
176 Users and roles
177 ---------------
178
179 The default user and role used for domains is system_u and system_r. Users are
180 visible in the labels of domains and associated objects (event channels); when
181 the vm_role module is enabled, "user_1:vm_r:domU_t" is a valid label for a
182 domain created by the user_1 user.
183
184 Access control rules involving users and roles are defined in a module's
185 constraints file (for example, vm_rule.cons). The vm_role module defines one
186 role (vm_r) and three users (user_1 .. user_3), along with constraints that
187 prevent different users from communicating using grants or event channels, while
188 still allowing communication with the system_u user where dom0 resides.
189
190 Resource Policy
191 ---------------
192
193 The example policy also includes a resource type (nic_dev_t) for device
194 passthrough, configured to allow use by domU_t. To label the PCI device 3:2.0
195 for passthrough, run:
196
197 tools/flask/utils/flask-label-pci 0000:03:02.0 system_u:object_r:nic_dev_t
198
199 This command must be rerun on each boot or after any policy reload.
200
201 When first loading or writing a policy, you should run FLASK in permissive mode
202 (flask=permissive on the command line) and check the Xen logs (xl dmesg) for AVC
203 denials before using it in enforcing mode (the default value of the boot
204 parameter, which can also be changed using xl setenforce). When using the
205 default types for domains (domU_t), the example policy shipped with Xen should
206 allow the same operations on or between domains as when not using FLASK.
207
208 By default, flask-label-pci labels the device, I/O ports, memory and IRQ with
209 the provided label. These are all unique per-device, except for IRQs which
210 can be shared between devices. This leads to assignment problems since vmA_t
211 can't access the IRQ devB_t. To work around this issue, flask-label-pci
212 takes an optional 3rd argument to label the IRQ:
213
214 flask-label-pci 0000:03:02.0 system_u:object_r:nic_dev_t \
215 system_u:object_r:shared_irq_t
216
217 The IRQ labeling only applies to the PIRQ - MSI/MSI-X interrupts are labeled
218 with the main device label.
219
220 The policy needs to define the shared_irq_t with:
221 type shared_irq_t, resource_type;
222
223 And the policy needs to be updated to allow domains appropriate access.
224
225 MLS/MCS policy
226 --------------
227
228 If you want to use the MLS policy, then set TYPE=xen-mls in the policy Makefile
229 before building the policy. Note that the MLS constraints in policy/mls
230 are incomplete and are only a sample.
231
232
233 AVC denials
234 -----------
235
236 XSM:Flask will emit avc: denied messages when a permission is denied by the
237 policy, just like SELinux. For example, if the HVM rules are removed from the
238 declare_domain and create_domain interfaces:
239
240 # xl dmesg | grep avc
241 (XEN) avc: denied { setparam } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
242 (XEN) avc: denied { getparam } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
243 (XEN) avc: denied { irqlevel } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
244 (XEN) avc: denied { pciroute } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
245 (XEN) avc: denied { setparam } for domid=4 scontext=system_u:system_r:domU_t tcontext=system_u:system_r:domU_t tclass=hvm
246 (XEN) avc: denied { cacheattr } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
247 (XEN) avc: denied { pcilevel } for domid=0 scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=hvm
248
249 Existing SELinux tools such as audit2allow can be applied to these denials, e.g.
250 xl dmesg | audit2allow
251
252 The generated allow rules can then be fed back into the policy by adding them to
253 a module, although manual review is advised and will often lead to adding
254 parameterized rules to the interfaces in xen.if to address the general case.
255
256
257 Device Labeling in Policy
258 -------------------------
259
260 FLASK is capable of labeling devices and enforcing policies associated with
261 them. There are two methods to label devices: dynamic labeling using
262 flask-label-pci or similar tools run in dom0, or static labeling defined in
263 policy. Static labeling will make security policy machine-specific and may
264 prevent the system from booting after any hardware changes (adding PCI cards,
265 memory, or even changing certain BIOS settings). Dynamic labeling requires that
266 the domain performing the labeling be trusted to label all the devices in the
267 system properly.
268
269 IRQs, PCI devices, I/O memory and x86 IO ports can all have labels defined.
270 There are examples commented out in tools/flask/policy/policy/device_contexts.
271
272 Device Labeling
273 ---------------
274
275 The "lspci -vvn" command can be used to output all the devices and identifiers
276 associated with them. For example, to label an Intel e1000e ethernet card the
277 lspci output is..
278
279 00:19.0 0200: 8086:10de (rev 02)
280 Subsystem: 1028:0276
281 Interrupt: pin A routed to IRQ 33
282 Region 0: Memory at febe0000 (32-bit, non-prefetchable) [size=128K]
283 Region 1: Memory at febd9000 (32-bit, non-prefetchable) [size=4K]
284 Region 2: I/O ports at ecc0 [size=32]
285 Kernel modules: e1000e
286
287 The labeling can be done with these lines in device_contexts:
288
289 pirqcon 33 system_u:object_r:nicP_t
290 iomemcon 0xfebe0-0xfebff system_u:object_r:nicP_t
291 iomemcon 0xfebd9 system_u:object_r:nicP_t
292 ioportcon 0xecc0-0xecdf system_u:object_r:nicP_t
293 pcidevicecon 0xc800 system_u:object_r:nicP_t
294
295 The PCI device label must be computed as the 32-bit SBDF number for the PCI
296 device. It the PCI device is aaaa:bb:cc.d or bb:cc.d, then the SBDF can be
297 calculated using:
298 SBDF = (a << 16) | (b << 8) | (c << 3) | d
299
300 The AVC denials for IRQs, memory, ports, and PCI devices will normally contain
301 the ranges being denied to more easily determine what resources are required.
302 When running in permissive mode, only the first denial of a given
303 source/destination is printed to the log, so labeling devices using this method
304 may require multiple passes to find all required ranges.