Andrew Walbran | a995e84 | 2021-03-29 17:19:12 +0000 | [diff] [blame] | 1 | type crosvm, domain, coredomain; |
| 2 | type crosvm_exec, system_file_type, exec_type, file_type; |
| 3 | type crosvm_tmpfs, file_type; |
| 4 | |
Elliot Berman | ae5869a | 2023-03-22 17:31:35 -0700 | [diff] [blame] | 5 | # Let crosvm open VM manager devices such as /dev/kvm. |
| 6 | allow crosvm vm_manager_device_type:chr_file rw_file_perms; |
Andrew Walbran | a995e84 | 2021-03-29 17:19:12 +0000 | [diff] [blame] | 7 | |
Alice Wang | 23b712e | 2024-08-01 08:29:31 +0000 | [diff] [blame^] | 8 | # 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 |
| 10 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, init_daemon_domain(crosvm)) |
| 11 | |
Andrew Walbran | a995e84 | 2021-03-29 17:19:12 +0000 | [diff] [blame] | 12 | # Most other domains shouldn't access /dev/kvm. |
| 13 | neverallow { domain -crosvm -ueventd -shell } kvm_device:chr_file getattr; |
Andrew Walbran | 2f27f96 | 2022-01-28 15:42:48 +0000 | [diff] [blame] | 14 | neverallow { domain -crosvm -ueventd } kvm_device:chr_file ~getattr; |
Jiyong Park | 2dd48d0 | 2021-12-28 21:26:03 +0900 | [diff] [blame] | 15 | neverallowxperm { domain -crosvm } kvm_device:chr_file ioctl ~{ KVM_CHECK_EXTENSION }; |
Andrew Walbran | 9b2fa1b | 2021-07-01 15:58:26 +0000 | [diff] [blame] | 16 | |
Elliot Berman | ae5869a | 2023-03-22 17:31:35 -0700 | [diff] [blame] | 17 | # 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. |
| 20 | neverallow { coredomain appdomain -crosvm -ueventd -shell } vm_manager_device_type:chr_file getattr; |
| 21 | neverallow { coredomain appdomain -crosvm -ueventd } vm_manager_device_type:chr_file ~getattr; |
| 22 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 23 | # Let crosvm create temporary files. |
| 24 | tmpfs_domain(crosvm) |
| 25 | |
| 26 | # Let crosvm receive file descriptors from VirtualizationService. |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 27 | allow crosvm virtualizationmanager:fd use; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 28 | |
Inseob Kim | 42798af | 2023-01-13 14:08:16 +0900 | [diff] [blame] | 29 | # Allow sending VirtualizationService the failure reason and console/log from the VM via pipe. |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 30 | allow crosvm virtualizationmanager:fifo_file write; |
Alan Stokes | b02ac32 | 2022-03-09 14:05:18 +0000 | [diff] [blame] | 31 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 32 | # 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 Yoo | d2a0892 | 2023-11-15 17:59:30 +0900 | [diff] [blame] | 34 | # /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] | 35 | # 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 Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 37 | allow crosvm { |
| 38 | virtualizationservice_data_file |
| 39 | staging_data_file |
| 40 | apk_data_file |
| 41 | app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 42 | privapp_data_file |
Alan Stokes | e2a002c | 2021-07-28 14:05:25 +0100 | [diff] [blame] | 43 | apex_compos_data_file |
Alice Wang | 40519f7 | 2023-08-31 11:37:30 +0000 | [diff] [blame] | 44 | apex_virt_data_file |
Jiyong Park | cdd5e07 | 2022-04-19 11:48:32 +0900 | [diff] [blame] | 45 | shell_data_file |
Seungjae Yoo | d2a0892 | 2023-11-15 17:59:30 +0900 | [diff] [blame] | 46 | vendor_microdroid_file |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 47 | }:file { getattr read ioctl lock }; |
| 48 | |
| 49 | # Allow searching the directory where the composite disk images are. |
| 50 | allow crosvm virtualizationservice_data_file:dir search; |
| 51 | |
Alan Stokes | aeab04f | 2024-02-01 16:16:01 +0000 | [diff] [blame] | 52 | # When running a VM as root we get spurious capability denials. |
| 53 | # Suppress them. |
| 54 | userdebug_or_eng(` |
| 55 | dontaudit crosvm self:capability ipc_lock; |
| 56 | ') |
| 57 | |
David Dai | 7066a96 | 2024-02-01 15:19:03 -0800 | [diff] [blame] | 58 | # Allow crosvm to tune for performance. |
| 59 | allow crosvm self:global_capability_class_set sys_nice; |
| 60 | |
Keir Fraser | ad58b8d | 2022-07-11 14:27:40 +0000 | [diff] [blame] | 61 | # Let crosvm access its control socket as created by VS. |
| 62 | # read, write, getattr: listener socket polling |
| 63 | # accept: listener socket accepting new connection |
| 64 | # Note that the open permission is not given as the socket is passed by FD. |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 65 | allow crosvm virtualizationmanager:unix_stream_socket { accept read write getattr getopt }; |
Keir Fraser | ad58b8d | 2022-07-11 14:27:40 +0000 | [diff] [blame] | 66 | |
Jaewan Kim | 7b843d4 | 2022-12-07 16:18:18 +0900 | [diff] [blame] | 67 | # Let crosvm open test artifacts under /data/local/tmp with file path. (e.g. custom pvmfw.img) |
| 68 | userdebug_or_eng(` |
| 69 | allow crosvm shell_data_file:dir search; |
| 70 | allow crosvm shell_data_file:file open; |
| 71 | ') |
| 72 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 73 | # The instance image and the composite image should be writable as well because they could represent |
| 74 | # mutable disks. |
| 75 | allow crosvm { |
| 76 | virtualizationservice_data_file |
| 77 | app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 78 | privapp_data_file |
Alan Stokes | e2a002c | 2021-07-28 14:05:25 +0100 | [diff] [blame] | 79 | apex_compos_data_file |
Alice Wang | 40519f7 | 2023-08-31 11:37:30 +0000 | [diff] [blame] | 80 | apex_virt_data_file |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 81 | }:file write; |
| 82 | |
| 83 | # 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] | 84 | allow crosvm adbd:fd use; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 85 | allow crosvm adbd:unix_stream_socket { read write }; |
Alan Stokes | 6d019be | 2023-06-08 13:13:08 +0100 | [diff] [blame] | 86 | allow crosvm devpts:chr_file { read write getattr ioctl }; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 87 | |
Jeongik Cha | f09f43c | 2024-04-02 14:50:14 +0900 | [diff] [blame] | 88 | is_flag_enabled(RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES, ` |
| 89 | # Allow crosvm to draw screen in the surface |
| 90 | allow crosvm device:dir { read open }; |
| 91 | allow crosvm same_process_hal_file:file { read open getattr map execute }; |
| 92 | allow crosvm gpu_device:chr_file { read write open ioctl map open getattr }; |
| 93 | allow crosvm hal_graphics_allocator:fd use; |
| 94 | allow crosvm hal_graphics_allocator_server:binder call; |
| 95 | allow crosvm surfaceflinger:fd use; |
| 96 | hal_client_domain(crosvm, hal_graphics_allocator) |
| 97 | |
| 98 | # To provide display service to an app to get surface. |
| 99 | # TODO(b/332677707): remove them when display service uses binder RPC. |
Jeongik Cha | 77a3ca6 | 2024-04-09 15:02:28 +0900 | [diff] [blame] | 100 | allow crosvm vmlauncher_app:binder { transfer call }; |
Jeongik Cha | f09f43c | 2024-04-02 14:50:14 +0900 | [diff] [blame] | 101 | allow crosvm servicemanager:binder { call transfer }; |
| 102 | allow crosvm virtualization_service:service_manager find; |
| 103 | allow crosvm virtualizationservice:binder { call transfer }; |
Mu-Le Lee | c7177f7 | 2024-04-17 08:38:47 +0800 | [diff] [blame] | 104 | |
| 105 | # Allow crosvm to play sound. |
| 106 | binder_call(crosvm, audioserver) |
| 107 | allow crosvm audioserver_service:service_manager find; |
Jeongik Cha | f09f43c | 2024-04-02 14:50:14 +0900 | [diff] [blame] | 108 | ') |
| 109 | |
Steven Moreland | fd59a2d | 2022-04-04 20:20:24 +0000 | [diff] [blame] | 110 | # crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254) |
| 111 | dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl; |
| 112 | |
Jiyong Park | 2eab15e | 2022-05-02 13:23:50 +0900 | [diff] [blame] | 113 | # crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by |
| 114 | # compliance tests and demo apps. Write access to instance.img is particularily important because |
| 115 | # the VM has to initialize the disk image on its first boot. Note that open access is still not |
| 116 | # granted because the files are expected to be opened by the owner of the VM (apps or shell in case |
| 117 | # when the vm is created by the `vm` tool) and handed over to crosvm as FD. |
| 118 | allow crosvm shell_data_file:file write; |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 119 | |
Inseob Kim | 42798af | 2023-01-13 14:08:16 +0900 | [diff] [blame] | 120 | # crosvm tries to read serial device, including the write-only pipe from virtualizationmanager (to |
| 121 | # forward console/log to the host logcat). |
| 122 | # crosvm only needs write permission, so dontaudit read |
Inseob Kim | bbe514d | 2023-08-03 12:53:48 +0900 | [diff] [blame] | 123 | dontaudit crosvm virtualizationmanager:fifo_file { read getattr }; |
Inseob Kim | 42798af | 2023-01-13 14:08:16 +0900 | [diff] [blame] | 124 | |
Nikita Ioffe | 40a48c1 | 2023-02-14 23:17:55 +0000 | [diff] [blame] | 125 | # Required for crosvm to start gdb-server to enable debugging of guest kernel. |
| 126 | allow crosvm self:tcp_socket { bind create read setopt write accept listen }; |
| 127 | allow crosvm port:tcp_socket name_bind; |
| 128 | allow crosvm adbd:unix_stream_socket ioctl; |
| 129 | allow crosvm node:tcp_socket node_bind; |
| 130 | |
Inseob Kim | 825056d | 2023-08-01 11:00:49 +0900 | [diff] [blame] | 131 | # Allow crosvm to interact to VFIO device |
| 132 | allow crosvm vfio_device:chr_file rw_file_perms; |
| 133 | allow crosvm vfio_device:dir r_dir_perms; |
| 134 | |
Inseob Kim | bbe514d | 2023-08-03 12:53:48 +0900 | [diff] [blame] | 135 | # Allow crosvm to access VM DTBO via a file created by virtualizationmanager. |
| 136 | allow crosvm virtualizationmanager:fd use; |
| 137 | allow crosvm virtualizationservice_data_file:file read; |
Inseob Kim | 825056d | 2023-08-01 11:00:49 +0900 | [diff] [blame] | 138 | |
Seungjae Yoo | 12fd482 | 2024-05-28 14:12:52 +0900 | [diff] [blame] | 139 | is_flag_enabled(RELEASE_AVF_ENABLE_NETWORK, ` |
| 140 | # Allow crosvm to deal with file descriptors of TAP interfaces. |
| 141 | allow crosvm tun_device:chr_file rw_file_perms; |
Seungjae Yoo | fcecae7 | 2024-06-14 15:27:05 +0900 | [diff] [blame] | 142 | allowxperm crosvm tun_device:chr_file ioctl { TUNGETIFF TUNSETOFFLOAD TUNSETVNETHDRSZ }; |
Seungjae Yoo | 12fd482 | 2024-05-28 14:12:52 +0900 | [diff] [blame] | 143 | allow crosvm self:udp_socket create_socket_perms; |
| 144 | allowxperm crosvm self:udp_socket ioctl SIOCGIFMTU; |
| 145 | allow crosvm vmnic:fd use; |
| 146 | ') |
| 147 | |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 148 | # Don't allow crosvm to open files that it doesn't own. |
| 149 | # This is important because a malicious application could try to start a VM with a composite disk |
| 150 | # image referring by name to files which it doesn't have permission to open, trying to get crosvm to |
| 151 | # open them on its behalf. By preventing crosvm from opening any other files we prevent this |
| 152 | # potential privilege escalation. See http://b/192453819 for more discussion. |
| 153 | neverallow crosvm { |
| 154 | virtualizationservice_data_file |
| 155 | staging_data_file |
| 156 | apk_data_file |
| 157 | app_data_file |
| 158 | privapp_data_file |
Ellen Arteca | 27b515e | 2024-04-30 20:26:55 +0000 | [diff] [blame] | 159 | is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file') |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 160 | userdebug_or_eng(`-shell_data_file') |
| 161 | }:file open; |
| 162 | |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 163 | # Don't allow crosvm to have access to ordinary vendor files that are not for VMs. |
| 164 | full_treble_only(` |
| 165 | neverallow crosvm { |
| 166 | vendor_file_type |
| 167 | -vendor_vm_file |
| 168 | -vendor_vm_data_file |
| 169 | # These types are not required for crosvm, but the access is granted to globally in domain.te |
| 170 | # thus should be exempted here. |
| 171 | -vendor_configs_file |
Seungjae Yoo | d2a0892 | 2023-11-15 17:59:30 +0900 | [diff] [blame] | 172 | -vendor_microdroid_file |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 173 | -vndk_sp_file |
| 174 | -vendor_task_profiles_file |
Jeongik Cha | f09f43c | 2024-04-02 14:50:14 +0900 | [diff] [blame] | 175 | is_flag_enabled(RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES, `-same_process_hal_file') |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 176 | }:file *; |
| 177 | ') |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 178 | |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 179 | # Only allow crosvm to read app data files for clients that can start |
| 180 | # VMs. Note that the use of app data files is further restricted |
| 181 | # inside the virtualizationservice by checking the label of all disk |
| 182 | # image files. |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 183 | neverallow crosvm { |
| 184 | app_data_file_type |
| 185 | -app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 186 | -privapp_data_file |
Jiyong Park | cdd5e07 | 2022-04-19 11:48:32 +0900 | [diff] [blame] | 187 | -shell_data_file |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 188 | }:file read; |
Inseob Kim | b20cb78 | 2022-02-03 15:30:26 +0900 | [diff] [blame] | 189 | |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 190 | # Only virtualizationmanager can run crosvm |
Inseob Kim | b20cb78 | 2022-02-03 15:30:26 +0900 | [diff] [blame] | 191 | neverallow { |
| 192 | domain |
| 193 | -crosvm |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 194 | -virtualizationmanager |
Alice Wang | 23b712e | 2024-08-01 08:29:31 +0000 | [diff] [blame^] | 195 | # TODO(b/357025924): This is a temporary workaround to allow the KeyMint VM to use crosvm |
| 196 | # directly. It should be removed once the KeyMint VM can be started with early_virtmgr |
| 197 | is_flag_enabled(RELEASE_AVF_ENABLE_EARLY_VM, `-init') |
Inseob Kim | b20cb78 | 2022-02-03 15:30:26 +0900 | [diff] [blame] | 198 | } crosvm_exec:file no_x_file_perms; |