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; |
Jiyong Park | 2dd48d0 | 2021-12-28 21:26:03 +0900 | [diff] [blame] | 10 | neverallow { domain -crosvm -ueventd -virtualizationservice } kvm_device:chr_file ~getattr; |
| 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 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 13 | # Let crosvm create temporary files. |
| 14 | tmpfs_domain(crosvm) |
| 15 | |
| 16 | # Let crosvm receive file descriptors from VirtualizationService. |
| 17 | allow crosvm virtualizationservice:fd use; |
| 18 | |
| 19 | # Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes |
| 20 | # (staging_data_file), APKs (apk_data_file and shell_data_file where the latter is for test apks in |
| 21 | # /data/local/tmp), and instance.img (app_data_file). Note that the open permission is not given as |
| 22 | # the files are passed as file descriptors. |
| 23 | allow crosvm { |
| 24 | virtualizationservice_data_file |
| 25 | staging_data_file |
| 26 | apk_data_file |
| 27 | app_data_file |
Alan Stokes | e2a002c | 2021-07-28 14:05:25 +0100 | [diff] [blame] | 28 | apex_compos_data_file |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 29 | userdebug_or_eng(`shell_data_file') |
| 30 | }:file { getattr read ioctl lock }; |
| 31 | |
| 32 | # Allow searching the directory where the composite disk images are. |
| 33 | allow crosvm virtualizationservice_data_file:dir search; |
| 34 | |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 35 | # Don't allow crosvm to open files that it doesn't own. |
Andrew Walbran | 8191dc0 | 2021-12-24 13:10:25 +0000 | [diff] [blame] | 36 | # This is important because a malicious application could try to start a VM with a composite disk |
| 37 | # image referring by name to files which it doesn't have permission to open, trying to get crosvm to |
| 38 | # open them on its behalf. By preventing crosvm from opening any other files we prevent this |
| 39 | # potential privilege escalation. See http://b/192453819 for more discussion. |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 40 | neverallow crosvm { |
Andrew Walbran | c0b4a91 | 2021-08-05 14:09:52 +0000 | [diff] [blame] | 41 | virtualizationservice_data_file |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 42 | staging_data_file |
| 43 | apk_data_file |
| 44 | app_data_file |
| 45 | userdebug_or_eng(`-shell_data_file') |
| 46 | }:file open; |
| 47 | |
| 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 | e2a002c | 2021-07-28 14:05:25 +0100 | [diff] [blame] | 53 | apex_compos_data_file |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 54 | }:file write; |
| 55 | |
| 56 | # 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] | 57 | allow crosvm adbd:fd use; |
Jiyong Park | 5e20d83 | 2021-07-12 21:11:33 +0900 | [diff] [blame] | 58 | allow crosvm adbd:unix_stream_socket { read write }; |
| 59 | allow crosvm appdomain:fifo_file { read write }; |
| 60 | |
| 61 | # The console log can also be written to /data/local/tmp. This is not safe as the log then can be |
| 62 | # visible to the processes which don't own the VM. Therefore, this is a debugging only feature. |
| 63 | userdebug_or_eng(`allow crosvm shell_data_file:file w_file_perms;') |
Jiyong Park | 3fee5a4 | 2021-08-09 09:24:45 +0900 | [diff] [blame] | 64 | |
| 65 | # Don't allow crosvm to have access to ordinary vendor files that are not for VMs. |
| 66 | full_treble_only(` |
| 67 | neverallow crosvm { |
| 68 | vendor_file_type |
| 69 | -vendor_vm_file |
| 70 | -vendor_vm_data_file |
| 71 | # These types are not required for crosvm, but the access is granted to globally in domain.te |
| 72 | # thus should be exempted here. |
| 73 | -vendor_configs_file |
| 74 | -vndk_sp_file |
| 75 | -vendor_task_profiles_file |
| 76 | }:file *; |
| 77 | ') |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 78 | |
| 79 | # app_data_file (and shell_data_file for debuggable builds) is the only |
| 80 | # app_data_file_type that is allowed for crosvm to read. Note that the use of |
Andrew Walbran | 8191dc0 | 2021-12-24 13:10:25 +0000 | [diff] [blame] | 81 | # app_data_file is allowed only for the instance disk image. This is enforced |
Jiyong Park | 028e722 | 2021-11-26 00:59:07 +0900 | [diff] [blame] | 82 | # inside the virtualizationservice by checking the file context of all disk |
| 83 | # image files. |
| 84 | neverallow crosvm { |
| 85 | app_data_file_type |
| 86 | -app_data_file |
| 87 | userdebug_or_eng(`-shell_data_file') |
| 88 | }:file read; |