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 | |
Andrew Walbran | a995e84 | 2021-03-29 17:19:12 +0000 | [diff] [blame] | 5 | # Let crosvm open /dev/kvm. |
| 6 | allow crosvm kvm_device:chr_file rw_file_perms; |
| 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 | |
Andrew Walbran | ed82cc8 | 2022-01-14 13:47:05 +0000 | [diff] [blame] | 13 | # Let crosvm mlock VM memory and page tables. |
| 14 | allow crosvm self:capability ipc_lock; |
| 15 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 16 | # Let crosvm create temporary files. |
| 17 | tmpfs_domain(crosvm) |
| 18 | |
| 19 | # Let crosvm receive file descriptors from VirtualizationService. |
| 20 | allow crosvm virtualizationservice:fd use; |
| 21 | |
Alan Stokes | b02ac32 | 2022-03-09 14:05:18 +0000 | [diff] [blame] | 22 | # Allow sending VirtualizationService the failure reason from the VM via pipe. |
| 23 | allow crosvm virtualizationservice:fifo_file write; |
| 24 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 25 | # Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes |
| 26 | # (staging_data_file), APKs (apk_data_file and shell_data_file where the latter is for test apks in |
| 27 | # /data/local/tmp), and instance.img (app_data_file). Note that the open permission is not given as |
| 28 | # the files are passed as file descriptors. |
| 29 | allow crosvm { |
| 30 | virtualizationservice_data_file |
| 31 | staging_data_file |
| 32 | apk_data_file |
| 33 | app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame^] | 34 | privapp_data_file |
Alan Stokes | e2a002c | 2021-07-28 14:05:25 +0100 | [diff] [blame] | 35 | apex_compos_data_file |
Jiyong Park | cdd5e07 | 2022-04-19 11:48:32 +0900 | [diff] [blame] | 36 | shell_data_file |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 37 | }:file { getattr read ioctl lock }; |
| 38 | |
| 39 | # Allow searching the directory where the composite disk images are. |
| 40 | allow crosvm virtualizationservice_data_file:dir search; |
| 41 | |
Keir Fraser | ad58b8d | 2022-07-11 14:27:40 +0000 | [diff] [blame] | 42 | # Let crosvm access its control socket as created by VS. |
| 43 | # read, write, getattr: listener socket polling |
| 44 | # accept: listener socket accepting new connection |
| 45 | # Note that the open permission is not given as the socket is passed by FD. |
Steven Moreland | 34f6b26 | 2022-10-11 01:13:29 +0000 | [diff] [blame] | 46 | allow crosvm virtualizationservice:unix_stream_socket { accept read write getattr getopt }; |
Keir Fraser | ad58b8d | 2022-07-11 14:27:40 +0000 | [diff] [blame] | 47 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 48 | # The instance image and the composite image should be writable as well because they could represent |
| 49 | # mutable disks. |
| 50 | allow crosvm { |
| 51 | virtualizationservice_data_file |
| 52 | app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame^] | 53 | privapp_data_file |
Alan Stokes | e2a002c | 2021-07-28 14:05:25 +0100 | [diff] [blame] | 54 | apex_compos_data_file |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 55 | }:file write; |
| 56 | |
| 57 | # 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] | 58 | allow crosvm adbd:fd use; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 59 | allow crosvm adbd:unix_stream_socket { read write }; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 60 | |
Steven Moreland | fd59a2d | 2022-04-04 20:20:24 +0000 | [diff] [blame] | 61 | # crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254) |
| 62 | dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl; |
| 63 | |
Jiyong Park | 2eab15e | 2022-05-02 13:23:50 +0900 | [diff] [blame] | 64 | # crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by |
| 65 | # compliance tests and demo apps. Write access to instance.img is particularily important because |
| 66 | # the VM has to initialize the disk image on its first boot. Note that open access is still not |
| 67 | # granted because the files are expected to be opened by the owner of the VM (apps or shell in case |
| 68 | # when the vm is created by the `vm` tool) and handed over to crosvm as FD. |
| 69 | allow crosvm shell_data_file:file write; |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 70 | |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame^] | 71 | # Don't allow crosvm to open files that it doesn't own. |
| 72 | # This is important because a malicious application could try to start a VM with a composite disk |
| 73 | # image referring by name to files which it doesn't have permission to open, trying to get crosvm to |
| 74 | # open them on its behalf. By preventing crosvm from opening any other files we prevent this |
| 75 | # potential privilege escalation. See http://b/192453819 for more discussion. |
| 76 | neverallow crosvm { |
| 77 | virtualizationservice_data_file |
| 78 | staging_data_file |
| 79 | apk_data_file |
| 80 | app_data_file |
| 81 | privapp_data_file |
| 82 | userdebug_or_eng(`-shell_data_file') |
| 83 | }:file open; |
| 84 | |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 85 | # Don't allow crosvm to have access to ordinary vendor files that are not for VMs. |
| 86 | full_treble_only(` |
| 87 | neverallow crosvm { |
| 88 | vendor_file_type |
| 89 | -vendor_vm_file |
| 90 | -vendor_vm_data_file |
| 91 | # These types are not required for crosvm, but the access is granted to globally in domain.te |
| 92 | # thus should be exempted here. |
| 93 | -vendor_configs_file |
| 94 | -vndk_sp_file |
| 95 | -vendor_task_profiles_file |
| 96 | }:file *; |
| 97 | ') |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 98 | |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame^] | 99 | # Only allow crosvm to read app data files for clients that can start |
| 100 | # VMs. Note that the use of app data files is further restricted |
| 101 | # inside the virtualizationservice by checking the label of all disk |
| 102 | # image files. |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 103 | neverallow crosvm { |
| 104 | app_data_file_type |
| 105 | -app_data_file |
Alan Stokes | 3060852 | 2022-10-24 12:32:34 +0100 | [diff] [blame^] | 106 | -privapp_data_file |
Jiyong Park | cdd5e07 | 2022-04-19 11:48:32 +0900 | [diff] [blame] | 107 | -shell_data_file |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 108 | }:file read; |
Inseob Kim | b20cb78 | 2022-02-03 15:30:26 +0900 | [diff] [blame] | 109 | |
| 110 | # Only virtualizationservice can run crosvm |
| 111 | neverallow { |
| 112 | domain |
| 113 | -crosvm |
| 114 | -virtualizationservice |
| 115 | } crosvm_exec:file no_x_file_perms; |