xref: /aosp_15_r20/system/sepolicy/prebuilts/api/202404/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
180#
181# Also rename per-user encrypted directories such as /data/user/10 from their
182# temporary name ("10.new") to their final name ("10").
183allow vold {
184    system_data_file
185    system_data_root_file
186}:dir { create_dir_perms mounton };
187allow vold system_data_file:lnk_file getattr;
188
189# Vold create users in /data/vendor_{ce,de}/[0-9]+
190allow vold vendor_data_file:dir create_dir_perms;
191
192# for secdiscard
193allow vold system_data_file:file read;
194
195# Set scheduling policy of kernel processes
196allow vold kernel:process setsched;
197
198# ASEC
199allow vold asec_image_file:file create_file_perms;
200allow vold asec_image_file:dir rw_dir_perms;
201allow vold asec_apk_file:dir { create_dir_perms mounton relabelfrom relabelto };
202allow vold asec_public_file:dir { relabelto setattr };
203allow vold asec_apk_file:file { r_file_perms setattr relabelfrom relabelto };
204allow vold asec_public_file:file { relabelto setattr };
205# restorecon files in asec containers created on 4.2 or earlier.
206allow vold unlabeled:dir { r_dir_perms setattr relabelfrom };
207allow vold unlabeled:file { r_file_perms setattr relabelfrom };
208
209# Access to FUSE control filesystem to hard-abort FUSE mounts
210allow vold fusectlfs:file rw_file_perms;
211allow vold fusectlfs:dir rw_dir_perms;
212
213# Allow vold to use wake locks.  Needed for idle maintenance and moving storage.
214wakelock_use(vold)
215
216# Allow vold to publish a binder service and make binder calls.
217binder_use(vold)
218add_service(vold, vold_service)
219
220# Allow vold to call into the system server so it can check permissions.
221binder_call(vold, system_server)
222allow vold permission_service:service_manager find;
223
224# talk to health storage HAL
225hal_client_domain(vold, hal_health_storage)
226
227# talk to bootloader HAL
228full_treble_only(`hal_client_domain(vold, hal_bootctl)')
229
230# Access userdata block device.
231allow vold userdata_block_device:blk_file rw_file_perms;
232allowxperm vold userdata_block_device:blk_file ioctl BLKSECDISCARD;
233
234# Access zoned block device.
235allow vold zoned_block_device:blk_file rw_file_perms;
236
237# Access metadata block device used for encryption meta-data.
238allow vold metadata_block_device:blk_file rw_file_perms;
239allowxperm vold metadata_block_device:blk_file ioctl BLKSECDISCARD;
240
241# Allow vold to manipulate /data/unencrypted
242allow vold unencrypted_data_file:{ file } create_file_perms;
243allow vold unencrypted_data_file:dir create_dir_perms;
244
245# Write to /proc/sys/vm/drop_caches
246allow vold proc_drop_caches:file w_file_perms;
247
248# Give vold a place where only vold can store files; everyone else is off limits
249allow vold vold_data_file:dir create_dir_perms;
250allow vold vold_data_file:file create_file_perms;
251
252# And a similar place in the metadata partition
253allow vold vold_metadata_file:dir create_dir_perms;
254allow vold vold_metadata_file:file create_file_perms;
255
256# linux keyring configuration
257allow vold init:key { write search setattr };
258allow vold vold:key { write search setattr };
259
260# vold temporarily changes its priority when running benchmarks
261allow vold self:global_capability_class_set sys_nice;
262
263# vold needs to chroot into app namespaces to remount when runtime permissions change
264allow vold self:global_capability_class_set sys_chroot;
265allow vold storage_file:dir mounton;
266
267# For AppFuse.
268allow vold fuse_device:chr_file rw_file_perms;
269allow vold fuse:filesystem { relabelfrom };
270allow vold app_fusefs:filesystem { relabelfrom relabelto };
271allow vold app_fusefs:filesystem { mount unmount };
272allow vold app_fuse_file:dir rw_dir_perms;
273allow vold app_fuse_file:file { read write open getattr append };
274
275# MoveStorage.cpp executes cp and rm
276allow vold toolbox_exec:file rx_file_perms;
277
278# Prepare profile dir for users.
279allow vold { user_profile_data_file user_profile_root_file }:dir create_dir_perms;
280
281# Raw writes to misc block device
282allow vold misc_block_device:blk_file w_file_perms;
283
284# vold might need to search or mount /mnt/vendor/*
285allow vold mnt_vendor_file:dir search;
286
287dontaudit vold self:global_capability_class_set sys_resource;
288
289# Allow ReadDefaultFstab().
290read_fstab(vold)
291
292# vold might need to search loopback apex files
293allow vold vendor_apex_file:file r_file_perms;
294
295neverallow {
296    domain
297    -vold
298    -vold_prepare_subdirs
299} vold_data_file:dir ~{ open create read getattr setattr search relabelfrom relabelto ioctl };
300
301neverallow {
302    domain
303    -init
304    -vold
305    -vold_prepare_subdirs
306} vold_data_file:dir *;
307
308neverallow {
309    domain
310    -init
311    -vold
312} vold_metadata_file:dir *;
313
314neverallow {
315    domain
316    -kernel
317    -vold
318    -vold_prepare_subdirs
319} vold_data_file:notdevfile_class_set ~{ relabelto getattr };
320
321neverallow {
322    domain
323    -init
324    -vold
325    -vold_prepare_subdirs
326} vold_metadata_file:notdevfile_class_set ~{ relabelto getattr };
327
328neverallow {
329    domain
330    -init
331    -kernel
332    -vold
333    -vold_prepare_subdirs
334} { vold_data_file vold_metadata_file }:notdevfile_class_set *;
335
336neverallow { domain -vold -init } restorecon_prop:property_service set;
337
338neverallow vold {
339  domain
340  -hal_health_storage_server
341  -hal_keymaster_server
342  -system_suspend_server
343  -hal_bootctl_server
344  -hwservicemanager
345  -keystore
346  -servicemanager
347  -system_server
348  userdebug_or_eng(`-su')
349}:binder call;
350
351neverallow vold fsck_exec:file execute_no_trans;
352neverallow { domain -init } vold:process { transition dyntransition };
353neverallow vold *:process ptrace;
354neverallow vold *:rawip_socket *;
355