blob: 73ce3c6984ed336b15846428c6d1ea134667b493 [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;
Andrew Walbran2f27f962022-01-28 15:42:48 +000010neverallow { domain -crosvm -ueventd } kvm_device:chr_file ~getattr;
Jiyong Park2dd48d02021-12-28 21:26:03 +090011neverallowxperm { domain -crosvm } kvm_device:chr_file ioctl ~{ KVM_CHECK_EXTENSION };
Andrew Walbran9b2fa1b2021-07-01 15:58:26 +000012
Andrew Walbraned82cc82022-01-14 13:47:05 +000013# Let crosvm mlock VM memory and page tables.
14allow crosvm self:capability ipc_lock;
15
Jiyong Park5e20d832021-07-12 21:11:33 +090016# Let crosvm create temporary files.
17tmpfs_domain(crosvm)
18
19# Let crosvm receive file descriptors from VirtualizationService.
20allow crosvm virtualizationservice:fd use;
21
Alan Stokesb02ac322022-03-09 14:05:18 +000022# Allow sending VirtualizationService the failure reason from the VM via pipe.
23allow crosvm virtualizationservice:fifo_file write;
24
Jiyong Park5e20d832021-07-12 21:11:33 +090025# 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.
29allow crosvm {
30 virtualizationservice_data_file
31 staging_data_file
32 apk_data_file
33 app_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010034 apex_compos_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +090035 shell_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090036}:file { getattr read ioctl lock };
37
38# Allow searching the directory where the composite disk images are.
39allow crosvm virtualizationservice_data_file:dir search;
40
Jiyong Park5e20d832021-07-12 21:11:33 +090041# Don't allow crosvm to open files that it doesn't own.
Andrew Walbran8191dc02021-12-24 13:10:25 +000042# This is important because a malicious application could try to start a VM with a composite disk
43# image referring by name to files which it doesn't have permission to open, trying to get crosvm to
44# open them on its behalf. By preventing crosvm from opening any other files we prevent this
45# potential privilege escalation. See http://b/192453819 for more discussion.
Jiyong Park5e20d832021-07-12 21:11:33 +090046neverallow crosvm {
Andrew Walbranc0b4a912021-08-05 14:09:52 +000047 virtualizationservice_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090048 staging_data_file
49 apk_data_file
50 app_data_file
51 userdebug_or_eng(`-shell_data_file')
52}:file open;
53
54# The instance image and the composite image should be writable as well because they could represent
55# mutable disks.
56allow crosvm {
57 virtualizationservice_data_file
58 app_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010059 apex_compos_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090060}:file write;
61
62# 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 +010063allow crosvm adbd:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090064allow crosvm adbd:unix_stream_socket { read write };
Jiyong Park5e20d832021-07-12 21:11:33 +090065
Jiyong Park2eab15e2022-05-02 13:23:50 +090066# crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by
67# compliance tests and demo apps. Write access to instance.img is particularily important because
68# the VM has to initialize the disk image on its first boot. Note that open access is still not
69# granted because the files are expected to be opened by the owner of the VM (apps or shell in case
70# when the vm is created by the `vm` tool) and handed over to crosvm as FD.
71allow crosvm shell_data_file:file write;
Jiyong Park3fee5a42021-08-09 09:24:45 +090072
73# Don't allow crosvm to have access to ordinary vendor files that are not for VMs.
74full_treble_only(`
75 neverallow crosvm {
76 vendor_file_type
77 -vendor_vm_file
78 -vendor_vm_data_file
79 # These types are not required for crosvm, but the access is granted to globally in domain.te
80 # thus should be exempted here.
81 -vendor_configs_file
82 -vndk_sp_file
83 -vendor_task_profiles_file
84 }:file *;
85')
Jiyong Park028e7222021-11-26 00:59:07 +090086
Jiyong Parkcdd5e072022-04-19 11:48:32 +090087# app_data_file and shell_data_file is the only app_data_file_type that is
88# allowed for crosvm to read. Note that the use of app_data_file is allowed
89# only for the instance disk image. This is enforced inside the
90# virtualizationservice by checking the file context of all disk image files.
Jiyong Park028e7222021-11-26 00:59:07 +090091neverallow crosvm {
92 app_data_file_type
93 -app_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +090094 -shell_data_file
Jiyong Park028e7222021-11-26 00:59:07 +090095}:file read;
Inseob Kimb20cb782022-02-03 15:30:26 +090096
97# Only virtualizationservice can run crosvm
98neverallow {
99 domain
100 -crosvm
101 -virtualizationservice
102} crosvm_exec:file no_x_file_perms;