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