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 VM manager devices such as /dev/kvm. 6*e4a36f41SAndroid Build Coastguard Workerallow crosvm vm_manager_device_type: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# Most other domains shouldn't access other vm managers either. 14*e4a36f41SAndroid Build Coastguard Worker# These restrictions need to be slightly looser than for kvm_device to allow 15*e4a36f41SAndroid Build Coastguard Worker# for different implementations. 16*e4a36f41SAndroid Build Coastguard Workerneverallow { coredomain appdomain -crosvm -ueventd -shell } vm_manager_device_type:chr_file getattr; 17*e4a36f41SAndroid Build Coastguard Workerneverallow { coredomain appdomain -crosvm -ueventd } vm_manager_device_type:chr_file ~getattr; 18*e4a36f41SAndroid Build Coastguard Worker 19*e4a36f41SAndroid Build Coastguard Worker# Let crosvm create temporary files. 20*e4a36f41SAndroid Build Coastguard Workertmpfs_domain(crosvm) 21*e4a36f41SAndroid Build Coastguard Worker 22*e4a36f41SAndroid Build Coastguard Worker# Let crosvm receive file descriptors from VirtualizationService. 23*e4a36f41SAndroid Build Coastguard Workerallow crosvm virtualizationmanager:fd use; 24*e4a36f41SAndroid Build Coastguard Worker 25*e4a36f41SAndroid Build Coastguard Worker# Allow sending VirtualizationService the failure reason and console/log from the VM via pipe. 26*e4a36f41SAndroid Build Coastguard Workerallow crosvm virtualizationmanager:fifo_file write; 27*e4a36f41SAndroid Build Coastguard Worker 28*e4a36f41SAndroid Build Coastguard Worker# Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes 29*e4a36f41SAndroid Build Coastguard Worker# (staging_data_file), APKs (apk_data_file and shell_data_file where the latter is for test apks in 30*e4a36f41SAndroid Build Coastguard Worker# /data/local/tmp), instance.img (app_data_file), and microdroid vendor image (vendor_microdroid_file). 31*e4a36f41SAndroid Build Coastguard Worker# Allow crosvm to read the instance image of the service VM saved in apex_virt_data_file. 32*e4a36f41SAndroid Build Coastguard Worker# Note that the open permission is not given as the files are passed as file descriptors. 33*e4a36f41SAndroid Build Coastguard Workerallow crosvm { 34*e4a36f41SAndroid Build Coastguard Worker virtualizationservice_data_file 35*e4a36f41SAndroid Build Coastguard Worker staging_data_file 36*e4a36f41SAndroid Build Coastguard Worker apk_data_file 37*e4a36f41SAndroid Build Coastguard Worker app_data_file 38*e4a36f41SAndroid Build Coastguard Worker privapp_data_file 39*e4a36f41SAndroid Build Coastguard Worker apex_compos_data_file 40*e4a36f41SAndroid Build Coastguard Worker apex_virt_data_file 41*e4a36f41SAndroid Build Coastguard Worker shell_data_file 42*e4a36f41SAndroid Build Coastguard Worker vendor_microdroid_file 43*e4a36f41SAndroid Build Coastguard Worker}:file { getattr read ioctl lock }; 44*e4a36f41SAndroid Build Coastguard Worker 45*e4a36f41SAndroid Build Coastguard Worker# Allow searching the directory where the composite disk images are. 46*e4a36f41SAndroid Build Coastguard Workerallow crosvm virtualizationservice_data_file:dir search; 47*e4a36f41SAndroid Build Coastguard Worker 48*e4a36f41SAndroid Build Coastguard Worker# When running a VM as root we get spurious capability denials. 49*e4a36f41SAndroid Build Coastguard Worker# Suppress them. 50*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 51*e4a36f41SAndroid Build Coastguard Worker dontaudit crosvm self:capability ipc_lock; 52*e4a36f41SAndroid Build Coastguard Worker') 53*e4a36f41SAndroid Build Coastguard Worker 54*e4a36f41SAndroid Build Coastguard Worker# Allow crosvm to tune for performance. 55*e4a36f41SAndroid Build Coastguard Workerallow crosvm self:global_capability_class_set sys_nice; 56*e4a36f41SAndroid Build Coastguard Worker 57*e4a36f41SAndroid Build Coastguard Worker# Let crosvm access its control socket as created by VS. 58*e4a36f41SAndroid Build Coastguard Worker# read, write, getattr: listener socket polling 59*e4a36f41SAndroid Build Coastguard Worker# accept: listener socket accepting new connection 60*e4a36f41SAndroid Build Coastguard Worker# Note that the open permission is not given as the socket is passed by FD. 61*e4a36f41SAndroid Build Coastguard Workerallow crosvm virtualizationmanager:unix_stream_socket { accept read write getattr getopt }; 62*e4a36f41SAndroid Build Coastguard Worker 63*e4a36f41SAndroid Build Coastguard Worker# Let crosvm open test artifacts under /data/local/tmp with file path. (e.g. custom pvmfw.img) 64*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 65*e4a36f41SAndroid Build Coastguard Worker allow crosvm shell_data_file:dir search; 66*e4a36f41SAndroid Build Coastguard Worker allow crosvm shell_data_file:file open; 67*e4a36f41SAndroid Build Coastguard Worker') 68*e4a36f41SAndroid Build Coastguard Worker 69*e4a36f41SAndroid Build Coastguard Worker# The instance image and the composite image should be writable as well because they could represent 70*e4a36f41SAndroid Build Coastguard Worker# mutable disks. 71*e4a36f41SAndroid Build Coastguard Workerallow crosvm { 72*e4a36f41SAndroid Build Coastguard Worker virtualizationservice_data_file 73*e4a36f41SAndroid Build Coastguard Worker app_data_file 74*e4a36f41SAndroid Build Coastguard Worker privapp_data_file 75*e4a36f41SAndroid Build Coastguard Worker apex_compos_data_file 76*e4a36f41SAndroid Build Coastguard Worker apex_virt_data_file 77*e4a36f41SAndroid Build Coastguard Worker}:file write; 78*e4a36f41SAndroid Build Coastguard Worker 79*e4a36f41SAndroid Build Coastguard Worker# Allow crosvm to pipe console log to shell or app which could be the owner of a VM. 80*e4a36f41SAndroid Build Coastguard Workerallow crosvm adbd:fd use; 81*e4a36f41SAndroid Build Coastguard Workerallow crosvm adbd:unix_stream_socket { read write }; 82*e4a36f41SAndroid Build Coastguard Workerallow crosvm devpts:chr_file { read write getattr ioctl }; 83*e4a36f41SAndroid Build Coastguard Worker 84*e4a36f41SAndroid Build Coastguard Worker# crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254) 85*e4a36f41SAndroid Build Coastguard Workerdontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl; 86*e4a36f41SAndroid Build Coastguard Worker 87*e4a36f41SAndroid Build Coastguard Worker# crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by 88*e4a36f41SAndroid Build Coastguard Worker# compliance tests and demo apps. Write access to instance.img is particularily important because 89*e4a36f41SAndroid Build Coastguard Worker# the VM has to initialize the disk image on its first boot. Note that open access is still not 90*e4a36f41SAndroid Build Coastguard Worker# granted because the files are expected to be opened by the owner of the VM (apps or shell in case 91*e4a36f41SAndroid Build Coastguard Worker# when the vm is created by the `vm` tool) and handed over to crosvm as FD. 92*e4a36f41SAndroid Build Coastguard Workerallow crosvm shell_data_file:file write; 93*e4a36f41SAndroid Build Coastguard Worker 94*e4a36f41SAndroid Build Coastguard Worker# crosvm tries to read serial device, including the write-only pipe from virtualizationmanager (to 95*e4a36f41SAndroid Build Coastguard Worker# forward console/log to the host logcat). 96*e4a36f41SAndroid Build Coastguard Worker# crosvm only needs write permission, so dontaudit read 97*e4a36f41SAndroid Build Coastguard Workerdontaudit crosvm virtualizationmanager:fifo_file { read getattr }; 98*e4a36f41SAndroid Build Coastguard Worker 99*e4a36f41SAndroid Build Coastguard Worker# Required for crosvm to start gdb-server to enable debugging of guest kernel. 100*e4a36f41SAndroid Build Coastguard Workerallow crosvm self:tcp_socket { bind create read setopt write accept listen }; 101*e4a36f41SAndroid Build Coastguard Workerallow crosvm port:tcp_socket name_bind; 102*e4a36f41SAndroid Build Coastguard Workerallow crosvm adbd:unix_stream_socket ioctl; 103*e4a36f41SAndroid Build Coastguard Workerallow crosvm node:tcp_socket node_bind; 104*e4a36f41SAndroid Build Coastguard Worker 105*e4a36f41SAndroid Build Coastguard Worker# Allow crosvm to interact to VFIO device 106*e4a36f41SAndroid Build Coastguard Workerallow crosvm vfio_device:chr_file rw_file_perms; 107*e4a36f41SAndroid Build Coastguard Workerallow crosvm vfio_device:dir r_dir_perms; 108*e4a36f41SAndroid Build Coastguard Worker 109*e4a36f41SAndroid Build Coastguard Worker# Allow crosvm to access VM DTBO via a file created by virtualizationmanager. 110*e4a36f41SAndroid Build Coastguard Workerallow crosvm virtualizationmanager:fd use; 111*e4a36f41SAndroid Build Coastguard Workerallow crosvm virtualizationservice_data_file:file read; 112*e4a36f41SAndroid Build Coastguard Worker 113*e4a36f41SAndroid Build Coastguard Worker# Don't allow crosvm to open files that it doesn't own. 114*e4a36f41SAndroid Build Coastguard Worker# This is important because a malicious application could try to start a VM with a composite disk 115*e4a36f41SAndroid Build Coastguard Worker# image referring by name to files which it doesn't have permission to open, trying to get crosvm to 116*e4a36f41SAndroid Build Coastguard Worker# open them on its behalf. By preventing crosvm from opening any other files we prevent this 117*e4a36f41SAndroid Build Coastguard Worker# potential privilege escalation. See http://b/192453819 for more discussion. 118*e4a36f41SAndroid Build Coastguard Workerneverallow crosvm { 119*e4a36f41SAndroid Build Coastguard Worker virtualizationservice_data_file 120*e4a36f41SAndroid Build Coastguard Worker staging_data_file 121*e4a36f41SAndroid Build Coastguard Worker apk_data_file 122*e4a36f41SAndroid Build Coastguard Worker app_data_file 123*e4a36f41SAndroid Build Coastguard Worker privapp_data_file 124*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-shell_data_file') 125*e4a36f41SAndroid Build Coastguard Worker}:file open; 126*e4a36f41SAndroid Build Coastguard Worker 127*e4a36f41SAndroid Build Coastguard Worker# Don't allow crosvm to have access to ordinary vendor files that are not for VMs. 128*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(` 129*e4a36f41SAndroid Build Coastguard Worker neverallow crosvm { 130*e4a36f41SAndroid Build Coastguard Worker vendor_file_type 131*e4a36f41SAndroid Build Coastguard Worker -vendor_vm_file 132*e4a36f41SAndroid Build Coastguard Worker -vendor_vm_data_file 133*e4a36f41SAndroid Build Coastguard Worker # These types are not required for crosvm, but the access is granted to globally in domain.te 134*e4a36f41SAndroid Build Coastguard Worker # thus should be exempted here. 135*e4a36f41SAndroid Build Coastguard Worker -vendor_configs_file 136*e4a36f41SAndroid Build Coastguard Worker -vendor_microdroid_file 137*e4a36f41SAndroid Build Coastguard Worker -vndk_sp_file 138*e4a36f41SAndroid Build Coastguard Worker -vendor_task_profiles_file 139*e4a36f41SAndroid Build Coastguard Worker }:file *; 140*e4a36f41SAndroid Build Coastguard Worker') 141*e4a36f41SAndroid Build Coastguard Worker 142*e4a36f41SAndroid Build Coastguard Worker# Only allow crosvm to read app data files for clients that can start 143*e4a36f41SAndroid Build Coastguard Worker# VMs. Note that the use of app data files is further restricted 144*e4a36f41SAndroid Build Coastguard Worker# inside the virtualizationservice by checking the label of all disk 145*e4a36f41SAndroid Build Coastguard Worker# image files. 146*e4a36f41SAndroid Build Coastguard Workerneverallow crosvm { 147*e4a36f41SAndroid Build Coastguard Worker app_data_file_type 148*e4a36f41SAndroid Build Coastguard Worker -app_data_file 149*e4a36f41SAndroid Build Coastguard Worker -privapp_data_file 150*e4a36f41SAndroid Build Coastguard Worker -shell_data_file 151*e4a36f41SAndroid Build Coastguard Worker}:file read; 152*e4a36f41SAndroid Build Coastguard Worker 153*e4a36f41SAndroid Build Coastguard Worker# Only virtualizationmanager can run crosvm 154*e4a36f41SAndroid Build Coastguard Workerneverallow { 155*e4a36f41SAndroid Build Coastguard Worker domain 156*e4a36f41SAndroid Build Coastguard Worker -crosvm 157*e4a36f41SAndroid Build Coastguard Worker -virtualizationmanager 158*e4a36f41SAndroid Build Coastguard Worker} crosvm_exec:file no_x_file_perms; 159