blob: 1031f0fbd556baebc5429e72de56467fade546a2 [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
Elliot Bermanae5869a2023-03-22 17:31:35 -07005# Let crosvm open VM manager devices such as /dev/kvm.
6allow crosvm vm_manager_device_type:chr_file rw_file_perms;
Andrew Walbrana995e842021-03-29 17:19:12 +00007
Alice Wang23b712e2024-08-01 08:29:31 +00008# TODO(b/357025924): This is a temporary workaround to allow the KeyMint VM to use crosvm
9# directly. It should be removed once the KeyMint VM can be started with early_virtmgr
10is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, init_daemon_domain(crosvm))
11
Andrew Walbrana995e842021-03-29 17:19:12 +000012# Most other domains shouldn't access /dev/kvm.
13neverallow { domain -crosvm -ueventd -shell } kvm_device:chr_file getattr;
Andrew Walbran2f27f962022-01-28 15:42:48 +000014neverallow { domain -crosvm -ueventd } kvm_device:chr_file ~getattr;
Jiyong Park2dd48d02021-12-28 21:26:03 +090015neverallowxperm { domain -crosvm } kvm_device:chr_file ioctl ~{ KVM_CHECK_EXTENSION };
Andrew Walbran9b2fa1b2021-07-01 15:58:26 +000016
Elliot Bermanae5869a2023-03-22 17:31:35 -070017# Most other domains shouldn't access other vm managers either.
18# These restrictions need to be slightly looser than for kvm_device to allow
19# for different implementations.
20neverallow { coredomain appdomain -crosvm -ueventd -shell } vm_manager_device_type:chr_file getattr;
21neverallow { coredomain appdomain -crosvm -ueventd } vm_manager_device_type:chr_file ~getattr;
22
Jiyong Park5e20d832021-07-12 21:11:33 +090023# Let crosvm create temporary files.
24tmpfs_domain(crosvm)
25
26# Let crosvm receive file descriptors from VirtualizationService.
Inseob Kim41fe7ea2024-09-03 10:59:07 +090027allow crosvm {
28 virtualizationmanager
29 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
30}:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090031
Inseob Kim42798af2023-01-13 14:08:16 +090032# Allow sending VirtualizationService the failure reason and console/log from the VM via pipe.
Inseob Kim41fe7ea2024-09-03 10:59:07 +090033allow crosvm {
34 virtualizationmanager
35 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
36}:fifo_file write;
Alan Stokesb02ac322022-03-09 14:05:18 +000037
Jiyong Park5e20d832021-07-12 21:11:33 +090038# Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes
39# (staging_data_file), APKs (apk_data_file and shell_data_file where the latter is for test apks in
Seungjae Yood2a08922023-11-15 17:59:30 +090040# /data/local/tmp), instance.img (app_data_file), and microdroid vendor image (vendor_microdroid_file).
Alice Wang40519f72023-08-31 11:37:30 +000041# Allow crosvm to read the instance image of the service VM saved in apex_virt_data_file.
42# Note that the open permission is not given as the files are passed as file descriptors.
Jiyong Park5e20d832021-07-12 21:11:33 +090043allow crosvm {
44 virtualizationservice_data_file
45 staging_data_file
46 apk_data_file
47 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010048 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010049 apex_compos_data_file
Alice Wang40519f72023-08-31 11:37:30 +000050 apex_virt_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +090051 shell_data_file
Seungjae Yood2a08922023-11-15 17:59:30 +090052 vendor_microdroid_file
Inseob Kim0b9625d2024-07-31 17:42:23 +090053 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Jiyong Park5e20d832021-07-12 21:11:33 +090054}:file { getattr read ioctl lock };
55
56# Allow searching the directory where the composite disk images are.
Inseob Kim0b9625d2024-07-31 17:42:23 +090057allow crosvm {
58 virtualizationservice_data_file
59 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
60}:dir search;
Jiyong Park5e20d832021-07-12 21:11:33 +090061
Alan Stokesaeab04f2024-02-01 16:16:01 +000062# When running a VM as root we get spurious capability denials.
63# Suppress them.
64userdebug_or_eng(`
65 dontaudit crosvm self:capability ipc_lock;
66')
67
David Dai7066a962024-02-01 15:19:03 -080068# Allow crosvm to tune for performance.
69allow crosvm self:global_capability_class_set sys_nice;
70
Keir Fraserad58b8d2022-07-11 14:27:40 +000071# Let crosvm access its control socket as created by VS.
72# read, write, getattr: listener socket polling
73# accept: listener socket accepting new connection
74# Note that the open permission is not given as the socket is passed by FD.
Inseob Kim41fe7ea2024-09-03 10:59:07 +090075allow crosvm {
76 virtualizationmanager
77 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
78}:unix_stream_socket { accept read write getattr getopt };
Keir Fraserad58b8d2022-07-11 14:27:40 +000079
Jaewan Kim7b843d42022-12-07 16:18:18 +090080# Let crosvm open test artifacts under /data/local/tmp with file path. (e.g. custom pvmfw.img)
81userdebug_or_eng(`
82 allow crosvm shell_data_file:dir search;
83 allow crosvm shell_data_file:file open;
84')
85
Jiyong Park5e20d832021-07-12 21:11:33 +090086# The instance image and the composite image should be writable as well because they could represent
87# mutable disks.
88allow crosvm {
89 virtualizationservice_data_file
90 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010091 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010092 apex_compos_data_file
Alice Wang40519f72023-08-31 11:37:30 +000093 apex_virt_data_file
Inseob Kim0b9625d2024-07-31 17:42:23 +090094 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Jiyong Park5e20d832021-07-12 21:11:33 +090095}:file write;
96
97# 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 +010098allow crosvm adbd:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090099allow crosvm adbd:unix_stream_socket { read write };
Alan Stokes6d019be2023-06-08 13:13:08 +0100100allow crosvm devpts:chr_file { read write getattr ioctl };
Jiyong Park5e20d832021-07-12 21:11:33 +0900101
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900102is_flag_enabled(RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES, `
103 # Allow crosvm to draw screen in the surface
104 allow crosvm device:dir { read open };
105 allow crosvm same_process_hal_file:file { read open getattr map execute };
106 allow crosvm gpu_device:chr_file { read write open ioctl map open getattr };
107 allow crosvm hal_graphics_allocator:fd use;
108 allow crosvm hal_graphics_allocator_server:binder call;
109 allow crosvm surfaceflinger:fd use;
110 hal_client_domain(crosvm, hal_graphics_allocator)
111
112 # To provide display service to an app to get surface.
113 # TODO(b/332677707): remove them when display service uses binder RPC.
Jeongik Cha77a3ca62024-04-09 15:02:28 +0900114 allow crosvm vmlauncher_app:binder { transfer call };
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900115 allow crosvm servicemanager:binder { call transfer };
116 allow crosvm virtualization_service:service_manager find;
117 allow crosvm virtualizationservice:binder { call transfer };
Mu-Le Leec7177f72024-04-17 08:38:47 +0800118
119 # Allow crosvm to play sound.
120 binder_call(crosvm, audioserver)
121 allow crosvm audioserver_service:service_manager find;
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900122')
123
Steven Morelandfd59a2d2022-04-04 20:20:24 +0000124# crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254)
125dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl;
126
Jiyong Park2eab15e2022-05-02 13:23:50 +0900127# crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by
128# compliance tests and demo apps. Write access to instance.img is particularily important because
129# the VM has to initialize the disk image on its first boot. Note that open access is still not
130# granted because the files are expected to be opened by the owner of the VM (apps or shell in case
131# when the vm is created by the `vm` tool) and handed over to crosvm as FD.
132allow crosvm shell_data_file:file write;
Jiyong Park3fee5a42021-08-09 09:24:45 +0900133
Inseob Kim42798af2023-01-13 14:08:16 +0900134# crosvm tries to read serial device, including the write-only pipe from virtualizationmanager (to
135# forward console/log to the host logcat).
136# crosvm only needs write permission, so dontaudit read
Inseob Kim41fe7ea2024-09-03 10:59:07 +0900137dontaudit crosvm {
138 virtualizationmanager
139 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
140}:fifo_file { read getattr };
Inseob Kim42798af2023-01-13 14:08:16 +0900141
Nikita Ioffe40a48c12023-02-14 23:17:55 +0000142# Required for crosvm to start gdb-server to enable debugging of guest kernel.
143allow crosvm self:tcp_socket { bind create read setopt write accept listen };
144allow crosvm port:tcp_socket name_bind;
145allow crosvm adbd:unix_stream_socket ioctl;
146allow crosvm node:tcp_socket node_bind;
147
Inseob Kim825056d2023-08-01 11:00:49 +0900148# Allow crosvm to interact to VFIO device
149allow crosvm vfio_device:chr_file rw_file_perms;
150allow crosvm vfio_device:dir r_dir_perms;
151
Inseob Kimbbe514d2023-08-03 12:53:48 +0900152# Allow crosvm to access VM DTBO via a file created by virtualizationmanager.
Inseob Kimbbe514d2023-08-03 12:53:48 +0900153allow crosvm virtualizationservice_data_file:file read;
Inseob Kim825056d2023-08-01 11:00:49 +0900154
Seungjae Yoo12fd4822024-05-28 14:12:52 +0900155is_flag_enabled(RELEASE_AVF_ENABLE_NETWORK, `
156 # Allow crosvm to deal with file descriptors of TAP interfaces.
157 allow crosvm tun_device:chr_file rw_file_perms;
Seungjae Yoofcecae72024-06-14 15:27:05 +0900158 allowxperm crosvm tun_device:chr_file ioctl { TUNGETIFF TUNSETOFFLOAD TUNSETVNETHDRSZ };
Seungjae Yoo12fd4822024-05-28 14:12:52 +0900159 allow crosvm self:udp_socket create_socket_perms;
160 allowxperm crosvm self:udp_socket ioctl SIOCGIFMTU;
161 allow crosvm vmnic:fd use;
162')
163
Inseob Kim41fe7ea2024-09-03 10:59:07 +0900164# Early VMs may print messages to kmsg_debug_device.
165allow crosvm kmsg_debug_device:chr_file w_file_perms;
166
Alan Stokes30608522022-10-24 12:32:34 +0100167# Don't allow crosvm to open files that it doesn't own.
168# This is important because a malicious application could try to start a VM with a composite disk
169# image referring by name to files which it doesn't have permission to open, trying to get crosvm to
170# open them on its behalf. By preventing crosvm from opening any other files we prevent this
171# potential privilege escalation. See http://b/192453819 for more discussion.
172neverallow crosvm {
173 virtualizationservice_data_file
174 staging_data_file
175 apk_data_file
176 app_data_file
177 privapp_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000178 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900179 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Alan Stokes30608522022-10-24 12:32:34 +0100180 userdebug_or_eng(`-shell_data_file')
181}:file open;
182
Jiyong Park3fee5a42021-08-09 09:24:45 +0900183# Don't allow crosvm to have access to ordinary vendor files that are not for VMs.
184full_treble_only(`
185 neverallow crosvm {
186 vendor_file_type
187 -vendor_vm_file
188 -vendor_vm_data_file
189 # These types are not required for crosvm, but the access is granted to globally in domain.te
190 # thus should be exempted here.
191 -vendor_configs_file
Seungjae Yood2a08922023-11-15 17:59:30 +0900192 -vendor_microdroid_file
Jiyong Park3fee5a42021-08-09 09:24:45 +0900193 -vndk_sp_file
194 -vendor_task_profiles_file
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900195 is_flag_enabled(RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES, `-same_process_hal_file')
Jiyong Park3fee5a42021-08-09 09:24:45 +0900196 }:file *;
197')
Jiyong Park028e7222021-11-26 00:59:07 +0900198
Alan Stokes30608522022-10-24 12:32:34 +0100199# Only allow crosvm to read app data files for clients that can start
200# VMs. Note that the use of app data files is further restricted
201# inside the virtualizationservice by checking the label of all disk
202# image files.
Jiyong Park028e7222021-11-26 00:59:07 +0900203neverallow crosvm {
204 app_data_file_type
205 -app_data_file
Alan Stokes30608522022-10-24 12:32:34 +0100206 -privapp_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +0900207 -shell_data_file
Jiyong Park028e7222021-11-26 00:59:07 +0900208}:file read;
Inseob Kimb20cb782022-02-03 15:30:26 +0900209
David Brazdil55d808c2022-12-15 13:38:42 +0000210# Only virtualizationmanager can run crosvm
Inseob Kimb20cb782022-02-03 15:30:26 +0900211neverallow {
212 domain
213 -crosvm
David Brazdil55d808c2022-12-15 13:38:42 +0000214 -virtualizationmanager
Alice Wang23b712e2024-08-01 08:29:31 +0000215 # TODO(b/357025924): This is a temporary workaround to allow the KeyMint VM to use crosvm
216 # directly. It should be removed once the KeyMint VM can be started with early_virtmgr
217 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `-init')
Inseob Kim41fe7ea2024-09-03 10:59:07 +0900218
219 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `-early_virtmgr')
Inseob Kimb20cb782022-02-03 15:30:26 +0900220} crosvm_exec:file no_x_file_perms;