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