blob: 3f135253ba491aa0f8c57b9817990f8ddebdedb0 [file] [log] [blame]
Andrew Walbrana995e842021-03-29 17:19:12 +00001type crosvm, domain, coredomain;
2type crosvm_exec, system_file_type, exec_type, file_type;
3type crosvm_tmpfs, file_type;
4
Andrew Walbrana995e842021-03-29 17:19:12 +00005# Let crosvm open /dev/kvm.
6allow crosvm kvm_device:chr_file rw_file_perms;
7
8# Most other domains shouldn't access /dev/kvm.
9neverallow { domain -crosvm -ueventd -shell } kvm_device:chr_file getattr;
Jiyong Park2dd48d02021-12-28 21:26:03 +090010neverallow { domain -crosvm -ueventd -virtualizationservice } kvm_device:chr_file ~getattr;
11neverallowxperm { domain -crosvm } kvm_device:chr_file ioctl ~{ KVM_CHECK_EXTENSION };
Andrew Walbran9b2fa1b2021-07-01 15:58:26 +000012
Jiyong Park5e20d832021-07-12 21:11:33 +090013# Let crosvm create temporary files.
14tmpfs_domain(crosvm)
15
16# Let crosvm receive file descriptors from VirtualizationService.
17allow 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.
23allow crosvm {
24 virtualizationservice_data_file
25 staging_data_file
26 apk_data_file
27 app_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010028 apex_compos_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090029 userdebug_or_eng(`shell_data_file')
30}:file { getattr read ioctl lock };
31
32# Allow searching the directory where the composite disk images are.
33allow crosvm virtualizationservice_data_file:dir search;
34
Jiyong Park5e20d832021-07-12 21:11:33 +090035# Don't allow crosvm to open files that it doesn't own.
36neverallow crosvm {
Andrew Walbranc0b4a912021-08-05 14:09:52 +000037 virtualizationservice_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090038 staging_data_file
39 apk_data_file
40 app_data_file
41 userdebug_or_eng(`-shell_data_file')
42}:file open;
43
44# The instance image and the composite image should be writable as well because they could represent
45# mutable disks.
46allow crosvm {
47 virtualizationservice_data_file
48 app_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010049 apex_compos_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090050}:file write;
51
52# Allow crosvm to pipe console log to shell or app which could be the owner of a VM.
Alan Stokes39f49702021-09-02 11:10:59 +010053allow crosvm adbd:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090054allow crosvm adbd:unix_stream_socket { read write };
55allow crosvm appdomain:fifo_file { read write };
56
57# The console log can also be written to /data/local/tmp. This is not safe as the log then can be
58# visible to the processes which don't own the VM. Therefore, this is a debugging only feature.
59userdebug_or_eng(`allow crosvm shell_data_file:file w_file_perms;')
Jiyong Park3fee5a42021-08-09 09:24:45 +090060
61# Don't allow crosvm to have access to ordinary vendor files that are not for VMs.
62full_treble_only(`
63 neverallow crosvm {
64 vendor_file_type
65 -vendor_vm_file
66 -vendor_vm_data_file
67 # These types are not required for crosvm, but the access is granted to globally in domain.te
68 # thus should be exempted here.
69 -vendor_configs_file
70 -vndk_sp_file
71 -vendor_task_profiles_file
72 }:file *;
73')
Jiyong Park028e7222021-11-26 00:59:07 +090074
75# app_data_file (and shell_data_file for debuggable builds) is the only
76# app_data_file_type that is allowed for crosvm to read. Note that the use of
77# app_data_file is allowed only for the intance disk image. This is enforced
78# inside the virtualizationservice by checking the file context of all disk
79# image files.
80neverallow crosvm {
81 app_data_file_type
82 -app_data_file
83 userdebug_or_eng(`-shell_data_file')
84}:file read;