Inseob Kim | f476970 | 2024-12-16 20:11:37 +0900 | [diff] [blame] | 1 | until_board_api(202504, ` |
| 2 | type crosvm, domain, coredomain; |
| 3 | ') |
| 4 | |
Andrew Walbran | a995e84 | 2021-03-29 17:19:12 +0000 | [diff] [blame] | 5 | type crosvm_exec, system_file_type, exec_type, file_type; |
| 6 | type crosvm_tmpfs, file_type; |
| 7 | |
Elliot Berman | ae5869a | 2023-03-22 17:31:35 -0700 | [diff] [blame] | 8 | # Let crosvm open VM manager devices such as /dev/kvm. |
| 9 | allow crosvm vm_manager_device_type:chr_file rw_file_perms; |
Andrew Walbran | a995e84 | 2021-03-29 17:19:12 +0000 | [diff] [blame] | 10 | |
| 11 | # Most other domains shouldn't access /dev/kvm. |
| 12 | neverallow { domain -crosvm -ueventd -shell } kvm_device:chr_file getattr; |
Andrew Walbran | 2f27f96 | 2022-01-28 15:42:48 +0000 | [diff] [blame] | 13 | neverallow { domain -crosvm -ueventd } kvm_device:chr_file ~getattr; |
Jiyong Park | 2dd48d0 | 2021-12-28 21:26:03 +0900 | [diff] [blame] | 14 | neverallowxperm { domain -crosvm } kvm_device:chr_file ioctl ~{ KVM_CHECK_EXTENSION }; |
Andrew Walbran | 9b2fa1b | 2021-07-01 15:58:26 +0000 | [diff] [blame] | 15 | |
Elliot Berman | ae5869a | 2023-03-22 17:31:35 -0700 | [diff] [blame] | 16 | # 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. |
| 19 | neverallow { coredomain appdomain -crosvm -ueventd -shell } vm_manager_device_type:chr_file getattr; |
| 20 | neverallow { coredomain appdomain -crosvm -ueventd } vm_manager_device_type:chr_file ~getattr; |
| 21 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 22 | # Let crosvm create temporary files. |
| 23 | tmpfs_domain(crosvm) |
| 24 | |
| 25 | # Let crosvm receive file descriptors from VirtualizationService. |
Inseob Kim | 41fe7ea | 2024-09-03 10:59:07 +0900 | [diff] [blame] | 26 | allow crosvm { |
| 27 | virtualizationmanager |
| 28 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr') |
| 29 | }:fd use; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 30 | |
Inseob Kim | 42798af | 2023-01-13 14:08:16 +0900 | [diff] [blame] | 31 | # Allow sending VirtualizationService the failure reason and console/log from the VM via pipe. |
Inseob Kim | 41fe7ea | 2024-09-03 10:59:07 +0900 | [diff] [blame] | 32 | allow crosvm { |
| 33 | virtualizationmanager |
| 34 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr') |
| 35 | }:fifo_file write; |
Alan Stokes | b02ac32 | 2022-03-09 14:05:18 +0000 | [diff] [blame] | 36 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 37 | # 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 Yoo | d2a0892 | 2023-11-15 17:59:30 +0900 | [diff] [blame] | 39 | # /data/local/tmp), instance.img (app_data_file), and microdroid vendor image (vendor_microdroid_file). |
Alice Wang | 40519f7 | 2023-08-31 11:37:30 +0000 | [diff] [blame] | 40 | # 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 Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 42 | allow crosvm { |
| 43 | virtualizationservice_data_file |
| 44 | staging_data_file |
| 45 | apk_data_file |
| 46 | app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 47 | privapp_data_file |
Alan Stokes | e2a002c | 2021-07-28 14:05:25 +0100 | [diff] [blame] | 48 | apex_compos_data_file |
Alice Wang | 40519f7 | 2023-08-31 11:37:30 +0000 | [diff] [blame] | 49 | apex_virt_data_file |
Jiyong Park | cdd5e07 | 2022-04-19 11:48:32 +0900 | [diff] [blame] | 50 | shell_data_file |
Seungjae Yoo | d2a0892 | 2023-11-15 17:59:30 +0900 | [diff] [blame] | 51 | vendor_microdroid_file |
Inseob Kim | 0b9625d | 2024-07-31 17:42:23 +0900 | [diff] [blame] | 52 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file') |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 53 | }:file { getattr read ioctl lock }; |
| 54 | |
| 55 | # Allow searching the directory where the composite disk images are. |
Inseob Kim | 0b9625d | 2024-07-31 17:42:23 +0900 | [diff] [blame] | 56 | allow crosvm { |
| 57 | virtualizationservice_data_file |
| 58 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file') |
| 59 | }:dir search; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 60 | |
Alan Stokes | aeab04f | 2024-02-01 16:16:01 +0000 | [diff] [blame] | 61 | # When running a VM as root we get spurious capability denials. |
| 62 | # Suppress them. |
| 63 | userdebug_or_eng(` |
| 64 | dontaudit crosvm self:capability ipc_lock; |
| 65 | ') |
| 66 | |
David Dai | 7066a96 | 2024-02-01 15:19:03 -0800 | [diff] [blame] | 67 | # Allow crosvm to tune for performance. |
| 68 | allow crosvm self:global_capability_class_set sys_nice; |
| 69 | |
Keir Fraser | ad58b8d | 2022-07-11 14:27:40 +0000 | [diff] [blame] | 70 | # 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 Kim | 41fe7ea | 2024-09-03 10:59:07 +0900 | [diff] [blame] | 74 | allow crosvm { |
| 75 | virtualizationmanager |
| 76 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr') |
| 77 | }:unix_stream_socket { accept read write getattr getopt }; |
Keir Fraser | ad58b8d | 2022-07-11 14:27:40 +0000 | [diff] [blame] | 78 | |
Jaewan Kim | 7b843d4 | 2022-12-07 16:18:18 +0900 | [diff] [blame] | 79 | # Let crosvm open test artifacts under /data/local/tmp with file path. (e.g. custom pvmfw.img) |
| 80 | userdebug_or_eng(` |
| 81 | allow crosvm shell_data_file:dir search; |
| 82 | allow crosvm shell_data_file:file open; |
| 83 | ') |
| 84 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 85 | # The instance image and the composite image should be writable as well because they could represent |
| 86 | # mutable disks. |
| 87 | allow crosvm { |
| 88 | virtualizationservice_data_file |
| 89 | app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 90 | privapp_data_file |
Alan Stokes | e2a002c | 2021-07-28 14:05:25 +0100 | [diff] [blame] | 91 | apex_compos_data_file |
Alice Wang | 40519f7 | 2023-08-31 11:37:30 +0000 | [diff] [blame] | 92 | apex_virt_data_file |
Inseob Kim | 0b9625d | 2024-07-31 17:42:23 +0900 | [diff] [blame] | 93 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file') |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 94 | }:file write; |
| 95 | |
| 96 | # Allow crosvm to pipe console log to shell or app which could be the owner of a VM. |
Alan Stokes | 39f4970 | 2021-09-02 11:10:59 +0100 | [diff] [blame] | 97 | allow crosvm adbd:fd use; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 98 | allow crosvm adbd:unix_stream_socket { read write }; |
Alan Stokes | 6d019be | 2023-06-08 13:13:08 +0100 | [diff] [blame] | 99 | allow crosvm devpts:chr_file { read write getattr ioctl }; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 100 | |
Jeongik Cha | f09f43c | 2024-04-02 14:50:14 +0900 | [diff] [blame] | 101 | is_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 Park | 7ebed47 | 2025-03-01 10:24:56 -0800 | [diff] [blame] | 112 | # TODO(b/332677707): remove them when display service uses binder RPC. |
| 113 | allow crosvm vmlauncher_app:binder { transfer call }; |
Jeongik Cha | f09f43c | 2024-04-02 14:50:14 +0900 | [diff] [blame] | 114 | allow crosvm servicemanager:binder { call transfer }; |
| 115 | allow crosvm virtualization_service:service_manager find; |
| 116 | allow crosvm virtualizationservice:binder { call transfer }; |
Mu-Le Lee | c7177f7 | 2024-04-17 08:38:47 +0800 | [diff] [blame] | 117 | |
| 118 | # Allow crosvm to play sound. |
| 119 | binder_call(crosvm, audioserver) |
| 120 | allow crosvm audioserver_service:service_manager find; |
Akilesh Kailash | 872e66d | 2024-10-28 21:58:46 -0700 | [diff] [blame] | 121 | |
| 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 Cha | f09f43c | 2024-04-02 14:50:14 +0900 | [diff] [blame] | 130 | ') |
| 131 | |
Steven Moreland | fd59a2d | 2022-04-04 20:20:24 +0000 | [diff] [blame] | 132 | # crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254) |
| 133 | dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl; |
| 134 | |
Jiyong Park | 2eab15e | 2022-05-02 13:23:50 +0900 | [diff] [blame] | 135 | # 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. |
| 140 | allow crosvm shell_data_file:file write; |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 141 | |
Inseob Kim | 42798af | 2023-01-13 14:08:16 +0900 | [diff] [blame] | 142 | # 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 Kim | 41fe7ea | 2024-09-03 10:59:07 +0900 | [diff] [blame] | 145 | dontaudit crosvm { |
| 146 | virtualizationmanager |
| 147 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `early_virtmgr') |
| 148 | }:fifo_file { read getattr }; |
Inseob Kim | 42798af | 2023-01-13 14:08:16 +0900 | [diff] [blame] | 149 | |
Nikita Ioffe | 40a48c1 | 2023-02-14 23:17:55 +0000 | [diff] [blame] | 150 | # Required for crosvm to start gdb-server to enable debugging of guest kernel. |
| 151 | allow crosvm self:tcp_socket { bind create read setopt write accept listen }; |
| 152 | allow crosvm port:tcp_socket name_bind; |
| 153 | allow crosvm adbd:unix_stream_socket ioctl; |
| 154 | allow crosvm node:tcp_socket node_bind; |
| 155 | |
Inseob Kim | 825056d | 2023-08-01 11:00:49 +0900 | [diff] [blame] | 156 | # Allow crosvm to interact to VFIO device |
| 157 | allow crosvm vfio_device:chr_file rw_file_perms; |
| 158 | allow crosvm vfio_device:dir r_dir_perms; |
| 159 | |
Inseob Kim | bbe514d | 2023-08-03 12:53:48 +0900 | [diff] [blame] | 160 | # Allow crosvm to access VM DTBO via a file created by virtualizationmanager. |
Inseob Kim | bbe514d | 2023-08-03 12:53:48 +0900 | [diff] [blame] | 161 | allow crosvm virtualizationservice_data_file:file read; |
Inseob Kim | 825056d | 2023-08-01 11:00:49 +0900 | [diff] [blame] | 162 | |
Seungjae Yoo | 12fd482 | 2024-05-28 14:12:52 +0900 | [diff] [blame] | 163 | is_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 Yoo | fcecae7 | 2024-06-14 15:27:05 +0900 | [diff] [blame] | 166 | allowxperm crosvm tun_device:chr_file ioctl { TUNGETIFF TUNSETOFFLOAD TUNSETVNETHDRSZ }; |
Seungjae Yoo | 12fd482 | 2024-05-28 14:12:52 +0900 | [diff] [blame] | 167 | 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 Kim | 41fe7ea | 2024-09-03 10:59:07 +0900 | [diff] [blame] | 172 | # Early VMs may print messages to kmsg_debug_device. |
| 173 | allow crosvm kmsg_debug_device:chr_file w_file_perms; |
| 174 | |
Inseob Kim | e398f7f | 2025-03-04 16:26:28 +0900 | [diff] [blame] | 175 | # Allow crosvm to read /data/nativetest for VTS |
| 176 | r_dir_file(crosvm, nativetest_data_file) |
| 177 | |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 178 | # 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. |
| 183 | neverallow crosvm { |
| 184 | virtualizationservice_data_file |
| 185 | staging_data_file |
| 186 | apk_data_file |
| 187 | app_data_file |
Akilesh Kailash | e7cd0eb | 2024-11-30 08:10:11 -0800 | [diff] [blame] | 188 | privapp_data_file |
Ellen Arteca | 27b515e | 2024-04-30 20:26:55 +0000 | [diff] [blame] | 189 | is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file') |
Inseob Kim | 0b9625d | 2024-07-31 17:42:23 +0900 | [diff] [blame] | 190 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `vm_data_file') |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 191 | userdebug_or_eng(`-shell_data_file') |
| 192 | }:file open; |
| 193 | |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 194 | # Don't allow crosvm to have access to ordinary vendor files that are not for VMs. |
| 195 | full_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. Mercier | 852d19b | 2024-10-14 16:56:12 +0000 | [diff] [blame] | 202 | -vendor_cgroup_desc_file |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 203 | -vendor_configs_file |
Seungjae Yoo | d2a0892 | 2023-11-15 17:59:30 +0900 | [diff] [blame] | 204 | -vendor_microdroid_file |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 205 | -vndk_sp_file |
| 206 | -vendor_task_profiles_file |
Todd Frederick | 6d3126d | 2024-10-22 15:13:47 +0000 | [diff] [blame] | 207 | -same_process_hal_file |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 208 | }:file *; |
| 209 | ') |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 210 | |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 211 | # 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 Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 215 | neverallow crosvm { |
| 216 | app_data_file_type |
| 217 | -app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 218 | -privapp_data_file |
Jiyong Park | cdd5e07 | 2022-04-19 11:48:32 +0900 | [diff] [blame] | 219 | -shell_data_file |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 220 | }:file read; |
Inseob Kim | b20cb78 | 2022-02-03 15:30:26 +0900 | [diff] [blame] | 221 | |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 222 | # Only virtualizationmanager can run crosvm |
Jiyong Park | 7ebed47 | 2025-03-01 10:24:56 -0800 | [diff] [blame] | 223 | # Allow vmlauncher app to launch crosvm for virtiofs |
Inseob Kim | b20cb78 | 2022-02-03 15:30:26 +0900 | [diff] [blame] | 224 | neverallow { |
| 225 | domain |
| 226 | -crosvm |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 227 | -virtualizationmanager |
Jiyong Park | 7ebed47 | 2025-03-01 10:24:56 -0800 | [diff] [blame] | 228 | -vmlauncher_app |
Paul Lawrence | 840b607 | 2025-01-28 07:41:05 -0800 | [diff] [blame] | 229 | userdebug_or_eng(`-overlay_remounter') |
Inseob Kim | 41fe7ea | 2024-09-03 10:59:07 +0900 | [diff] [blame] | 230 | |
| 231 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `-early_virtmgr') |
Inseob Kim | b20cb78 | 2022-02-03 15:30:26 +0900 | [diff] [blame] | 232 | } crosvm_exec:file no_x_file_perms; |