blob: 11c70adabd3b07d013ecfe607000ba6b7dc61d54 [file] [log] [blame]
Inseob Kimf4769702024-12-16 20:11:37 +09001until_board_api(202504, `
2 type crosvm, domain, coredomain;
3')
4
Andrew Walbrana995e842021-03-29 17:19:12 +00005type crosvm_exec, system_file_type, exec_type, file_type;
6type crosvm_tmpfs, file_type;
7
Elliot Bermanae5869a2023-03-22 17:31:35 -07008# Let crosvm open VM manager devices such as /dev/kvm.
9allow crosvm vm_manager_device_type:chr_file rw_file_perms;
Andrew Walbrana995e842021-03-29 17:19:12 +000010
11# Most other domains shouldn't access /dev/kvm.
12neverallow { domain -crosvm -ueventd -shell } kvm_device:chr_file getattr;
Andrew Walbran2f27f962022-01-28 15:42:48 +000013neverallow { domain -crosvm -ueventd } kvm_device:chr_file ~getattr;
Jiyong Park2dd48d02021-12-28 21:26:03 +090014neverallowxperm { domain -crosvm } kvm_device:chr_file ioctl ~{ KVM_CHECK_EXTENSION };
Andrew Walbran9b2fa1b2021-07-01 15:58:26 +000015
Elliot Bermanae5869a2023-03-22 17:31:35 -070016# Most other domains shouldn't access other vm managers either.
17# These restrictions need to be slightly looser than for kvm_device to allow
18# for different implementations.
19neverallow { coredomain appdomain -crosvm -ueventd -shell } vm_manager_device_type:chr_file getattr;
20neverallow { coredomain appdomain -crosvm -ueventd } vm_manager_device_type:chr_file ~getattr;
21
Jiyong Park5e20d832021-07-12 21:11:33 +090022# Let crosvm create temporary files.
23tmpfs_domain(crosvm)
24
25# Let crosvm receive file descriptors from VirtualizationService.
Inseob Kim41fe7ea2024-09-03 10:59:07 +090026allow crosvm {
27 virtualizationmanager
28 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
29}:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090030
Inseob Kim42798af2023-01-13 14:08:16 +090031# Allow sending VirtualizationService the failure reason and console/log from the VM via pipe.
Inseob Kim41fe7ea2024-09-03 10:59:07 +090032allow crosvm {
33 virtualizationmanager
34 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
35}:fifo_file write;
Alan Stokesb02ac322022-03-09 14:05:18 +000036
Jiyong Park5e20d832021-07-12 21:11:33 +090037# Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes
38# (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 +090039# /data/local/tmp), instance.img (app_data_file), and microdroid vendor image (vendor_microdroid_file).
Alice Wang40519f72023-08-31 11:37:30 +000040# Allow crosvm to read the instance image of the service VM saved in apex_virt_data_file.
41# Note that the open permission is not given as the files are passed as file descriptors.
Jiyong Park5e20d832021-07-12 21:11:33 +090042allow crosvm {
43 virtualizationservice_data_file
44 staging_data_file
45 apk_data_file
46 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010047 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010048 apex_compos_data_file
Alice Wang40519f72023-08-31 11:37:30 +000049 apex_virt_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +090050 shell_data_file
Seungjae Yood2a08922023-11-15 17:59:30 +090051 vendor_microdroid_file
Inseob Kim0b9625d2024-07-31 17:42:23 +090052 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Jiyong Park5e20d832021-07-12 21:11:33 +090053}:file { getattr read ioctl lock };
54
55# Allow searching the directory where the composite disk images are.
Inseob Kim0b9625d2024-07-31 17:42:23 +090056allow crosvm {
57 virtualizationservice_data_file
58 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
59}:dir search;
Jiyong Park5e20d832021-07-12 21:11:33 +090060
Alan Stokesaeab04f2024-02-01 16:16:01 +000061# When running a VM as root we get spurious capability denials.
62# Suppress them.
63userdebug_or_eng(`
64 dontaudit crosvm self:capability ipc_lock;
65')
66
David Dai7066a962024-02-01 15:19:03 -080067# Allow crosvm to tune for performance.
68allow crosvm self:global_capability_class_set sys_nice;
69
Keir Fraserad58b8d2022-07-11 14:27:40 +000070# Let crosvm access its control socket as created by VS.
71# read, write, getattr: listener socket polling
72# accept: listener socket accepting new connection
73# Note that the open permission is not given as the socket is passed by FD.
Inseob Kim41fe7ea2024-09-03 10:59:07 +090074allow crosvm {
75 virtualizationmanager
76 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
77}:unix_stream_socket { accept read write getattr getopt };
Keir Fraserad58b8d2022-07-11 14:27:40 +000078
Jaewan Kim7b843d42022-12-07 16:18:18 +090079# Let crosvm open test artifacts under /data/local/tmp with file path. (e.g. custom pvmfw.img)
80userdebug_or_eng(`
81 allow crosvm shell_data_file:dir search;
82 allow crosvm shell_data_file:file open;
83')
84
Jiyong Park5e20d832021-07-12 21:11:33 +090085# The instance image and the composite image should be writable as well because they could represent
86# mutable disks.
87allow crosvm {
88 virtualizationservice_data_file
89 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010090 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010091 apex_compos_data_file
Alice Wang40519f72023-08-31 11:37:30 +000092 apex_virt_data_file
Inseob Kim0b9625d2024-07-31 17:42:23 +090093 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Jiyong Park5e20d832021-07-12 21:11:33 +090094}:file write;
95
96# 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 +010097allow crosvm adbd:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090098allow crosvm adbd:unix_stream_socket { read write };
Alan Stokes6d019be2023-06-08 13:13:08 +010099allow crosvm devpts:chr_file { read write getattr ioctl };
Jiyong Park5e20d832021-07-12 21:11:33 +0900100
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900101is_flag_enabled(RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES, `
102 # Allow crosvm to draw screen in the surface
103 allow crosvm device:dir { read open };
104 allow crosvm same_process_hal_file:file { read open getattr map execute };
105 allow crosvm gpu_device:chr_file { read write open ioctl map open getattr };
106 allow crosvm hal_graphics_allocator:fd use;
107 allow crosvm hal_graphics_allocator_server:binder call;
108 allow crosvm surfaceflinger:fd use;
109 hal_client_domain(crosvm, hal_graphics_allocator)
110
111 # To provide display service to an app to get surface.
Jiyong Park7ebed472025-03-01 10:24:56 -0800112 # TODO(b/332677707): remove them when display service uses binder RPC.
113 allow crosvm vmlauncher_app:binder { transfer call };
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900114 allow crosvm servicemanager:binder { call transfer };
115 allow crosvm virtualization_service:service_manager find;
116 allow crosvm virtualizationservice:binder { call transfer };
Mu-Le Leec7177f72024-04-17 08:38:47 +0800117
118 # Allow crosvm to play sound.
119 binder_call(crosvm, audioserver)
120 allow crosvm audioserver_service:service_manager find;
Akilesh Kailash872e66d2024-10-28 21:58:46 -0700121
122 # Allow crosvm to mount fuse path in guest VM through virtiofs
123 allow crosvm fuse:file create_file_perms;
124 allow crosvm fuse:dir create_dir_perms;
125 allow crosvm mnt_user_file:dir search;
126
127 # Allow crosvm to create unix socket for vhost-user-fs
128 allow crosvm virtualizationservice_data_file:dir { add_name write remove_name };
129 allow crosvm virtualizationservice_data_file:sock_file { create write unlink };
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900130')
131
Steven Morelandfd59a2d2022-04-04 20:20:24 +0000132# crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254)
133dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl;
134
Jiyong Park2eab15e2022-05-02 13:23:50 +0900135# crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by
136# compliance tests and demo apps. Write access to instance.img is particularily important because
137# the VM has to initialize the disk image on its first boot. Note that open access is still not
138# granted because the files are expected to be opened by the owner of the VM (apps or shell in case
139# when the vm is created by the `vm` tool) and handed over to crosvm as FD.
140allow crosvm shell_data_file:file write;
Jiyong Park3fee5a42021-08-09 09:24:45 +0900141
Inseob Kim42798af2023-01-13 14:08:16 +0900142# crosvm tries to read serial device, including the write-only pipe from virtualizationmanager (to
143# forward console/log to the host logcat).
144# crosvm only needs write permission, so dontaudit read
Inseob Kim41fe7ea2024-09-03 10:59:07 +0900145dontaudit crosvm {
146 virtualizationmanager
147 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
148}:fifo_file { read getattr };
Inseob Kim42798af2023-01-13 14:08:16 +0900149
Nikita Ioffe40a48c12023-02-14 23:17:55 +0000150# Required for crosvm to start gdb-server to enable debugging of guest kernel.
151allow crosvm self:tcp_socket { bind create read setopt write accept listen };
152allow crosvm port:tcp_socket name_bind;
153allow crosvm adbd:unix_stream_socket ioctl;
154allow crosvm node:tcp_socket node_bind;
155
Inseob Kim825056d2023-08-01 11:00:49 +0900156# Allow crosvm to interact to VFIO device
157allow crosvm vfio_device:chr_file rw_file_perms;
158allow crosvm vfio_device:dir r_dir_perms;
159
Inseob Kimbbe514d2023-08-03 12:53:48 +0900160# Allow crosvm to access VM DTBO via a file created by virtualizationmanager.
Inseob Kimbbe514d2023-08-03 12:53:48 +0900161allow crosvm virtualizationservice_data_file:file read;
Inseob Kim825056d2023-08-01 11:00:49 +0900162
Seungjae Yoo12fd4822024-05-28 14:12:52 +0900163is_flag_enabled(RELEASE_AVF_ENABLE_NETWORK, `
164 # Allow crosvm to deal with file descriptors of TAP interfaces.
165 allow crosvm tun_device:chr_file rw_file_perms;
Seungjae Yoofcecae72024-06-14 15:27:05 +0900166 allowxperm crosvm tun_device:chr_file ioctl { TUNGETIFF TUNSETOFFLOAD TUNSETVNETHDRSZ };
Seungjae Yoo12fd4822024-05-28 14:12:52 +0900167 allow crosvm self:udp_socket create_socket_perms;
168 allowxperm crosvm self:udp_socket ioctl SIOCGIFMTU;
169 allow crosvm vmnic:fd use;
170')
171
Inseob Kim41fe7ea2024-09-03 10:59:07 +0900172# Early VMs may print messages to kmsg_debug_device.
173allow crosvm kmsg_debug_device:chr_file w_file_perms;
174
Inseob Kime398f7f2025-03-04 16:26:28 +0900175# Allow crosvm to read /data/nativetest for VTS
176r_dir_file(crosvm, nativetest_data_file)
177
Alan Stokes30608522022-10-24 12:32:34 +0100178# Don't allow crosvm to open files that it doesn't own.
179# This is important because a malicious application could try to start a VM with a composite disk
180# image referring by name to files which it doesn't have permission to open, trying to get crosvm to
181# open them on its behalf. By preventing crosvm from opening any other files we prevent this
182# potential privilege escalation. See http://b/192453819 for more discussion.
183neverallow crosvm {
184 virtualizationservice_data_file
185 staging_data_file
186 apk_data_file
187 app_data_file
Akilesh Kailashe7cd0eb2024-11-30 08:10:11 -0800188 privapp_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000189 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900190 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Alan Stokes30608522022-10-24 12:32:34 +0100191 userdebug_or_eng(`-shell_data_file')
192}:file open;
193
Jiyong Park3fee5a42021-08-09 09:24:45 +0900194# Don't allow crosvm to have access to ordinary vendor files that are not for VMs.
195full_treble_only(`
196 neverallow crosvm {
197 vendor_file_type
198 -vendor_vm_file
199 -vendor_vm_data_file
200 # These types are not required for crosvm, but the access is granted to globally in domain.te
201 # thus should be exempted here.
T.J. Mercier852d19b2024-10-14 16:56:12 +0000202 -vendor_cgroup_desc_file
Jiyong Park3fee5a42021-08-09 09:24:45 +0900203 -vendor_configs_file
Seungjae Yood2a08922023-11-15 17:59:30 +0900204 -vendor_microdroid_file
Jiyong Park3fee5a42021-08-09 09:24:45 +0900205 -vndk_sp_file
206 -vendor_task_profiles_file
Todd Frederick6d3126d2024-10-22 15:13:47 +0000207 -same_process_hal_file
Jiyong Park3fee5a42021-08-09 09:24:45 +0900208 }:file *;
209')
Jiyong Park028e7222021-11-26 00:59:07 +0900210
Alan Stokes30608522022-10-24 12:32:34 +0100211# Only allow crosvm to read app data files for clients that can start
212# VMs. Note that the use of app data files is further restricted
213# inside the virtualizationservice by checking the label of all disk
214# image files.
Jiyong Park028e7222021-11-26 00:59:07 +0900215neverallow crosvm {
216 app_data_file_type
217 -app_data_file
Alan Stokes30608522022-10-24 12:32:34 +0100218 -privapp_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +0900219 -shell_data_file
Jiyong Park028e7222021-11-26 00:59:07 +0900220}:file read;
Inseob Kimb20cb782022-02-03 15:30:26 +0900221
David Brazdil55d808c2022-12-15 13:38:42 +0000222# Only virtualizationmanager can run crosvm
Jiyong Park7ebed472025-03-01 10:24:56 -0800223# Allow vmlauncher app to launch crosvm for virtiofs
Inseob Kimb20cb782022-02-03 15:30:26 +0900224neverallow {
225 domain
226 -crosvm
David Brazdil55d808c2022-12-15 13:38:42 +0000227 -virtualizationmanager
Jiyong Park7ebed472025-03-01 10:24:56 -0800228 -vmlauncher_app
Paul Lawrence840b6072025-01-28 07:41:05 -0800229 userdebug_or_eng(`-overlay_remounter')
Inseob Kim41fe7ea2024-09-03 10:59:07 +0900230
231 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `-early_virtmgr')
Inseob Kimb20cb782022-02-03 15:30:26 +0900232} crosvm_exec:file no_x_file_perms;