xref: /aosp_15_r20/system/sepolicy/prebuilts/api/33.0/public/installd.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# installer daemon
2*e4a36f41SAndroid Build Coastguard Workertype installd, domain;
3*e4a36f41SAndroid Build Coastguard Workertype installd_exec, system_file_type, exec_type, file_type;
4*e4a36f41SAndroid Build Coastguard Workertypeattribute installd mlstrustedsubject;
5*e4a36f41SAndroid Build Coastguard Workerallow installd self:global_capability_class_set { chown dac_override dac_read_search fowner fsetid setgid setuid sys_admin kill };
6*e4a36f41SAndroid Build Coastguard Worker
7*e4a36f41SAndroid Build Coastguard Worker# Allow labeling of files under /data/app/com.example/oat/
8*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:dir relabelto;
9*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:file { relabelto link };
10*e4a36f41SAndroid Build Coastguard Worker
11*e4a36f41SAndroid Build Coastguard Worker# Allow movement of APK files between volumes
12*e4a36f41SAndroid Build Coastguard Workerallow installd apk_data_file:dir { create_dir_perms relabelfrom };
13*e4a36f41SAndroid Build Coastguard Workerallow installd apk_data_file:file { create_file_perms relabelfrom link };
14*e4a36f41SAndroid Build Coastguard Workerallow installd apk_data_file:lnk_file { create r_file_perms unlink };
15*e4a36f41SAndroid Build Coastguard Worker
16*e4a36f41SAndroid Build Coastguard Workerallow installd asec_apk_file:file r_file_perms;
17*e4a36f41SAndroid Build Coastguard Workerallow installd apk_tmp_file:file { r_file_perms unlink };
18*e4a36f41SAndroid Build Coastguard Workerallow installd apk_tmp_file:dir { relabelfrom create_dir_perms };
19*e4a36f41SAndroid Build Coastguard Workerallow installd oemfs:dir r_dir_perms;
20*e4a36f41SAndroid Build Coastguard Workerallow installd oemfs:file r_file_perms;
21*e4a36f41SAndroid Build Coastguard Workerallow installd cgroup:dir create_dir_perms;
22*e4a36f41SAndroid Build Coastguard Workerallow installd cgroup_v2:dir create_dir_perms;
23*e4a36f41SAndroid Build Coastguard Workerallow installd mnt_expand_file:dir { search getattr };
24*e4a36f41SAndroid Build Coastguard Worker# Check validity of SELinux context before use.
25*e4a36f41SAndroid Build Coastguard Workerselinux_check_context(installd)
26*e4a36f41SAndroid Build Coastguard Worker
27*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, rootfs)
28*e4a36f41SAndroid Build Coastguard Worker# Scan through APKs in /system/app and /system/priv-app
29*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, system_file)
30*e4a36f41SAndroid Build Coastguard Worker# Scan through APKs in /vendor/app
31*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, vendor_app_file)
32*e4a36f41SAndroid Build Coastguard Worker# Scan through JARs in /vendor/framework
33*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, vendor_framework_file)
34*e4a36f41SAndroid Build Coastguard Worker# Scan through Runtime Resource Overlay APKs in /vendor/overlay
35*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, vendor_overlay_file)
36*e4a36f41SAndroid Build Coastguard Worker# Get file context
37*e4a36f41SAndroid Build Coastguard Workerallow installd file_contexts_file:file r_file_perms;
38*e4a36f41SAndroid Build Coastguard Worker# Get seapp_context
39*e4a36f41SAndroid Build Coastguard Workerallow installd seapp_contexts_file:file r_file_perms;
40*e4a36f41SAndroid Build Coastguard Worker
41*e4a36f41SAndroid Build Coastguard Worker# Search /data/app-asec and stat files in it.
42*e4a36f41SAndroid Build Coastguard Workerallow installd asec_image_file:dir search;
43*e4a36f41SAndroid Build Coastguard Workerallow installd asec_image_file:file getattr;
44*e4a36f41SAndroid Build Coastguard Worker
45*e4a36f41SAndroid Build Coastguard Worker# Create /data/user and /data/user/0 if necessary.
46*e4a36f41SAndroid Build Coastguard Worker# Also required to initially create /data/data subdirectories
47*e4a36f41SAndroid Build Coastguard Worker# and lib symlinks before the setfilecon call.  May want to
48*e4a36f41SAndroid Build Coastguard Worker# move symlink creation after setfilecon in installd.
49*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:dir create_dir_perms;
50*e4a36f41SAndroid Build Coastguard Worker# Also, allow read for lnk_file so that we can process /data/user/0 links when
51*e4a36f41SAndroid Build Coastguard Worker# optimizing application code.
52*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:lnk_file { create getattr read setattr unlink };
53*e4a36f41SAndroid Build Coastguard Worker
54*e4a36f41SAndroid Build Coastguard Worker# Manage lower filesystem via pass_through mounts
55*e4a36f41SAndroid Build Coastguard Workerallow installd mnt_pass_through_file:dir r_dir_perms;
56*e4a36f41SAndroid Build Coastguard Worker
57*e4a36f41SAndroid Build Coastguard Worker# Upgrade /data/media for multi-user if necessary.
58*e4a36f41SAndroid Build Coastguard Workerallow installd media_rw_data_file:dir create_dir_perms;
59*e4a36f41SAndroid Build Coastguard Workerallow installd media_rw_data_file:file { getattr unlink };
60*e4a36f41SAndroid Build Coastguard Worker# restorecon new /data/media directory.
61*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:dir relabelfrom;
62*e4a36f41SAndroid Build Coastguard Workerallow installd media_rw_data_file:dir relabelto;
63*e4a36f41SAndroid Build Coastguard Worker
64*e4a36f41SAndroid Build Coastguard Worker# Delete /data/media files through sdcardfs, instead of going behind its back
65*e4a36f41SAndroid Build Coastguard Workerallow installd tmpfs:dir r_dir_perms;
66*e4a36f41SAndroid Build Coastguard Workerallow installd storage_file:dir search;
67*e4a36f41SAndroid Build Coastguard Workerallow installd { sdcard_type fuse }:dir { search open read write remove_name getattr rmdir };
68*e4a36f41SAndroid Build Coastguard Workerallow installd { sdcard_type fuse }:file { getattr unlink };
69*e4a36f41SAndroid Build Coastguard Worker
70*e4a36f41SAndroid Build Coastguard Worker# Create app's mirror data directory in /data_mirror, and bind mount the real directory to it
71*e4a36f41SAndroid Build Coastguard Workerallow installd mirror_data_file:dir { create_dir_perms mounton };
72*e4a36f41SAndroid Build Coastguard Worker
73*e4a36f41SAndroid Build Coastguard Worker# Upgrade /data/misc/keychain for multi-user if necessary.
74*e4a36f41SAndroid Build Coastguard Workerallow installd misc_user_data_file:dir create_dir_perms;
75*e4a36f41SAndroid Build Coastguard Workerallow installd misc_user_data_file:file create_file_perms;
76*e4a36f41SAndroid Build Coastguard Workerallow installd keychain_data_file:dir create_dir_perms;
77*e4a36f41SAndroid Build Coastguard Workerallow installd keychain_data_file:file {r_file_perms unlink};
78*e4a36f41SAndroid Build Coastguard Worker
79*e4a36f41SAndroid Build Coastguard Worker# Create /data/misc/installd/layout_version.* file
80*e4a36f41SAndroid Build Coastguard Workerallow installd install_data_file:file create_file_perms;
81*e4a36f41SAndroid Build Coastguard Workerallow installd install_data_file:dir rw_dir_perms;
82*e4a36f41SAndroid Build Coastguard Worker
83*e4a36f41SAndroid Build Coastguard Worker# Create files under /data/dalvik-cache.
84*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:dir create_dir_perms;
85*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:file create_file_perms;
86*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:lnk_file getattr;
87*e4a36f41SAndroid Build Coastguard Worker
88*e4a36f41SAndroid Build Coastguard Worker# Create files under /data/resource-cache.
89*e4a36f41SAndroid Build Coastguard Workerallow installd resourcecache_data_file:dir rw_dir_perms;
90*e4a36f41SAndroid Build Coastguard Workerallow installd resourcecache_data_file:file create_file_perms;
91*e4a36f41SAndroid Build Coastguard Worker
92*e4a36f41SAndroid Build Coastguard Worker# Upgrade from unlabeled userdata.
93*e4a36f41SAndroid Build Coastguard Worker# Just need enough to remove and/or relabel it.
94*e4a36f41SAndroid Build Coastguard Workerallow installd unlabeled:dir { getattr search relabelfrom rw_dir_perms rmdir };
95*e4a36f41SAndroid Build Coastguard Workerallow installd unlabeled:notdevfile_class_set { getattr relabelfrom rename unlink setattr };
96*e4a36f41SAndroid Build Coastguard Worker# Read pkg.apk file for input during dexopt.
97*e4a36f41SAndroid Build Coastguard Workerallow installd unlabeled:file r_file_perms;
98*e4a36f41SAndroid Build Coastguard Worker
99*e4a36f41SAndroid Build Coastguard Worker# Upgrade from before system_app_data_file was used for system UID apps.
100*e4a36f41SAndroid Build Coastguard Worker# Just need enough to relabel it and to unlink removed package files.
101*e4a36f41SAndroid Build Coastguard Worker# Directory access covered by earlier rule above.
102*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:notdevfile_class_set { getattr relabelfrom unlink };
103*e4a36f41SAndroid Build Coastguard Worker
104*e4a36f41SAndroid Build Coastguard Worker# Manage /data/data subdirectories, including initially labeling them
105*e4a36f41SAndroid Build Coastguard Worker# upon creation via setfilecon or running restorecon_recursive,
106*e4a36f41SAndroid Build Coastguard Worker# setting owner/mode, creating symlinks within them, and deleting them
107*e4a36f41SAndroid Build Coastguard Worker# upon package uninstall.
108*e4a36f41SAndroid Build Coastguard Workerallow installd app_data_file_type:dir { create_dir_perms relabelfrom relabelto };
109*e4a36f41SAndroid Build Coastguard Workerallow installd app_data_file_type:notdevfile_class_set { create_file_perms relabelfrom relabelto };
110*e4a36f41SAndroid Build Coastguard Worker
111*e4a36f41SAndroid Build Coastguard Worker# Allow setting extended attributes (for project quota IDs) on dirs and files
112*e4a36f41SAndroid Build Coastguard Worker# and to enable project ID inheritance through FS_IOC_SETFLAGS
113*e4a36f41SAndroid Build Coastguard Worker# Added install_data_file to be able to create file under /data/misc/installd/ioctl_check
114*e4a36f41SAndroid Build Coastguard Workerallowxperm installd { app_data_file_type system_data_file install_data_file}:{ dir file } ioctl {
115*e4a36f41SAndroid Build Coastguard Worker  FS_IOC_FSGETXATTR
116*e4a36f41SAndroid Build Coastguard Worker  FS_IOC_FSSETXATTR
117*e4a36f41SAndroid Build Coastguard Worker  FS_IOC_GETFLAGS
118*e4a36f41SAndroid Build Coastguard Worker  FS_IOC_SETFLAGS
119*e4a36f41SAndroid Build Coastguard Worker};
120*e4a36f41SAndroid Build Coastguard Worker
121*e4a36f41SAndroid Build Coastguard Worker# Similar for the files under /data/misc/profiles/
122*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_root_file:dir { create_dir_perms relabelfrom };
123*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_data_file:dir { create_dir_perms relabelto };
124*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_data_file:file create_file_perms;
125*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_data_file:file unlink;
126*e4a36f41SAndroid Build Coastguard Worker
127*e4a36f41SAndroid Build Coastguard Worker# Allow zygote to unmount mirror directories
128*e4a36f41SAndroid Build Coastguard Workerallow installd labeledfs:filesystem unmount;
129*e4a36f41SAndroid Build Coastguard Worker
130*e4a36f41SAndroid Build Coastguard Worker# Files created/updated by profman dumps.
131*e4a36f41SAndroid Build Coastguard Workerallow installd profman_dump_data_file:dir { search add_name write };
132*e4a36f41SAndroid Build Coastguard Workerallow installd profman_dump_data_file:file { create setattr open write };
133*e4a36f41SAndroid Build Coastguard Worker
134*e4a36f41SAndroid Build Coastguard Worker# Create and use pty created by android_fork_execvp().
135*e4a36f41SAndroid Build Coastguard Workerallow installd devpts:chr_file rw_file_perms;
136*e4a36f41SAndroid Build Coastguard Worker
137*e4a36f41SAndroid Build Coastguard Worker# execute toybox for app relocation
138*e4a36f41SAndroid Build Coastguard Workerallow installd toolbox_exec:file rx_file_perms;
139*e4a36f41SAndroid Build Coastguard Worker
140*e4a36f41SAndroid Build Coastguard Worker# Allow installd to publish a binder service and make binder calls.
141*e4a36f41SAndroid Build Coastguard Workerbinder_use(installd)
142*e4a36f41SAndroid Build Coastguard Workeradd_service(installd, installd_service)
143*e4a36f41SAndroid Build Coastguard Workerallow installd dumpstate:fifo_file  { getattr write };
144*e4a36f41SAndroid Build Coastguard Worker
145*e4a36f41SAndroid Build Coastguard Worker# Allow installd to call into the system server so it can check permissions.
146*e4a36f41SAndroid Build Coastguard Workerbinder_call(installd, system_server)
147*e4a36f41SAndroid Build Coastguard Workerallow installd permission_service:service_manager find;
148*e4a36f41SAndroid Build Coastguard Worker
149*e4a36f41SAndroid Build Coastguard Worker# Allow installd to read and write quotas
150*e4a36f41SAndroid Build Coastguard Workerallow installd block_device:dir { search };
151*e4a36f41SAndroid Build Coastguard Workerallow installd labeledfs:filesystem { quotaget quotamod };
152*e4a36f41SAndroid Build Coastguard Worker
153*e4a36f41SAndroid Build Coastguard Worker# Allow installd to delete from /data/preloads when trimming data caches
154*e4a36f41SAndroid Build Coastguard Worker# TODO b/34690396 Remove when time-based purge policy for preloads is implemented in system_server
155*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_data_file:file { r_file_perms unlink };
156*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_data_file:dir { r_dir_perms write remove_name rmdir };
157*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_media_file:file { r_file_perms unlink };
158*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_media_file:dir { r_dir_perms write remove_name rmdir };
159*e4a36f41SAndroid Build Coastguard Worker
160*e4a36f41SAndroid Build Coastguard Worker# Allow installd to read /proc/filesystems
161*e4a36f41SAndroid Build Coastguard Workerallow installd proc_filesystems:file r_file_perms;
162*e4a36f41SAndroid Build Coastguard Worker
163*e4a36f41SAndroid Build Coastguard Worker#add for move app to sd card
164*e4a36f41SAndroid Build Coastguard Workerget_prop(installd, storage_config_prop)
165*e4a36f41SAndroid Build Coastguard Worker
166*e4a36f41SAndroid Build Coastguard Worker# Allow installd to access apps installed on the Incremental File System
167*e4a36f41SAndroid Build Coastguard Worker# Accessing files on the Incremental File System uses fds opened in the context of vold.
168*e4a36f41SAndroid Build Coastguard Workerallow installd vold:fd use;
169*e4a36f41SAndroid Build Coastguard Worker
170*e4a36f41SAndroid Build Coastguard Worker###
171*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules
172*e4a36f41SAndroid Build Coastguard Worker###
173*e4a36f41SAndroid Build Coastguard Worker
174*e4a36f41SAndroid Build Coastguard Worker# only system_server, installd, dumpstate, and servicemanager may interact with installd over binder
175*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server -dumpstate -installd } installd_service:service_manager find;
176*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server -dumpstate -servicemanager } installd:binder call;
177*e4a36f41SAndroid Build Coastguard Workerneverallow installd {
178*e4a36f41SAndroid Build Coastguard Worker    domain
179*e4a36f41SAndroid Build Coastguard Worker    -system_server
180*e4a36f41SAndroid Build Coastguard Worker    -servicemanager
181*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-su')
182*e4a36f41SAndroid Build Coastguard Worker}:binder call;
183