blob: 2d9a688860236501f78995ad9891c84ba142a4b4 [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
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
Alan Stokes30608522022-10-24 12:32:34 +010037 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010038 apex_compos_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +090039 shell_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090040}: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
David Brazdil55d808c2022-12-15 13:38:42 +000045# Allow crosvm to mlock guest memory.
46allow crosvm self:capability ipc_lock;
47
Keir Fraserad58b8d2022-07-11 14:27:40 +000048# 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.
David Brazdil55d808c2022-12-15 13:38:42 +000052allow crosvm virtualizationmanager:unix_stream_socket { accept read write getattr getopt };
Keir Fraserad58b8d2022-07-11 14:27:40 +000053
Jaewan Kim7b843d42022-12-07 16:18:18 +090054# 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
Jiyong Park5e20d832021-07-12 21:11:33 +090060# 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
Alan Stokes30608522022-10-24 12:32:34 +010065 privapp_data_file
Alan Stokese2a002c2021-07-28 14:05:25 +010066 apex_compos_data_file
Jiyong Park5e20d832021-07-12 21:11:33 +090067}:file write;
68
69# 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 +010070allow crosvm adbd:fd use;
Jiyong Park5e20d832021-07-12 21:11:33 +090071allow crosvm adbd:unix_stream_socket { read write };
Alan Stokes6d019be2023-06-08 13:13:08 +010072allow crosvm devpts:chr_file { read write getattr ioctl };
Jiyong Park5e20d832021-07-12 21:11:33 +090073
Steven Morelandfd59a2d2022-04-04 20:20:24 +000074# crosvm tries to use netlink sockets as part its APCI implementation, but we don't need it for AVF (b/228077254)
75dontaudit crosvm self:netlink_generic_socket create_socket_perms_no_ioctl;
76
Jiyong Park2eab15e2022-05-02 13:23:50 +090077# crosvm can write files in /data/local/tmp which are usually used for instance.img and logging by
78# compliance tests and demo apps. Write access to instance.img is particularily important because
79# the VM has to initialize the disk image on its first boot. Note that open access is still not
80# granted because the files are expected to be opened by the owner of the VM (apps or shell in case
81# when the vm is created by the `vm` tool) and handed over to crosvm as FD.
82allow crosvm shell_data_file:file write;
Jiyong Park3fee5a42021-08-09 09:24:45 +090083
Inseob Kim42798af2023-01-13 14:08:16 +090084# crosvm tries to read serial device, including the write-only pipe from virtualizationmanager (to
85# forward console/log to the host logcat).
86# crosvm only needs write permission, so dontaudit read
Inseob Kimbbe514d2023-08-03 12:53:48 +090087dontaudit crosvm virtualizationmanager:fifo_file { read getattr };
Inseob Kim42798af2023-01-13 14:08:16 +090088
Nikita Ioffe40a48c12023-02-14 23:17:55 +000089# Required for crosvm to start gdb-server to enable debugging of guest kernel.
90allow crosvm self:tcp_socket { bind create read setopt write accept listen };
91allow crosvm port:tcp_socket name_bind;
92allow crosvm adbd:unix_stream_socket ioctl;
93allow crosvm node:tcp_socket node_bind;
94
Inseob Kim825056d2023-08-01 11:00:49 +090095# Allow crosvm to interact to VFIO device
96allow crosvm vfio_device:chr_file rw_file_perms;
97allow crosvm vfio_device:dir r_dir_perms;
98
Inseob Kimbbe514d2023-08-03 12:53:48 +090099# Allow crosvm to access VM DTBO via a file created by virtualizationmanager.
100allow crosvm virtualizationmanager:fd use;
101allow crosvm virtualizationservice_data_file:file read;
Inseob Kim825056d2023-08-01 11:00:49 +0900102
Alan Stokes30608522022-10-24 12:32:34 +0100103# Don't allow crosvm to open files that it doesn't own.
104# This is important because a malicious application could try to start a VM with a composite disk
105# image referring by name to files which it doesn't have permission to open, trying to get crosvm to
106# open them on its behalf. By preventing crosvm from opening any other files we prevent this
107# potential privilege escalation. See http://b/192453819 for more discussion.
108neverallow crosvm {
109 virtualizationservice_data_file
110 staging_data_file
111 apk_data_file
112 app_data_file
113 privapp_data_file
114 userdebug_or_eng(`-shell_data_file')
115}:file open;
116
Jiyong Park3fee5a42021-08-09 09:24:45 +0900117# Don't allow crosvm to have access to ordinary vendor files that are not for VMs.
118full_treble_only(`
119 neverallow crosvm {
120 vendor_file_type
121 -vendor_vm_file
122 -vendor_vm_data_file
123 # These types are not required for crosvm, but the access is granted to globally in domain.te
124 # thus should be exempted here.
125 -vendor_configs_file
126 -vndk_sp_file
127 -vendor_task_profiles_file
128 }:file *;
129')
Jiyong Park028e7222021-11-26 00:59:07 +0900130
Alan Stokes30608522022-10-24 12:32:34 +0100131# Only allow crosvm to read app data files for clients that can start
132# VMs. Note that the use of app data files is further restricted
133# inside the virtualizationservice by checking the label of all disk
134# image files.
Jiyong Park028e7222021-11-26 00:59:07 +0900135neverallow crosvm {
136 app_data_file_type
137 -app_data_file
Alan Stokes30608522022-10-24 12:32:34 +0100138 -privapp_data_file
Jiyong Parkcdd5e072022-04-19 11:48:32 +0900139 -shell_data_file
Jiyong Park028e7222021-11-26 00:59:07 +0900140}:file read;
Inseob Kimb20cb782022-02-03 15:30:26 +0900141
David Brazdil55d808c2022-12-15 13:38:42 +0000142# Only virtualizationmanager can run crosvm
Inseob Kimb20cb782022-02-03 15:30:26 +0900143neverallow {
144 domain
145 -crosvm
David Brazdil55d808c2022-12-15 13:38:42 +0000146 -virtualizationmanager
Inseob Kimb20cb782022-02-03 15:30:26 +0900147} crosvm_exec:file no_x_file_perms;