blob: 0aab5416bc77ee4a924b8339887061384160402d [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
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
Elliot Bermanae5869a2023-03-22 17:31:35 -070013# Most other domains shouldn't access other vm managers either.
14# These restrictions need to be slightly looser than for kvm_device to allow
15# for different implementations.
16neverallow { coredomain appdomain -crosvm -ueventd -shell } vm_manager_device_type:chr_file getattr;
17neverallow { coredomain appdomain -crosvm -ueventd } vm_manager_device_type:chr_file ~getattr;
18
Jiyong Park5e20d832021-07-12 21:11:33 +090019# Let crosvm create temporary files.
20tmpfs_domain(crosvm)
21
22# Let crosvm receive file descriptors from VirtualizationService.
Inseob Kim41fe7ea2024-09-03 10:59:07 +090023allow crosvm {
24 virtualizationmanager
25 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
26}:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090027
Inseob Kim42798af2023-01-13 14:08:16 +090028# Allow sending VirtualizationService the failure reason and console/log from the VM via pipe.
Inseob Kim41fe7ea2024-09-03 10:59:07 +090029allow crosvm {
30 virtualizationmanager
31 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
32}:fifo_file write;
Alan Stokesb02ac322022-03-09 14:05:18 +000033
Jiyong Park5e20d832021-07-12 21:11:33 +090034# Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes
35# (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 +090036# /data/local/tmp), instance.img (app_data_file), and microdroid vendor image (vendor_microdroid_file).
Alice Wang40519f72023-08-31 11:37:30 +000037# Allow crosvm to read the instance image of the service VM saved in apex_virt_data_file.
38# Note that the open permission is not given as the files are passed as file descriptors.
Jiyong Park5e20d832021-07-12 21:11:33 +090039allow crosvm {
40 virtualizationservice_data_file
41 staging_data_file
42 apk_data_file
43 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010044 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010045 apex_compos_data_file
Alice Wang40519f72023-08-31 11:37:30 +000046 apex_virt_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +090047 shell_data_file
Seungjae Yood2a08922023-11-15 17:59:30 +090048 vendor_microdroid_file
Inseob Kim0b9625d2024-07-31 17:42:23 +090049 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Jiyong Park5e20d832021-07-12 21:11:33 +090050}:file { getattr read ioctl lock };
51
52# Allow searching the directory where the composite disk images are.
Inseob Kim0b9625d2024-07-31 17:42:23 +090053allow crosvm {
54 virtualizationservice_data_file
55 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
56}:dir search;
Jiyong Park5e20d832021-07-12 21:11:33 +090057
Alan Stokesaeab04f2024-02-01 16:16:01 +000058# When running a VM as root we get spurious capability denials.
59# Suppress them.
60userdebug_or_eng(`
61 dontaudit crosvm self:capability ipc_lock;
62')
63
David Dai7066a962024-02-01 15:19:03 -080064# Allow crosvm to tune for performance.
65allow crosvm self:global_capability_class_set sys_nice;
66
Keir Fraserad58b8d2022-07-11 14:27:40 +000067# Let crosvm access its control socket as created by VS.
68# read, write, getattr: listener socket polling
69# accept: listener socket accepting new connection
70# Note that the open permission is not given as the socket is passed by FD.
Inseob Kim41fe7ea2024-09-03 10:59:07 +090071allow crosvm {
72 virtualizationmanager
73 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
74}:unix_stream_socket { accept read write getattr getopt };
Keir Fraserad58b8d2022-07-11 14:27:40 +000075
Jaewan Kim7b843d42022-12-07 16:18:18 +090076# Let crosvm open test artifacts under /data/local/tmp with file path. (e.g. custom pvmfw.img)
77userdebug_or_eng(`
78 allow crosvm shell_data_file:dir search;
79 allow crosvm shell_data_file:file open;
80')
81
Jiyong Park5e20d832021-07-12 21:11:33 +090082# The instance image and the composite image should be writable as well because they could represent
83# mutable disks.
84allow crosvm {
85 virtualizationservice_data_file
86 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010087 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010088 apex_compos_data_file
Alice Wang40519f72023-08-31 11:37:30 +000089 apex_virt_data_file
Inseob Kim0b9625d2024-07-31 17:42:23 +090090 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Jiyong Park5e20d832021-07-12 21:11:33 +090091}:file write;
92
93# 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 +010094allow crosvm adbd:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090095allow crosvm adbd:unix_stream_socket { read write };
Alan Stokes6d019be2023-06-08 13:13:08 +010096allow crosvm devpts:chr_file { read write getattr ioctl };
Jiyong Park5e20d832021-07-12 21:11:33 +090097
Jeongik Chaf09f43c2024-04-02 14:50:14 +090098is_flag_enabled(RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES, `
99 # Allow crosvm to draw screen in the surface
100 allow crosvm device:dir { read open };
101 allow crosvm same_process_hal_file:file { read open getattr map execute };
102 allow crosvm gpu_device:chr_file { read write open ioctl map open getattr };
103 allow crosvm hal_graphics_allocator:fd use;
104 allow crosvm hal_graphics_allocator_server:binder call;
105 allow crosvm surfaceflinger:fd use;
106 hal_client_domain(crosvm, hal_graphics_allocator)
107
108 # To provide display service to an app to get surface.
109 # TODO(b/332677707): remove them when display service uses binder RPC.
Jeongik Cha77a3ca62024-04-09 15:02:28 +0900110 allow crosvm vmlauncher_app:binder { transfer call };
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900111 allow crosvm servicemanager:binder { call transfer };
112 allow crosvm virtualization_service:service_manager find;
113 allow crosvm virtualizationservice:binder { call transfer };
Mu-Le Leec7177f72024-04-17 08:38:47 +0800114
115 # Allow crosvm to play sound.
116 binder_call(crosvm, audioserver)
117 allow crosvm audioserver_service:service_manager find;
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900118')
119
Steven Morelandfd59a2d2022-04-04 20:20:24 +0000120# crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254)
121dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl;
122
Jiyong Park2eab15e2022-05-02 13:23:50 +0900123# crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by
124# compliance tests and demo apps. Write access to instance.img is particularily important because
125# the VM has to initialize the disk image on its first boot. Note that open access is still not
126# granted because the files are expected to be opened by the owner of the VM (apps or shell in case
127# when the vm is created by the `vm` tool) and handed over to crosvm as FD.
128allow crosvm shell_data_file:file write;
Jiyong Park3fee5a42021-08-09 09:24:45 +0900129
Inseob Kim42798af2023-01-13 14:08:16 +0900130# crosvm tries to read serial device, including the write-only pipe from virtualizationmanager (to
131# forward console/log to the host logcat).
132# crosvm only needs write permission, so dontaudit read
Inseob Kim41fe7ea2024-09-03 10:59:07 +0900133dontaudit crosvm {
134 virtualizationmanager
135 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr')
136}:fifo_file { read getattr };
Inseob Kim42798af2023-01-13 14:08:16 +0900137
Nikita Ioffe40a48c12023-02-14 23:17:55 +0000138# Required for crosvm to start gdb-server to enable debugging of guest kernel.
139allow crosvm self:tcp_socket { bind create read setopt write accept listen };
140allow crosvm port:tcp_socket name_bind;
141allow crosvm adbd:unix_stream_socket ioctl;
142allow crosvm node:tcp_socket node_bind;
143
Inseob Kim825056d2023-08-01 11:00:49 +0900144# Allow crosvm to interact to VFIO device
145allow crosvm vfio_device:chr_file rw_file_perms;
146allow crosvm vfio_device:dir r_dir_perms;
147
Inseob Kimbbe514d2023-08-03 12:53:48 +0900148# Allow crosvm to access VM DTBO via a file created by virtualizationmanager.
Inseob Kimbbe514d2023-08-03 12:53:48 +0900149allow crosvm virtualizationservice_data_file:file read;
Inseob Kim825056d2023-08-01 11:00:49 +0900150
Seungjae Yoo12fd4822024-05-28 14:12:52 +0900151is_flag_enabled(RELEASE_AVF_ENABLE_NETWORK, `
152 # Allow crosvm to deal with file descriptors of TAP interfaces.
153 allow crosvm tun_device:chr_file rw_file_perms;
Seungjae Yoofcecae72024-06-14 15:27:05 +0900154 allowxperm crosvm tun_device:chr_file ioctl { TUNGETIFF TUNSETOFFLOAD TUNSETVNETHDRSZ };
Seungjae Yoo12fd4822024-05-28 14:12:52 +0900155 allow crosvm self:udp_socket create_socket_perms;
156 allowxperm crosvm self:udp_socket ioctl SIOCGIFMTU;
157 allow crosvm vmnic:fd use;
158')
159
Inseob Kim41fe7ea2024-09-03 10:59:07 +0900160# Early VMs may print messages to kmsg_debug_device.
161allow crosvm kmsg_debug_device:chr_file w_file_perms;
162
Alan Stokes30608522022-10-24 12:32:34 +0100163# Don't allow crosvm to open files that it doesn't own.
164# This is important because a malicious application could try to start a VM with a composite disk
165# image referring by name to files which it doesn't have permission to open, trying to get crosvm to
166# open them on its behalf. By preventing crosvm from opening any other files we prevent this
167# potential privilege escalation. See http://b/192453819 for more discussion.
168neverallow crosvm {
169 virtualizationservice_data_file
170 staging_data_file
171 apk_data_file
172 app_data_file
173 privapp_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000174 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900175 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file')
Alan Stokes30608522022-10-24 12:32:34 +0100176 userdebug_or_eng(`-shell_data_file')
177}:file open;
178
Jiyong Park3fee5a42021-08-09 09:24:45 +0900179# Don't allow crosvm to have access to ordinary vendor files that are not for VMs.
180full_treble_only(`
181 neverallow crosvm {
182 vendor_file_type
183 -vendor_vm_file
184 -vendor_vm_data_file
185 # These types are not required for crosvm, but the access is granted to globally in domain.te
186 # thus should be exempted here.
187 -vendor_configs_file
Seungjae Yood2a08922023-11-15 17:59:30 +0900188 -vendor_microdroid_file
Jiyong Park3fee5a42021-08-09 09:24:45 +0900189 -vndk_sp_file
190 -vendor_task_profiles_file
Todd Frederick6d3126d2024-10-22 15:13:47 +0000191 -same_process_hal_file
Jiyong Park3fee5a42021-08-09 09:24:45 +0900192 }:file *;
193')
Jiyong Park028e7222021-11-26 00:59:07 +0900194
Alan Stokes30608522022-10-24 12:32:34 +0100195# Only allow crosvm to read app data files for clients that can start
196# VMs. Note that the use of app data files is further restricted
197# inside the virtualizationservice by checking the label of all disk
198# image files.
Jiyong Park028e7222021-11-26 00:59:07 +0900199neverallow crosvm {
200 app_data_file_type
201 -app_data_file
Alan Stokes30608522022-10-24 12:32:34 +0100202 -privapp_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +0900203 -shell_data_file
Jiyong Park028e7222021-11-26 00:59:07 +0900204}:file read;
Inseob Kimb20cb782022-02-03 15:30:26 +0900205
David Brazdil55d808c2022-12-15 13:38:42 +0000206# Only virtualizationmanager can run crosvm
Inseob Kimb20cb782022-02-03 15:30:26 +0900207neverallow {
208 domain
209 -crosvm
David Brazdil55d808c2022-12-15 13:38:42 +0000210 -virtualizationmanager
Inseob Kim41fe7ea2024-09-03 10:59:07 +0900211
212 is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `-early_virtmgr')
Inseob Kimb20cb782022-02-03 15:30:26 +0900213} crosvm_exec:file no_x_file_perms;