blob: ee8f90cf929323b2ed6c8d1285df792bd2155103 [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
Elliot Bermanae5869a2023-03-22 17:31:35 -07005# Let crosvm open VM manager devices such as /dev/kvm.
6allow crosvm vm_manager_device_type:chr_file rw_file_perms;
Andrew Walbrana995e842021-03-29 17:19:12 +00007
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
Elliot Bermanae5869a2023-03-22 17:31:35 -070013# 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
Jiyong Park5e20d832021-07-12 21:11:33 +090019# Let crosvm create temporary files.
20tmpfs_domain(crosvm)
21
22# Let crosvm receive file descriptors from VirtualizationService.
David Brazdil55d808c2022-12-15 13:38:42 +000023allow crosvm virtualizationmanager:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090024
Inseob Kim42798af2023-01-13 14:08:16 +090025# Allow sending VirtualizationService the failure reason and console/log from the VM via pipe.
David Brazdil55d808c2022-12-15 13:38:42 +000026allow crosvm virtualizationmanager:fifo_file write;
Alan Stokesb02ac322022-03-09 14:05:18 +000027
Jiyong Park5e20d832021-07-12 21:11:33 +090028# 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
Seungjae Yood2a08922023-11-15 17:59:30 +090030# /data/local/tmp), instance.img (app_data_file), and microdroid vendor image (vendor_microdroid_file).
Alice Wang40519f72023-08-31 11:37:30 +000031# Allow crosvm to read the instance image of the service VM saved in apex_virt_data_file.
32# Note that the open permission is not given as the files are passed as file descriptors.
Jiyong Park5e20d832021-07-12 21:11:33 +090033allow crosvm {
34 virtualizationservice_data_file
35 staging_data_file
36 apk_data_file
37 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010038 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010039 apex_compos_data_file
Alice Wang40519f72023-08-31 11:37:30 +000040 apex_virt_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +090041 shell_data_file
Seungjae Yood2a08922023-11-15 17:59:30 +090042 vendor_microdroid_file
Jiyong Park5e20d832021-07-12 21:11:33 +090043}:file { getattr read ioctl lock };
44
45# Allow searching the directory where the composite disk images are.
46allow crosvm virtualizationservice_data_file:dir search;
47
Alan Stokesaeab04f2024-02-01 16:16:01 +000048# When running a VM as root we get spurious capability denials.
49# Suppress them.
50userdebug_or_eng(`
51 dontaudit crosvm self:capability ipc_lock;
52')
53
David Dai7066a962024-02-01 15:19:03 -080054# Allow crosvm to tune for performance.
55allow crosvm self:global_capability_class_set sys_nice;
56
Keir Fraserad58b8d2022-07-11 14:27:40 +000057# Let crosvm access its control socket as created by VS.
58# read, write, getattr: listener socket polling
59# accept: listener socket accepting new connection
60# Note that the open permission is not given as the socket is passed by FD.
David Brazdil55d808c2022-12-15 13:38:42 +000061allow crosvm virtualizationmanager:unix_stream_socket { accept read write getattr getopt };
Keir Fraserad58b8d2022-07-11 14:27:40 +000062
Jaewan Kim7b843d42022-12-07 16:18:18 +090063# Let crosvm open test artifacts under /data/local/tmp with file path. (e.g. custom pvmfw.img)
64userdebug_or_eng(`
65 allow crosvm shell_data_file:dir search;
66 allow crosvm shell_data_file:file open;
67')
68
Jiyong Park5e20d832021-07-12 21:11:33 +090069# The instance image and the composite image should be writable as well because they could represent
70# mutable disks.
71allow crosvm {
72 virtualizationservice_data_file
73 app_data_file
Alan Stokes30608522022-10-24 12:32:34 +010074 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010075 apex_compos_data_file
Alice Wang40519f72023-08-31 11:37:30 +000076 apex_virt_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090077}:file write;
78
79# 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 +010080allow crosvm adbd:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090081allow crosvm adbd:unix_stream_socket { read write };
Alan Stokes6d019be2023-06-08 13:13:08 +010082allow crosvm devpts:chr_file { read write getattr ioctl };
Jiyong Park5e20d832021-07-12 21:11:33 +090083
Jeongik Chaf09f43c2024-04-02 14:50:14 +090084is_flag_enabled(RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES, `
85 # Allow crosvm to draw screen in the surface
86 allow crosvm device:dir { read open };
87 allow crosvm same_process_hal_file:file { read open getattr map execute };
88 allow crosvm gpu_device:chr_file { read write open ioctl map open getattr };
89 allow crosvm hal_graphics_allocator:fd use;
90 allow crosvm hal_graphics_allocator_server:binder call;
91 allow crosvm surfaceflinger:fd use;
92 hal_client_domain(crosvm, hal_graphics_allocator)
93
94 # To provide display service to an app to get surface.
95 # TODO(b/332677707): remove them when display service uses binder RPC.
Jeongik Cha77a3ca62024-04-09 15:02:28 +090096 allow crosvm vmlauncher_app:binder { transfer call };
Jeongik Chaf09f43c2024-04-02 14:50:14 +090097 allow crosvm servicemanager:binder { call transfer };
98 allow crosvm virtualization_service:service_manager find;
99 allow crosvm virtualizationservice:binder { call transfer };
Mu-Le Leec7177f72024-04-17 08:38:47 +0800100
101 # Allow crosvm to play sound.
102 binder_call(crosvm, audioserver)
103 allow crosvm audioserver_service:service_manager find;
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900104')
105
Steven Morelandfd59a2d2022-04-04 20:20:24 +0000106# crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254)
107dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl;
108
Jiyong Park2eab15e2022-05-02 13:23:50 +0900109# crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by
110# compliance tests and demo apps. Write access to instance.img is particularily important because
111# the VM has to initialize the disk image on its first boot. Note that open access is still not
112# granted because the files are expected to be opened by the owner of the VM (apps or shell in case
113# when the vm is created by the `vm` tool) and handed over to crosvm as FD.
114allow crosvm shell_data_file:file write;
Jiyong Park3fee5a42021-08-09 09:24:45 +0900115
Inseob Kim42798af2023-01-13 14:08:16 +0900116# crosvm tries to read serial device, including the write-only pipe from virtualizationmanager (to
117# forward console/log to the host logcat).
118# crosvm only needs write permission, so dontaudit read
Inseob Kimbbe514d2023-08-03 12:53:48 +0900119dontaudit crosvm virtualizationmanager:fifo_file { read getattr };
Inseob Kim42798af2023-01-13 14:08:16 +0900120
Nikita Ioffe40a48c12023-02-14 23:17:55 +0000121# Required for crosvm to start gdb-server to enable debugging of guest kernel.
122allow crosvm self:tcp_socket { bind create read setopt write accept listen };
123allow crosvm port:tcp_socket name_bind;
124allow crosvm adbd:unix_stream_socket ioctl;
125allow crosvm node:tcp_socket node_bind;
126
Inseob Kim825056d2023-08-01 11:00:49 +0900127# Allow crosvm to interact to VFIO device
128allow crosvm vfio_device:chr_file rw_file_perms;
129allow crosvm vfio_device:dir r_dir_perms;
130
Inseob Kimbbe514d2023-08-03 12:53:48 +0900131# Allow crosvm to access VM DTBO via a file created by virtualizationmanager.
132allow crosvm virtualizationmanager:fd use;
133allow crosvm virtualizationservice_data_file:file read;
Inseob Kim825056d2023-08-01 11:00:49 +0900134
Alan Stokes30608522022-10-24 12:32:34 +0100135# Don't allow crosvm to open files that it doesn't own.
136# This is important because a malicious application could try to start a VM with a composite disk
137# image referring by name to files which it doesn't have permission to open, trying to get crosvm to
138# open them on its behalf. By preventing crosvm from opening any other files we prevent this
139# potential privilege escalation. See http://b/192453819 for more discussion.
140neverallow crosvm {
141 virtualizationservice_data_file
142 staging_data_file
143 apk_data_file
144 app_data_file
145 privapp_data_file
146 userdebug_or_eng(`-shell_data_file')
147}:file open;
148
Jiyong Park3fee5a42021-08-09 09:24:45 +0900149# Don't allow crosvm to have access to ordinary vendor files that are not for VMs.
150full_treble_only(`
151 neverallow crosvm {
152 vendor_file_type
153 -vendor_vm_file
154 -vendor_vm_data_file
155 # These types are not required for crosvm, but the access is granted to globally in domain.te
156 # thus should be exempted here.
157 -vendor_configs_file
Seungjae Yood2a08922023-11-15 17:59:30 +0900158 -vendor_microdroid_file
Jiyong Park3fee5a42021-08-09 09:24:45 +0900159 -vndk_sp_file
160 -vendor_task_profiles_file
Jeongik Chaf09f43c2024-04-02 14:50:14 +0900161 is_flag_enabled(RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES, `-same_process_hal_file')
Jiyong Park3fee5a42021-08-09 09:24:45 +0900162 }:file *;
163')
Jiyong Park028e7222021-11-26 00:59:07 +0900164
Alan Stokes30608522022-10-24 12:32:34 +0100165# Only allow crosvm to read app data files for clients that can start
166# VMs. Note that the use of app data files is further restricted
167# inside the virtualizationservice by checking the label of all disk
168# image files.
Jiyong Park028e7222021-11-26 00:59:07 +0900169neverallow crosvm {
170 app_data_file_type
171 -app_data_file
Alan Stokes30608522022-10-24 12:32:34 +0100172 -privapp_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +0900173 -shell_data_file
Jiyong Park028e7222021-11-26 00:59:07 +0900174}:file read;
Inseob Kimb20cb782022-02-03 15:30:26 +0900175
David Brazdil55d808c2022-12-15 13:38:42 +0000176# Only virtualizationmanager can run crosvm
Inseob Kimb20cb782022-02-03 15:30:26 +0900177neverallow {
178 domain
179 -crosvm
David Brazdil55d808c2022-12-15 13:38:42 +0000180 -virtualizationmanager
Inseob Kimb20cb782022-02-03 15:30:26 +0900181} crosvm_exec:file no_x_file_perms;