blob: 3cae67221ae4da55f326a7e2094c917981c5b1d3 [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.
David Brazdil55d808c2022-12-15 13:38:42 +000027allow crosvm virtualizationmanager:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090028
Inseob Kim42798af2023-01-13 14:08:16 +090029# Allow sending VirtualizationService the failure reason and console/log from the VM via pipe.
David Brazdil55d808c2022-12-15 13:38:42 +000030allow crosvm virtualizationmanager:fifo_file write;
Alan Stokesb02ac322022-03-09 14:05:18 +000031
Jiyong Park5e20d832021-07-12 21:11:33 +090032# Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes
33# (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 +090034# /data/local/tmp), instance.img (app_data_file), and microdroid vendor image (vendor_microdroid_file).
Alice Wang40519f72023-08-31 11:37:30 +000035# Allow crosvm to read the instance image of the service VM saved in apex_virt_data_file.
36# Note that the open permission is not given as the files are passed as file descriptors.
Jiyong Park5e20d832021-07-12 21:11:33 +090037allow crosvm {
38 virtualizationservice_data_file
39 staging_data_file
40 apk_data_file
41 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010042 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010043 apex_compos_data_file
Alice Wang40519f72023-08-31 11:37:30 +000044 apex_virt_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +090045 shell_data_file
Seungjae Yood2a08922023-11-15 17:59:30 +090046 vendor_microdroid_file
Inseob Kim0b9625d2024-07-31 17:42:23 +090047 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Jiyong Park5e20d832021-07-12 21:11:33 +090048}:file { getattr read ioctl lock };
49
50# Allow searching the directory where the composite disk images are.
Inseob Kim0b9625d2024-07-31 17:42:23 +090051allow crosvm {
52 virtualizationservice_data_file
53 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
54}:dir search;
Jiyong Park5e20d832021-07-12 21:11:33 +090055
Alan Stokesaeab04f2024-02-01 16:16:01 +000056# When running a VM as root we get spurious capability denials.
57# Suppress them.
58userdebug_or_eng(`
59 dontaudit crosvm self:capability ipc_lock;
60')
61
David Dai7066a962024-02-01 15:19:03 -080062# Allow crosvm to tune for performance.
63allow crosvm self:global_capability_class_set sys_nice;
64
Keir Fraserad58b8d2022-07-11 14:27:40 +000065# Let crosvm access its control socket as created by VS.
66# read, write, getattr: listener socket polling
67# accept: listener socket accepting new connection
68# Note that the open permission is not given as the socket is passed by FD.
David Brazdil55d808c2022-12-15 13:38:42 +000069allow crosvm virtualizationmanager:unix_stream_socket { accept read write getattr getopt };
Keir Fraserad58b8d2022-07-11 14:27:40 +000070
Jaewan Kim7b843d42022-12-07 16:18:18 +090071# Let crosvm open test artifacts under /data/local/tmp with file path. (e.g. custom pvmfw.img)
72userdebug_or_eng(`
73 allow crosvm shell_data_file:dir search;
74 allow crosvm shell_data_file:file open;
75')
76
Jiyong Park5e20d832021-07-12 21:11:33 +090077# The instance image and the composite image should be writable as well because they could represent
78# mutable disks.
79allow crosvm {
80 virtualizationservice_data_file
81 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010082 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010083 apex_compos_data_file
Alice Wang40519f72023-08-31 11:37:30 +000084 apex_virt_data_file
Inseob Kim0b9625d2024-07-31 17:42:23 +090085 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Jiyong Park5e20d832021-07-12 21:11:33 +090086}:file write;
87
88# 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 +010089allow crosvm adbd:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090090allow crosvm adbd:unix_stream_socket { read write };
Alan Stokes6d019be2023-06-08 13:13:08 +010091allow crosvm devpts:chr_file { read write getattr ioctl };
Jiyong Park5e20d832021-07-12 21:11:33 +090092
Jeongik Chaf09f43c2024-04-02 14:50:14 +090093is_flag_enabled(RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES, `
94 # Allow crosvm to draw screen in the surface
95 allow crosvm device:dir { read open };
96 allow crosvm same_process_hal_file:file { read open getattr map execute };
97 allow crosvm gpu_device:chr_file { read write open ioctl map open getattr };
98 allow crosvm hal_graphics_allocator:fd use;
99 allow crosvm hal_graphics_allocator_server:binder call;
100 allow crosvm surfaceflinger:fd use;
101 hal_client_domain(crosvm, hal_graphics_allocator)
102
103 # To provide display service to an app to get surface.
104 # TODO(b/332677707): remove them when display service uses binder RPC.
Jeongik Cha77a3ca62024-04-09 15:02:28 +0900105 allow crosvm vmlauncher_app:binder { transfer call };
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900106 allow crosvm servicemanager:binder { call transfer };
107 allow crosvm virtualization_service:service_manager find;
108 allow crosvm virtualizationservice:binder { call transfer };
Mu-Le Leec7177f72024-04-17 08:38:47 +0800109
110 # Allow crosvm to play sound.
111 binder_call(crosvm, audioserver)
112 allow crosvm audioserver_service:service_manager find;
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900113')
114
Steven Morelandfd59a2d2022-04-04 20:20:24 +0000115# crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254)
116dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl;
117
Jiyong Park2eab15e2022-05-02 13:23:50 +0900118# crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by
119# compliance tests and demo apps. Write access to instance.img is particularily important because
120# the VM has to initialize the disk image on its first boot. Note that open access is still not
121# granted because the files are expected to be opened by the owner of the VM (apps or shell in case
122# when the vm is created by the `vm` tool) and handed over to crosvm as FD.
123allow crosvm shell_data_file:file write;
Jiyong Park3fee5a42021-08-09 09:24:45 +0900124
Inseob Kim42798af2023-01-13 14:08:16 +0900125# crosvm tries to read serial device, including the write-only pipe from virtualizationmanager (to
126# forward console/log to the host logcat).
127# crosvm only needs write permission, so dontaudit read
Inseob Kimbbe514d2023-08-03 12:53:48 +0900128dontaudit crosvm virtualizationmanager:fifo_file { read getattr };
Inseob Kim42798af2023-01-13 14:08:16 +0900129
Nikita Ioffe40a48c12023-02-14 23:17:55 +0000130# Required for crosvm to start gdb-server to enable debugging of guest kernel.
131allow crosvm self:tcp_socket { bind create read setopt write accept listen };
132allow crosvm port:tcp_socket name_bind;
133allow crosvm adbd:unix_stream_socket ioctl;
134allow crosvm node:tcp_socket node_bind;
135
Inseob Kim825056d2023-08-01 11:00:49 +0900136# Allow crosvm to interact to VFIO device
137allow crosvm vfio_device:chr_file rw_file_perms;
138allow crosvm vfio_device:dir r_dir_perms;
139
Inseob Kimbbe514d2023-08-03 12:53:48 +0900140# Allow crosvm to access VM DTBO via a file created by virtualizationmanager.
141allow crosvm virtualizationmanager:fd use;
142allow crosvm virtualizationservice_data_file:file read;
Inseob Kim825056d2023-08-01 11:00:49 +0900143
Seungjae Yoo12fd4822024-05-28 14:12:52 +0900144is_flag_enabled(RELEASE_AVF_ENABLE_NETWORK, `
145 # Allow crosvm to deal with file descriptors of TAP interfaces.
146 allow crosvm tun_device:chr_file rw_file_perms;
Seungjae Yoofcecae72024-06-14 15:27:05 +0900147 allowxperm crosvm tun_device:chr_file ioctl { TUNGETIFF TUNSETOFFLOAD TUNSETVNETHDRSZ };
Seungjae Yoo12fd4822024-05-28 14:12:52 +0900148 allow crosvm self:udp_socket create_socket_perms;
149 allowxperm crosvm self:udp_socket ioctl SIOCGIFMTU;
150 allow crosvm vmnic:fd use;
151')
152
Alan Stokes30608522022-10-24 12:32:34 +0100153# Don't allow crosvm to open files that it doesn't own.
154# This is important because a malicious application could try to start a VM with a composite disk
155# image referring by name to files which it doesn't have permission to open, trying to get crosvm to
156# open them on its behalf. By preventing crosvm from opening any other files we prevent this
157# potential privilege escalation. See http://b/192453819 for more discussion.
158neverallow crosvm {
159 virtualizationservice_data_file
160 staging_data_file
161 apk_data_file
162 app_data_file
163 privapp_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000164 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900165 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Alan Stokes30608522022-10-24 12:32:34 +0100166 userdebug_or_eng(`-shell_data_file')
167}:file open;
168
Jiyong Park3fee5a42021-08-09 09:24:45 +0900169# Don't allow crosvm to have access to ordinary vendor files that are not for VMs.
170full_treble_only(`
171 neverallow crosvm {
172 vendor_file_type
173 -vendor_vm_file
174 -vendor_vm_data_file
175 # These types are not required for crosvm, but the access is granted to globally in domain.te
176 # thus should be exempted here.
177 -vendor_configs_file
Seungjae Yood2a08922023-11-15 17:59:30 +0900178 -vendor_microdroid_file
Jiyong Park3fee5a42021-08-09 09:24:45 +0900179 -vndk_sp_file
180 -vendor_task_profiles_file
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900181 is_flag_enabled(RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES, `-same_process_hal_file')
Jiyong Park3fee5a42021-08-09 09:24:45 +0900182 }:file *;
183')
Jiyong Park028e7222021-11-26 00:59:07 +0900184
Alan Stokes30608522022-10-24 12:32:34 +0100185# Only allow crosvm to read app data files for clients that can start
186# VMs. Note that the use of app data files is further restricted
187# inside the virtualizationservice by checking the label of all disk
188# image files.
Jiyong Park028e7222021-11-26 00:59:07 +0900189neverallow crosvm {
190 app_data_file_type
191 -app_data_file
Alan Stokes30608522022-10-24 12:32:34 +0100192 -privapp_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +0900193 -shell_data_file
Jiyong Park028e7222021-11-26 00:59:07 +0900194}:file read;
Inseob Kimb20cb782022-02-03 15:30:26 +0900195
David Brazdil55d808c2022-12-15 13:38:42 +0000196# Only virtualizationmanager can run crosvm
Inseob Kimb20cb782022-02-03 15:30:26 +0900197neverallow {
198 domain
199 -crosvm
David Brazdil55d808c2022-12-15 13:38:42 +0000200 -virtualizationmanager
Alice Wang23b712e2024-08-01 08:29:31 +0000201 # TODO(b/357025924): This is a temporary workaround to allow the KeyMint VM to use crosvm
202 # directly. It should be removed once the KeyMint VM can be started with early_virtmgr
203 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `-init')
Inseob Kimb20cb782022-02-03 15:30:26 +0900204} crosvm_exec:file no_x_file_perms;