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 | |
| 8 | # Most other domains shouldn't access /dev/kvm. |
| 9 | neverallow { domain -crosvm -ueventd -shell } kvm_device:chr_file getattr; |
Andrew Walbran | 2f27f96 | 2022-01-28 15:42:48 +0000 | [diff] [blame] | 10 | neverallow { domain -crosvm -ueventd } kvm_device:chr_file ~getattr; |
Jiyong Park | 2dd48d0 | 2021-12-28 21:26:03 +0900 | [diff] [blame] | 11 | neverallowxperm { domain -crosvm } kvm_device:chr_file ioctl ~{ KVM_CHECK_EXTENSION }; |
Andrew Walbran | 9b2fa1b | 2021-07-01 15:58:26 +0000 | [diff] [blame] | 12 | |
Elliot Berman | ae5869a | 2023-03-22 17:31:35 -0700 | [diff] [blame] | 13 | # 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. |
| 16 | neverallow { coredomain appdomain -crosvm -ueventd -shell } vm_manager_device_type:chr_file getattr; |
| 17 | neverallow { coredomain appdomain -crosvm -ueventd } vm_manager_device_type:chr_file ~getattr; |
| 18 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 19 | # Let crosvm create temporary files. |
| 20 | tmpfs_domain(crosvm) |
| 21 | |
| 22 | # Let crosvm receive file descriptors from VirtualizationService. |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 23 | allow crosvm virtualizationmanager:fd use; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 24 | |
Inseob Kim | 42798af | 2023-01-13 14:08:16 +0900 | [diff] [blame] | 25 | # 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] | 26 | allow crosvm virtualizationmanager:fifo_file write; |
Alan Stokes | b02ac32 | 2022-03-09 14:05:18 +0000 | [diff] [blame] | 27 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 28 | # Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes |
| 29 | # (staging_data_file), APKs (apk_data_file and shell_data_file where the latter is for test apks in |
Alice Wang | 40519f7 | 2023-08-31 11:37:30 +0000 | [diff] [blame^] | 30 | # /data/local/tmp), and instance.img (app_data_file). |
| 31 | # Allow crosvm to read the instance image of the service VM saved in apex_virt_data_file. |
| 32 | # 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] | 33 | allow crosvm { |
| 34 | virtualizationservice_data_file |
| 35 | staging_data_file |
| 36 | apk_data_file |
| 37 | app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 38 | privapp_data_file |
Alan Stokes | e2a002c | 2021-07-28 14:05:25 +0100 | [diff] [blame] | 39 | apex_compos_data_file |
Alice Wang | 40519f7 | 2023-08-31 11:37:30 +0000 | [diff] [blame^] | 40 | apex_virt_data_file |
Jiyong Park | cdd5e07 | 2022-04-19 11:48:32 +0900 | [diff] [blame] | 41 | shell_data_file |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 42 | }:file { getattr read ioctl lock }; |
| 43 | |
| 44 | # Allow searching the directory where the composite disk images are. |
| 45 | allow crosvm virtualizationservice_data_file:dir search; |
| 46 | |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 47 | # Allow crosvm to mlock guest memory. |
| 48 | allow crosvm self:capability ipc_lock; |
| 49 | |
Keir Fraser | ad58b8d | 2022-07-11 14:27:40 +0000 | [diff] [blame] | 50 | # Let crosvm access its control socket as created by VS. |
| 51 | # read, write, getattr: listener socket polling |
| 52 | # accept: listener socket accepting new connection |
| 53 | # 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] | 54 | allow crosvm virtualizationmanager:unix_stream_socket { accept read write getattr getopt }; |
Keir Fraser | ad58b8d | 2022-07-11 14:27:40 +0000 | [diff] [blame] | 55 | |
Jaewan Kim | 7b843d4 | 2022-12-07 16:18:18 +0900 | [diff] [blame] | 56 | # Let crosvm open test artifacts under /data/local/tmp with file path. (e.g. custom pvmfw.img) |
| 57 | userdebug_or_eng(` |
| 58 | allow crosvm shell_data_file:dir search; |
| 59 | allow crosvm shell_data_file:file open; |
| 60 | ') |
| 61 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 62 | # The instance image and the composite image should be writable as well because they could represent |
| 63 | # mutable disks. |
| 64 | allow crosvm { |
| 65 | virtualizationservice_data_file |
| 66 | app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 67 | privapp_data_file |
Alan Stokes | e2a002c | 2021-07-28 14:05:25 +0100 | [diff] [blame] | 68 | apex_compos_data_file |
Alice Wang | 40519f7 | 2023-08-31 11:37:30 +0000 | [diff] [blame^] | 69 | apex_virt_data_file |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 70 | }:file write; |
| 71 | |
| 72 | # 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] | 73 | allow crosvm adbd:fd use; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 74 | allow crosvm adbd:unix_stream_socket { read write }; |
Alan Stokes | 6d019be | 2023-06-08 13:13:08 +0100 | [diff] [blame] | 75 | allow crosvm devpts:chr_file { read write getattr ioctl }; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 76 | |
Steven Moreland | fd59a2d | 2022-04-04 20:20:24 +0000 | [diff] [blame] | 77 | # crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254) |
| 78 | dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl; |
| 79 | |
Jiyong Park | 2eab15e | 2022-05-02 13:23:50 +0900 | [diff] [blame] | 80 | # crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by |
| 81 | # compliance tests and demo apps. Write access to instance.img is particularily important because |
| 82 | # the VM has to initialize the disk image on its first boot. Note that open access is still not |
| 83 | # granted because the files are expected to be opened by the owner of the VM (apps or shell in case |
| 84 | # when the vm is created by the `vm` tool) and handed over to crosvm as FD. |
| 85 | allow crosvm shell_data_file:file write; |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 86 | |
Inseob Kim | 42798af | 2023-01-13 14:08:16 +0900 | [diff] [blame] | 87 | # crosvm tries to read serial device, including the write-only pipe from virtualizationmanager (to |
| 88 | # forward console/log to the host logcat). |
| 89 | # crosvm only needs write permission, so dontaudit read |
Inseob Kim | bbe514d | 2023-08-03 12:53:48 +0900 | [diff] [blame] | 90 | dontaudit crosvm virtualizationmanager:fifo_file { read getattr }; |
Inseob Kim | 42798af | 2023-01-13 14:08:16 +0900 | [diff] [blame] | 91 | |
Nikita Ioffe | 40a48c1 | 2023-02-14 23:17:55 +0000 | [diff] [blame] | 92 | # Required for crosvm to start gdb-server to enable debugging of guest kernel. |
| 93 | allow crosvm self:tcp_socket { bind create read setopt write accept listen }; |
| 94 | allow crosvm port:tcp_socket name_bind; |
| 95 | allow crosvm adbd:unix_stream_socket ioctl; |
| 96 | allow crosvm node:tcp_socket node_bind; |
| 97 | |
Inseob Kim | 825056d | 2023-08-01 11:00:49 +0900 | [diff] [blame] | 98 | # Allow crosvm to interact to VFIO device |
| 99 | allow crosvm vfio_device:chr_file rw_file_perms; |
| 100 | allow crosvm vfio_device:dir r_dir_perms; |
| 101 | |
Inseob Kim | bbe514d | 2023-08-03 12:53:48 +0900 | [diff] [blame] | 102 | # Allow crosvm to access VM DTBO via a file created by virtualizationmanager. |
| 103 | allow crosvm virtualizationmanager:fd use; |
| 104 | allow crosvm virtualizationservice_data_file:file read; |
Inseob Kim | 825056d | 2023-08-01 11:00:49 +0900 | [diff] [blame] | 105 | |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 106 | # Don't allow crosvm to open files that it doesn't own. |
| 107 | # This is important because a malicious application could try to start a VM with a composite disk |
| 108 | # image referring by name to files which it doesn't have permission to open, trying to get crosvm to |
| 109 | # open them on its behalf. By preventing crosvm from opening any other files we prevent this |
| 110 | # potential privilege escalation. See http://b/192453819 for more discussion. |
| 111 | neverallow crosvm { |
| 112 | virtualizationservice_data_file |
| 113 | staging_data_file |
| 114 | apk_data_file |
| 115 | app_data_file |
| 116 | privapp_data_file |
| 117 | userdebug_or_eng(`-shell_data_file') |
| 118 | }:file open; |
| 119 | |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 120 | # Don't allow crosvm to have access to ordinary vendor files that are not for VMs. |
| 121 | full_treble_only(` |
| 122 | neverallow crosvm { |
| 123 | vendor_file_type |
| 124 | -vendor_vm_file |
| 125 | -vendor_vm_data_file |
| 126 | # These types are not required for crosvm, but the access is granted to globally in domain.te |
| 127 | # thus should be exempted here. |
| 128 | -vendor_configs_file |
| 129 | -vndk_sp_file |
| 130 | -vendor_task_profiles_file |
| 131 | }:file *; |
| 132 | ') |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 133 | |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 134 | # Only allow crosvm to read app data files for clients that can start |
| 135 | # VMs. Note that the use of app data files is further restricted |
| 136 | # inside the virtualizationservice by checking the label of all disk |
| 137 | # image files. |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 138 | neverallow crosvm { |
| 139 | app_data_file_type |
| 140 | -app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame] | 141 | -privapp_data_file |
Jiyong Park | cdd5e07 | 2022-04-19 11:48:32 +0900 | [diff] [blame] | 142 | -shell_data_file |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 143 | }:file read; |
Inseob Kim | b20cb78 | 2022-02-03 15:30:26 +0900 | [diff] [blame] | 144 | |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 145 | # Only virtualizationmanager can run crosvm |
Inseob Kim | b20cb78 | 2022-02-03 15:30:26 +0900 | [diff] [blame] | 146 | neverallow { |
| 147 | domain |
| 148 | -crosvm |
David Brazdil | 55d808c | 2022-12-15 13:38:42 +0000 | [diff] [blame] | 149 | -virtualizationmanager |
Inseob Kim | b20cb78 | 2022-02-03 15:30:26 +0900 | [diff] [blame] | 150 | } crosvm_exec:file no_x_file_perms; |