1*e4a36f41SAndroid Build Coastguard Workertype crosvm, domain, coredomain; 2*e4a36f41SAndroid Build Coastguard Workertype crosvm_exec, system_file_type, exec_type, file_type; 3*e4a36f41SAndroid Build Coastguard Workertype crosvm_tmpfs, file_type; 4*e4a36f41SAndroid Build Coastguard Worker 5*e4a36f41SAndroid Build Coastguard Worker# Let crosvm open /dev/kvm. 6*e4a36f41SAndroid Build Coastguard Workerallow crosvm kvm_device:chr_file rw_file_perms; 7*e4a36f41SAndroid Build Coastguard Worker 8*e4a36f41SAndroid Build Coastguard Worker# Most other domains shouldn't access /dev/kvm. 9*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -crosvm -ueventd -shell } kvm_device:chr_file getattr; 10*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -crosvm -ueventd } kvm_device:chr_file ~getattr; 11*e4a36f41SAndroid Build Coastguard Workerneverallowxperm { domain -crosvm } kvm_device:chr_file ioctl ~{ KVM_CHECK_EXTENSION }; 12*e4a36f41SAndroid Build Coastguard Worker 13*e4a36f41SAndroid Build Coastguard Worker# Let crosvm mlock VM memory and page tables. 14*e4a36f41SAndroid Build Coastguard Workerallow crosvm self:capability ipc_lock; 15*e4a36f41SAndroid Build Coastguard Worker 16*e4a36f41SAndroid Build Coastguard Worker# Let crosvm create temporary files. 17*e4a36f41SAndroid Build Coastguard Workertmpfs_domain(crosvm) 18*e4a36f41SAndroid Build Coastguard Worker 19*e4a36f41SAndroid Build Coastguard Worker# Let crosvm receive file descriptors from VirtualizationService. 20*e4a36f41SAndroid Build Coastguard Workerallow crosvm virtualizationservice:fd use; 21*e4a36f41SAndroid Build Coastguard Worker 22*e4a36f41SAndroid Build Coastguard Worker# Allow sending VirtualizationService the failure reason from the VM via pipe. 23*e4a36f41SAndroid Build Coastguard Workerallow crosvm virtualizationservice:fifo_file write; 24*e4a36f41SAndroid Build Coastguard Worker 25*e4a36f41SAndroid Build Coastguard Worker# Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes 26*e4a36f41SAndroid Build Coastguard Worker# (staging_data_file), APKs (apk_data_file and shell_data_file where the latter is for test apks in 27*e4a36f41SAndroid Build Coastguard Worker# /data/local/tmp), and instance.img (app_data_file). Note that the open permission is not given as 28*e4a36f41SAndroid Build Coastguard Worker# the files are passed as file descriptors. 29*e4a36f41SAndroid Build Coastguard Workerallow crosvm { 30*e4a36f41SAndroid Build Coastguard Worker virtualizationservice_data_file 31*e4a36f41SAndroid Build Coastguard Worker staging_data_file 32*e4a36f41SAndroid Build Coastguard Worker apk_data_file 33*e4a36f41SAndroid Build Coastguard Worker app_data_file 34*e4a36f41SAndroid Build Coastguard Worker apex_compos_data_file 35*e4a36f41SAndroid Build Coastguard Worker shell_data_file 36*e4a36f41SAndroid Build Coastguard Worker}:file { getattr read ioctl lock }; 37*e4a36f41SAndroid Build Coastguard Worker 38*e4a36f41SAndroid Build Coastguard Worker# Allow searching the directory where the composite disk images are. 39*e4a36f41SAndroid Build Coastguard Workerallow crosvm virtualizationservice_data_file:dir search; 40*e4a36f41SAndroid Build Coastguard Worker 41*e4a36f41SAndroid Build Coastguard Worker# Don't allow crosvm to open files that it doesn't own. 42*e4a36f41SAndroid Build Coastguard Worker# This is important because a malicious application could try to start a VM with a composite disk 43*e4a36f41SAndroid Build Coastguard Worker# image referring by name to files which it doesn't have permission to open, trying to get crosvm to 44*e4a36f41SAndroid Build Coastguard Worker# open them on its behalf. By preventing crosvm from opening any other files we prevent this 45*e4a36f41SAndroid Build Coastguard Worker# potential privilege escalation. See http://b/192453819 for more discussion. 46*e4a36f41SAndroid Build Coastguard Workerneverallow crosvm { 47*e4a36f41SAndroid Build Coastguard Worker virtualizationservice_data_file 48*e4a36f41SAndroid Build Coastguard Worker staging_data_file 49*e4a36f41SAndroid Build Coastguard Worker apk_data_file 50*e4a36f41SAndroid Build Coastguard Worker app_data_file 51*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-shell_data_file') 52*e4a36f41SAndroid Build Coastguard Worker}:file open; 53*e4a36f41SAndroid Build Coastguard Worker 54*e4a36f41SAndroid Build Coastguard Worker# The instance image and the composite image should be writable as well because they could represent 55*e4a36f41SAndroid Build Coastguard Worker# mutable disks. 56*e4a36f41SAndroid Build Coastguard Workerallow crosvm { 57*e4a36f41SAndroid Build Coastguard Worker virtualizationservice_data_file 58*e4a36f41SAndroid Build Coastguard Worker app_data_file 59*e4a36f41SAndroid Build Coastguard Worker apex_compos_data_file 60*e4a36f41SAndroid Build Coastguard Worker}:file write; 61*e4a36f41SAndroid Build Coastguard Worker 62*e4a36f41SAndroid Build Coastguard Worker# Allow crosvm to pipe console log to shell or app which could be the owner of a VM. 63*e4a36f41SAndroid Build Coastguard Workerallow crosvm adbd:fd use; 64*e4a36f41SAndroid Build Coastguard Workerallow crosvm adbd:unix_stream_socket { read write }; 65*e4a36f41SAndroid Build Coastguard Worker 66*e4a36f41SAndroid Build Coastguard Worker# For ACPI 67*e4a36f41SAndroid Build Coastguard Workerallow crosvm self:netlink_generic_socket create_socket_perms_no_ioctl; 68*e4a36f41SAndroid Build Coastguard Worker 69*e4a36f41SAndroid Build Coastguard Worker# The console log can also be written to /data/local/tmp. This is not safe as the log then can be 70*e4a36f41SAndroid Build Coastguard Worker# visible to the processes which don't own the VM. Therefore, this is a debugging only feature. 71*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`allow crosvm shell_data_file:file w_file_perms;') 72*e4a36f41SAndroid Build Coastguard Worker 73*e4a36f41SAndroid Build Coastguard Worker# Don't allow crosvm to have access to ordinary vendor files that are not for VMs. 74*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(` 75*e4a36f41SAndroid Build Coastguard Worker neverallow crosvm { 76*e4a36f41SAndroid Build Coastguard Worker vendor_file_type 77*e4a36f41SAndroid Build Coastguard Worker -vendor_vm_file 78*e4a36f41SAndroid Build Coastguard Worker -vendor_vm_data_file 79*e4a36f41SAndroid Build Coastguard Worker # These types are not required for crosvm, but the access is granted to globally in domain.te 80*e4a36f41SAndroid Build Coastguard Worker # thus should be exempted here. 81*e4a36f41SAndroid Build Coastguard Worker -vendor_configs_file 82*e4a36f41SAndroid Build Coastguard Worker -vndk_sp_file 83*e4a36f41SAndroid Build Coastguard Worker -vendor_task_profiles_file 84*e4a36f41SAndroid Build Coastguard Worker }:file *; 85*e4a36f41SAndroid Build Coastguard Worker') 86*e4a36f41SAndroid Build Coastguard Worker 87*e4a36f41SAndroid Build Coastguard Worker# app_data_file and shell_data_file is the only app_data_file_type that is 88*e4a36f41SAndroid Build Coastguard Worker# allowed for crosvm to read. Note that the use of app_data_file is allowed 89*e4a36f41SAndroid Build Coastguard Worker# only for the instance disk image. This is enforced inside the 90*e4a36f41SAndroid Build Coastguard Worker# virtualizationservice by checking the file context of all disk image files. 91*e4a36f41SAndroid Build Coastguard Workerneverallow crosvm { 92*e4a36f41SAndroid Build Coastguard Worker app_data_file_type 93*e4a36f41SAndroid Build Coastguard Worker -app_data_file 94*e4a36f41SAndroid Build Coastguard Worker -shell_data_file 95*e4a36f41SAndroid Build Coastguard Worker}:file read; 96*e4a36f41SAndroid Build Coastguard Worker 97*e4a36f41SAndroid Build Coastguard Worker# Only virtualizationservice can run crosvm 98*e4a36f41SAndroid Build Coastguard Workerneverallow { 99*e4a36f41SAndroid Build Coastguard Worker domain 100*e4a36f41SAndroid Build Coastguard Worker -crosvm 101*e4a36f41SAndroid Build Coastguard Worker -virtualizationservice 102*e4a36f41SAndroid Build Coastguard Worker} crosvm_exec:file no_x_file_perms; 103