blob: c682bb504fb49dabb47e6e27e548dca6c3efd1aa [file] [log] [blame]
Andrew Walbrana995e842021-03-29 17:19:12 +00001type crosvm, domain, coredomain;
2type crosvm_exec, system_file_type, exec_type, file_type;
3type crosvm_tmpfs, file_type;
4
Andrew Walbrana995e842021-03-29 17:19:12 +00005# Let crosvm open /dev/kvm.
6allow crosvm kvm_device:chr_file rw_file_perms;
7
8# Most other domains shouldn't access /dev/kvm.
9neverallow { domain -crosvm -ueventd -shell } kvm_device:chr_file getattr;
Andrew Walbran2f27f962022-01-28 15:42:48 +000010neverallow { domain -crosvm -ueventd } kvm_device:chr_file ~getattr;
Jiyong Park2dd48d02021-12-28 21:26:03 +090011neverallowxperm { domain -crosvm } kvm_device:chr_file ioctl ~{ KVM_CHECK_EXTENSION };
Andrew Walbran9b2fa1b2021-07-01 15:58:26 +000012
Jiyong Park5e20d832021-07-12 21:11:33 +090013# Let crosvm create temporary files.
14tmpfs_domain(crosvm)
15
16# Let crosvm receive file descriptors from VirtualizationService.
David Brazdil55d808c2022-12-15 13:38:42 +000017allow crosvm virtualizationmanager:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090018
Alan Stokesb02ac322022-03-09 14:05:18 +000019# Allow sending VirtualizationService the failure reason from the VM via pipe.
David Brazdil55d808c2022-12-15 13:38:42 +000020allow crosvm virtualizationmanager:fifo_file write;
Alan Stokesb02ac322022-03-09 14:05:18 +000021
Jiyong Park5e20d832021-07-12 21:11:33 +090022# Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes
23# (staging_data_file), APKs (apk_data_file and shell_data_file where the latter is for test apks in
24# /data/local/tmp), and instance.img (app_data_file). Note that the open permission is not given as
25# the files are passed as file descriptors.
26allow crosvm {
27 virtualizationservice_data_file
28 staging_data_file
29 apk_data_file
30 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010031 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010032 apex_compos_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +090033 shell_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090034}:file { getattr read ioctl lock };
35
36# Allow searching the directory where the composite disk images are.
37allow crosvm virtualizationservice_data_file:dir search;
38
David Brazdil55d808c2022-12-15 13:38:42 +000039# Allow crosvm to mlock guest memory.
40allow crosvm self:capability ipc_lock;
41
Keir Fraserad58b8d2022-07-11 14:27:40 +000042# Let crosvm access its control socket as created by VS.
43# read, write, getattr: listener socket polling
44# accept: listener socket accepting new connection
45# Note that the open permission is not given as the socket is passed by FD.
David Brazdil55d808c2022-12-15 13:38:42 +000046allow crosvm virtualizationmanager:unix_stream_socket { accept read write getattr getopt };
Keir Fraserad58b8d2022-07-11 14:27:40 +000047
Jaewan Kim7b843d42022-12-07 16:18:18 +090048# Let crosvm open test artifacts under /data/local/tmp with file path. (e.g. custom pvmfw.img)
49userdebug_or_eng(`
50 allow crosvm shell_data_file:dir search;
51 allow crosvm shell_data_file:file open;
52')
53
Jiyong Park5e20d832021-07-12 21:11:33 +090054# The instance image and the composite image should be writable as well because they could represent
55# mutable disks.
56allow crosvm {
57 virtualizationservice_data_file
58 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010059 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010060 apex_compos_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090061}:file write;
62
63# Allow crosvm to pipe console log to shell or app which could be the owner of a VM.
Alan Stokes39f49702021-09-02 11:10:59 +010064allow crosvm adbd:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090065allow crosvm adbd:unix_stream_socket { read write };
Jiyong Park5e20d832021-07-12 21:11:33 +090066
Steven Morelandfd59a2d2022-04-04 20:20:24 +000067# crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254)
68dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl;
69
Jiyong Park2eab15e2022-05-02 13:23:50 +090070# crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by
71# compliance tests and demo apps. Write access to instance.img is particularily important because
72# the VM has to initialize the disk image on its first boot. Note that open access is still not
73# granted because the files are expected to be opened by the owner of the VM (apps or shell in case
74# when the vm is created by the `vm` tool) and handed over to crosvm as FD.
75allow crosvm shell_data_file:file write;
Jiyong Park3fee5a42021-08-09 09:24:45 +090076
Alan Stokes30608522022-10-24 12:32:34 +010077# Don't allow crosvm to open files that it doesn't own.
78# This is important because a malicious application could try to start a VM with a composite disk
79# image referring by name to files which it doesn't have permission to open, trying to get crosvm to
80# open them on its behalf. By preventing crosvm from opening any other files we prevent this
81# potential privilege escalation. See http://b/192453819 for more discussion.
82neverallow crosvm {
83 virtualizationservice_data_file
84 staging_data_file
85 apk_data_file
86 app_data_file
87 privapp_data_file
88 userdebug_or_eng(`-shell_data_file')
89}:file open;
90
Jiyong Park3fee5a42021-08-09 09:24:45 +090091# Don't allow crosvm to have access to ordinary vendor files that are not for VMs.
92full_treble_only(`
93 neverallow crosvm {
94 vendor_file_type
95 -vendor_vm_file
96 -vendor_vm_data_file
97 # These types are not required for crosvm, but the access is granted to globally in domain.te
98 # thus should be exempted here.
99 -vendor_configs_file
100 -vndk_sp_file
101 -vendor_task_profiles_file
102 }:file *;
103')
Jiyong Park028e7222021-11-26 00:59:07 +0900104
Alan Stokes30608522022-10-24 12:32:34 +0100105# Only allow crosvm to read app data files for clients that can start
106# VMs. Note that the use of app data files is further restricted
107# inside the virtualizationservice by checking the label of all disk
108# image files.
Jiyong Park028e7222021-11-26 00:59:07 +0900109neverallow crosvm {
110 app_data_file_type
111 -app_data_file
Alan Stokes30608522022-10-24 12:32:34 +0100112 -privapp_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +0900113 -shell_data_file
Jiyong Park028e7222021-11-26 00:59:07 +0900114}:file read;
Inseob Kimb20cb782022-02-03 15:30:26 +0900115
David Brazdil55d808c2022-12-15 13:38:42 +0000116# Only virtualizationmanager can run crosvm
Inseob Kimb20cb782022-02-03 15:30:26 +0900117neverallow {
118 domain
119 -crosvm
David Brazdil55d808c2022-12-15 13:38:42 +0000120 -virtualizationmanager
Inseob Kimb20cb782022-02-03 15:30:26 +0900121} crosvm_exec:file no_x_file_perms;