xref: /aosp_15_r20/system/sepolicy/prebuilts/api/34.0/public/vold.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1# volume manager
2type vold, domain;
3type vold_exec, exec_type, file_type, system_file_type;
4
5# Read already opened /cache files.
6allow vold cache_file:dir r_dir_perms;
7allow vold cache_file:file { getattr read };
8allow vold cache_file:lnk_file r_file_perms;
9
10r_dir_file(vold, { sysfs_type -sysfs_batteryinfo })
11# XXX Label sysfs files with a specific type?
12allow vold {
13  sysfs # writing to /sys/*/uevent during coldboot.
14  sysfs_devices_block
15  sysfs_dm
16  sysfs_loop # writing to /sys/block/loop*/uevent during coldboot.
17  sysfs_usb
18  sysfs_zram_uevent
19  sysfs_fs_f2fs
20}:file w_file_perms;
21
22r_dir_file(vold, rootfs)
23r_dir_file(vold, metadata_file)
24allow vold {
25  proc # b/67049235 processes /proc/<pid>/* files are mislabeled.
26  proc_bootconfig
27  proc_cmdline
28  proc_drop_caches
29  proc_filesystems
30  proc_meminfo
31  proc_mounts
32}:file r_file_perms;
33
34#Get file contexts
35allow vold file_contexts_file:file r_file_perms;
36
37# Allow us to jump into execution domains of above tools
38allow vold self:process setexec;
39
40# For formatting adoptable storage devices
41allow vold e2fs_exec:file rx_file_perms;
42
43# Run fstrim on mounted partitions
44# allowxperm still requires the ioctl permission for the individual type
45allowxperm vold { fs_type file_type }:dir ioctl FITRIM;
46
47# Get/set file-based encryption policies on dirs in /data and adoptable storage,
48# and add/remove file-based encryption keys.
49allowxperm vold data_file_type:dir ioctl {
50  FS_IOC_GET_ENCRYPTION_POLICY
51  FS_IOC_SET_ENCRYPTION_POLICY
52  FS_IOC_ADD_ENCRYPTION_KEY
53  FS_IOC_REMOVE_ENCRYPTION_KEY
54  FS_IOC_GET_ENCRYPTION_KEY_STATUS
55};
56
57# Only vold and init should ever set file-based encryption policies.
58neverallowxperm {
59  domain
60  -vold
61  -init
62  -vendor_init
63} data_file_type:dir ioctl { FS_IOC_SET_ENCRYPTION_POLICY };
64
65# Only vold should ever add/remove file-based encryption keys.
66neverallowxperm {
67  domain
68  -vold
69} data_file_type:dir ioctl { FS_IOC_ADD_ENCRYPTION_KEY FS_IOC_REMOVE_ENCRYPTION_KEY FS_IOC_GET_ENCRYPTION_KEY_STATUS };
70
71# Allow securely erasing crypto key files. F2FS_IOC_SEC_TRIM_FILE is
72# tried first. Otherwise, FS_IOC_FIEMAP is needed to get the
73# location of the file's blocks on the raw block device to erase.
74allowxperm vold {
75  vold_data_file
76  vold_metadata_file
77}:file ioctl {
78  F2FS_IOC_SEC_TRIM_FILE
79  FS_IOC_FIEMAP
80};
81
82typeattribute vold mlstrustedsubject;
83allow vold self:process setfscreate;
84allow vold system_file:file x_file_perms;
85not_full_treble(`allow vold vendor_file:file x_file_perms;')
86allow vold block_device:dir create_dir_perms;
87allow vold device:dir write;
88allow vold devpts:chr_file rw_file_perms;
89allow vold rootfs:dir mounton;
90allow vold { sdcard_type fuse }:dir mounton; # TODO: deprecated in M
91allow vold { sdcard_type fuse }:filesystem { mount remount unmount }; # TODO: deprecated in M
92
93# Manage locations where storage is mounted
94allow vold { mnt_media_rw_file storage_file sdcard_type fuse }:dir create_dir_perms;
95allow vold { mnt_media_rw_file storage_file sdcard_type fuse }:file create_file_perms;
96
97# Access to storage that backs emulated FUSE daemons for migration optimization
98allow vold media_rw_data_file:dir create_dir_perms;
99allow vold media_rw_data_file:file create_file_perms;
100# Allow mounting (lower filesystem) on parts of media for performance
101allow vold media_rw_data_file:dir mounton;
102
103# Allow setting project quota IDs and enabling project ID inheritance on
104# /data/media/$userId/* and /mnt/expand/$volume/media/$userId/*
105allowxperm vold media_rw_data_file:{ dir file } ioctl {
106  FS_IOC_FSGETXATTR
107  FS_IOC_FSSETXATTR
108  FS_IOC_GETFLAGS
109  FS_IOC_SETFLAGS
110};
111
112# Allow mounting of storage devices
113allow vold { mnt_media_rw_stub_file storage_stub_file }:dir { mounton create rmdir getattr setattr };
114
115# Manage per-user primary symlinks
116allow vold mnt_user_file:dir { create_dir_perms mounton };
117allow vold mnt_user_file:lnk_file create_file_perms;
118allow vold mnt_user_file:file create_file_perms;
119
120# Manage per-user pass_through primary symlinks
121allow vold mnt_pass_through_file:dir { create_dir_perms mounton };
122allow vold mnt_pass_through_file:lnk_file create_file_perms;
123
124# Allow to create and mount expanded storage
125allow vold mnt_expand_file:dir { create_dir_perms mounton };
126allow vold apk_data_file:dir { create getattr setattr };
127allow vold shell_data_file:dir { create getattr setattr };
128allow vold system_userdir_file:dir { create getattr setattr };
129allow vold media_userdir_file:dir { create getattr setattr open read ioctl };
130# Needed to set the casefold flag on /mnt/expand/$volume/media
131allowxperm vold media_userdir_file:dir ioctl { FS_IOC_GETFLAGS FS_IOC_SETFLAGS };
132
133# Allow to mount incremental file system on /data/incremental and create files
134allow vold apk_data_file:dir { mounton rw_dir_perms };
135# Allow to create and write files in /data/incremental
136allow vold apk_data_file:file { rw_file_perms unlink };
137# Allow to bind-mount incremental file system on /data/app/vmdl*.tmp and read files
138allow vold apk_tmp_file:dir { mounton r_dir_perms };
139# Allow to read incremental control file and call selinux restorecon on it
140allow vold incremental_control_file:file { r_file_perms relabelto };
141
142allow vold tmpfs:filesystem { mount unmount };
143allow vold tmpfs:dir create_dir_perms;
144allow vold tmpfs:dir mounton;
145allow vold self:global_capability_class_set { net_admin dac_override dac_read_search mknod sys_admin chown fowner fsetid };
146allow vold self:netlink_kobject_uevent_socket create_socket_perms_no_ioctl;
147allow vold loop_control_device:chr_file rw_file_perms;
148allow vold loop_device:blk_file { create setattr unlink rw_file_perms };
149allowxperm vold loop_device:blk_file ioctl {
150  LOOP_CLR_FD
151  LOOP_CTL_GET_FREE
152  LOOP_GET_STATUS64
153  LOOP_SET_FD
154  LOOP_SET_STATUS64
155};
156allow vold vold_device:blk_file { create setattr unlink rw_file_perms };
157allowxperm vold vold_device:blk_file ioctl { BLKDISCARD BLKGETSIZE };
158allow vold dm_device:chr_file rw_file_perms;
159allow vold dm_device:blk_file rw_file_perms;
160allowxperm vold dm_device:blk_file ioctl { BLKDISCARD BLKSECDISCARD BLKREPORTZONE BLKRESETZONE };
161# For vold Process::killProcessesWithOpenFiles function.
162allow vold domain:dir r_dir_perms;
163allow vold domain:{ file lnk_file } r_file_perms;
164allow vold domain:process { signal sigkill };
165allow vold self:global_capability_class_set { sys_ptrace kill };
166
167allow vold kmsg_device:chr_file rw_file_perms;
168
169# Run fsck in the fsck domain.
170allow vold fsck_exec:file { r_file_perms execute };
171
172# Log fsck results
173allow vold fscklogs:dir rw_dir_perms;
174allow vold fscklogs:file create_file_perms;
175
176# Mount and unmount filesystems.
177allow vold labeledfs:filesystem { mount unmount remount };
178
179# Create and mount on /data/tmp_mnt and management of expansion mounts
180allow vold {
181    system_data_file
182    system_data_root_file
183}:dir { create rw_dir_perms mounton setattr rmdir };
184allow vold system_data_file:lnk_file getattr;
185
186# Vold create users in /data/vendor_{ce,de}/[0-9]+
187allow vold vendor_data_file:dir create_dir_perms;
188
189# for secdiscard
190allow vold system_data_file:file read;
191
192# Set scheduling policy of kernel processes
193allow vold kernel:process setsched;
194
195# ASEC
196allow vold asec_image_file:file create_file_perms;
197allow vold asec_image_file:dir rw_dir_perms;
198allow vold asec_apk_file:dir { create_dir_perms mounton relabelfrom relabelto };
199allow vold asec_public_file:dir { relabelto setattr };
200allow vold asec_apk_file:file { r_file_perms setattr relabelfrom relabelto };
201allow vold asec_public_file:file { relabelto setattr };
202# restorecon files in asec containers created on 4.2 or earlier.
203allow vold unlabeled:dir { r_dir_perms setattr relabelfrom };
204allow vold unlabeled:file { r_file_perms setattr relabelfrom };
205
206# Access to FUSE control filesystem to hard-abort FUSE mounts
207allow vold fusectlfs:file rw_file_perms;
208allow vold fusectlfs:dir rw_dir_perms;
209
210# Allow vold to use wake locks.  Needed for idle maintenance and moving storage.
211wakelock_use(vold)
212
213# Allow vold to publish a binder service and make binder calls.
214binder_use(vold)
215add_service(vold, vold_service)
216
217# Allow vold to call into the system server so it can check permissions.
218binder_call(vold, system_server)
219allow vold permission_service:service_manager find;
220
221# talk to health storage HAL
222hal_client_domain(vold, hal_health_storage)
223
224# talk to bootloader HAL
225full_treble_only(`hal_client_domain(vold, hal_bootctl)')
226
227# Access userdata block device.
228allow vold userdata_block_device:blk_file rw_file_perms;
229allowxperm vold userdata_block_device:blk_file ioctl BLKSECDISCARD;
230
231# Access zoned block device.
232allow vold zoned_block_device:blk_file rw_file_perms;
233
234# Access metadata block device used for encryption meta-data.
235allow vold metadata_block_device:blk_file rw_file_perms;
236allowxperm vold metadata_block_device:blk_file ioctl BLKSECDISCARD;
237
238# Allow vold to manipulate /data/unencrypted
239allow vold unencrypted_data_file:{ file } create_file_perms;
240allow vold unencrypted_data_file:dir create_dir_perms;
241
242# Write to /proc/sys/vm/drop_caches
243allow vold proc_drop_caches:file w_file_perms;
244
245# Give vold a place where only vold can store files; everyone else is off limits
246allow vold vold_data_file:dir create_dir_perms;
247allow vold vold_data_file:file create_file_perms;
248
249# And a similar place in the metadata partition
250allow vold vold_metadata_file:dir create_dir_perms;
251allow vold vold_metadata_file:file create_file_perms;
252
253# linux keyring configuration
254allow vold init:key { write search setattr };
255allow vold vold:key { write search setattr };
256
257# vold temporarily changes its priority when running benchmarks
258allow vold self:global_capability_class_set sys_nice;
259
260# vold needs to chroot into app namespaces to remount when runtime permissions change
261allow vold self:global_capability_class_set sys_chroot;
262allow vold storage_file:dir mounton;
263
264# For AppFuse.
265allow vold fuse_device:chr_file rw_file_perms;
266allow vold fuse:filesystem { relabelfrom };
267allow vold app_fusefs:filesystem { relabelfrom relabelto };
268allow vold app_fusefs:filesystem { mount unmount };
269allow vold app_fuse_file:dir rw_dir_perms;
270allow vold app_fuse_file:file { read write open getattr append };
271
272# MoveStorage.cpp executes cp and rm
273allow vold toolbox_exec:file rx_file_perms;
274
275# Prepare profile dir for users.
276allow vold { user_profile_data_file user_profile_root_file }:dir create_dir_perms;
277
278# Raw writes to misc block device
279allow vold misc_block_device:blk_file w_file_perms;
280
281# vold might need to search or mount /mnt/vendor/*
282allow vold mnt_vendor_file:dir search;
283
284dontaudit vold self:global_capability_class_set sys_resource;
285
286# Allow ReadDefaultFstab().
287read_fstab(vold)
288
289# vold might need to search loopback apex files
290allow vold vendor_apex_file:file r_file_perms;
291
292neverallow {
293    domain
294    -vold
295    -vold_prepare_subdirs
296} vold_data_file:dir ~{ open create read getattr setattr search relabelfrom relabelto ioctl };
297
298neverallow {
299    domain
300    -init
301    -vold
302    -vold_prepare_subdirs
303} vold_data_file:dir *;
304
305neverallow {
306    domain
307    -init
308    -vold
309} vold_metadata_file:dir *;
310
311neverallow {
312    domain
313    -kernel
314    -vold
315    -vold_prepare_subdirs
316} vold_data_file:notdevfile_class_set ~{ relabelto getattr };
317
318neverallow {
319    domain
320    -init
321    -vold
322    -vold_prepare_subdirs
323} vold_metadata_file:notdevfile_class_set ~{ relabelto getattr };
324
325neverallow {
326    domain
327    -init
328    -kernel
329    -vold
330    -vold_prepare_subdirs
331} { vold_data_file vold_metadata_file }:notdevfile_class_set *;
332
333neverallow { domain -vold -init } restorecon_prop:property_service set;
334
335neverallow vold {
336  domain
337  -hal_health_storage_server
338  -system_suspend_server
339  -hal_bootctl_server
340  -hwservicemanager
341  -keystore
342  -servicemanager
343  -system_server
344  userdebug_or_eng(`-su')
345}:binder call;
346
347neverallow vold fsck_exec:file execute_no_trans;
348neverallow { domain -init } vold:process { transition dyntransition };
349neverallow vold *:process ptrace;
350neverallow vold *:rawip_socket *;
351