blob: b0b4ec5115041572de65ccc84cfead7007f09a1e [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;
10neverallow { domain -crosvm -ueventd } kvm_device:chr_file ~getattr;
Andrew Walbran9b2fa1b2021-07-01 15:58:26 +000011
Jiyong Park5e20d832021-07-12 21:11:33 +090012# Let crosvm create temporary files.
13tmpfs_domain(crosvm)
14
15# Let crosvm receive file descriptors from VirtualizationService.
16allow crosvm virtualizationservice:fd use;
17
18# Let crosvm read the composite disk images (virtualizationservice_data_file), APEXes
19# (staging_data_file), APKs (apk_data_file and shell_data_file where the latter is for test apks in
20# /data/local/tmp), and instance.img (app_data_file). Note that the open permission is not given as
21# the files are passed as file descriptors.
22allow crosvm {
23 virtualizationservice_data_file
24 staging_data_file
25 apk_data_file
26 app_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010027 apex_compos_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090028 userdebug_or_eng(`shell_data_file')
29}:file { getattr read ioctl lock };
30
31# Allow searching the directory where the composite disk images are.
32allow crosvm virtualizationservice_data_file:dir search;
33
Jiyong Park5e20d832021-07-12 21:11:33 +090034# Don't allow crosvm to open files that it doesn't own.
Andrew Walbran8191dc02021-12-24 13:10:25 +000035# This is important because a malicious application could try to start a VM with a composite disk
36# image referring by name to files which it doesn't have permission to open, trying to get crosvm to
37# open them on its behalf. By preventing crosvm from opening any other files we prevent this
38# potential privilege escalation. See http://b/192453819 for more discussion.
Jiyong Park5e20d832021-07-12 21:11:33 +090039neverallow crosvm {
Andrew Walbranc0b4a912021-08-05 14:09:52 +000040 virtualizationservice_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090041 staging_data_file
42 apk_data_file
43 app_data_file
44 userdebug_or_eng(`-shell_data_file')
45}:file open;
46
47# The instance image and the composite image should be writable as well because they could represent
48# mutable disks.
49allow crosvm {
50 virtualizationservice_data_file
51 app_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010052 apex_compos_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090053}:file write;
54
55# 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 +010056allow crosvm adbd:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090057allow crosvm adbd:unix_stream_socket { read write };
58allow crosvm appdomain:fifo_file { read write };
59
60# The console log can also be written to /data/local/tmp. This is not safe as the log then can be
61# visible to the processes which don't own the VM. Therefore, this is a debugging only feature.
62userdebug_or_eng(`allow crosvm shell_data_file:file w_file_perms;')
Jiyong Park3fee5a42021-08-09 09:24:45 +090063
64# Don't allow crosvm to have access to ordinary vendor files that are not for VMs.
65full_treble_only(`
66 neverallow crosvm {
67 vendor_file_type
68 -vendor_vm_file
69 -vendor_vm_data_file
70 # These types are not required for crosvm, but the access is granted to globally in domain.te
71 # thus should be exempted here.
72 -vendor_configs_file
73 -vndk_sp_file
74 -vendor_task_profiles_file
75 }:file *;
76')
Jiyong Park028e7222021-11-26 00:59:07 +090077
78# app_data_file (and shell_data_file for debuggable builds) is the only
79# app_data_file_type that is allowed for crosvm to read. Note that the use of
Andrew Walbran8191dc02021-12-24 13:10:25 +000080# app_data_file is allowed only for the instance disk image. This is enforced
Jiyong Park028e7222021-11-26 00:59:07 +090081# inside the virtualizationservice by checking the file context of all disk
82# image files.
83neverallow crosvm {
84 app_data_file_type
85 -app_data_file
86 userdebug_or_eng(`-shell_data_file')
87}:file read;