1# installer daemon
2type installd, domain;
3type installd_exec, system_file_type, exec_type, file_type;
4typeattribute installd mlstrustedsubject;
5allow installd self:global_capability_class_set { chown dac_override dac_read_search fowner fsetid setgid setuid sys_admin };
6
7# Allow labeling of files under /data/app/com.example/oat/
8allow installd dalvikcache_data_file:dir relabelto;
9allow installd dalvikcache_data_file:file { relabelto link };
10
11# Allow movement of APK files between volumes
12allow installd apk_data_file:dir { create_dir_perms relabelfrom };
13allow installd apk_data_file:file { create_file_perms relabelfrom link };
14allow installd apk_data_file:lnk_file { create r_file_perms unlink };
15
16# FS_IOC_ENABLE_VERITY and FS_IOC_MEASURE_VERITY (or in old implementation used in installd,
17# FS_IOC_SET_VERITY_MEASUREMENT) ioctls on APKs in /data/app, to support fsverity.
18# TODO(b/120629632): this path is deprecated, remove when possible.
19allowxperm installd apk_data_file:file ioctl {
20  FS_IOC_ENABLE_VERITY FS_IOC_MEASURE_VERITY
21};
22
23allow installd asec_apk_file:file r_file_perms;
24allow installd apk_tmp_file:file { r_file_perms unlink };
25allow installd apk_tmp_file:dir { relabelfrom create_dir_perms };
26allow installd oemfs:dir r_dir_perms;
27allow installd oemfs:file r_file_perms;
28allow installd cgroup:dir create_dir_perms;
29allow installd mnt_expand_file:dir { search getattr };
30# Check validity of SELinux context before use.
31selinux_check_context(installd)
32
33r_dir_file(installd, rootfs)
34# Scan through APKs in /system/app and /system/priv-app
35r_dir_file(installd, system_file)
36# Scan through APKs in /vendor/app
37r_dir_file(installd, vendor_app_file)
38# Scan through JARs in /vendor/framework
39r_dir_file(installd, vendor_framework_file)
40# Scan through Runtime Resource Overlay APKs in /vendor/overlay
41r_dir_file(installd, vendor_overlay_file)
42# Get file context
43allow installd file_contexts_file:file r_file_perms;
44# Get seapp_context
45allow installd seapp_contexts_file:file r_file_perms;
46
47# Search /data/app-asec and stat files in it.
48allow installd asec_image_file:dir search;
49allow installd asec_image_file:file getattr;
50
51# Create /data/user and /data/user/0 if necessary.
52# Also required to initially create /data/data subdirectories
53# and lib symlinks before the setfilecon call.  May want to
54# move symlink creation after setfilecon in installd.
55allow installd system_data_file:dir create_dir_perms;
56# Also, allow read for lnk_file so that we can process /data/user/0 links when
57# optimizing application code.
58allow installd system_data_file:lnk_file { create getattr read setattr unlink };
59
60# Upgrade /data/media for multi-user if necessary.
61allow installd media_rw_data_file:dir create_dir_perms;
62allow installd media_rw_data_file:file { getattr unlink };
63# restorecon new /data/media directory.
64allow installd system_data_file:dir relabelfrom;
65allow installd media_rw_data_file:dir relabelto;
66
67# Delete /data/media files through sdcardfs, instead of going behind its back
68allow installd tmpfs:dir r_dir_perms;
69allow installd storage_file:dir search;
70allow installd sdcard_type:dir { search open read write remove_name getattr rmdir };
71allow installd sdcard_type:file { getattr unlink };
72
73# Upgrade /data/misc/keychain for multi-user if necessary.
74allow installd misc_user_data_file:dir create_dir_perms;
75allow installd misc_user_data_file:file create_file_perms;
76allow installd keychain_data_file:dir create_dir_perms;
77allow installd keychain_data_file:file {r_file_perms unlink};
78
79# Create /data/.layout_version.* file
80allow installd install_data_file:file create_file_perms;
81
82# Create files under /data/dalvik-cache.
83allow installd dalvikcache_data_file:dir create_dir_perms;
84allow installd dalvikcache_data_file:file create_file_perms;
85allow installd dalvikcache_data_file:lnk_file getattr;
86
87# Create files under /data/resource-cache.
88allow installd resourcecache_data_file:dir rw_dir_perms;
89allow installd resourcecache_data_file:file create_file_perms;
90
91# Upgrade from unlabeled userdata.
92# Just need enough to remove and/or relabel it.
93allow installd unlabeled:dir { getattr search relabelfrom rw_dir_perms rmdir };
94allow installd unlabeled:notdevfile_class_set { getattr relabelfrom rename unlink setattr };
95# Read pkg.apk file for input during dexopt.
96allow installd unlabeled:file r_file_perms;
97
98# Upgrade from before system_app_data_file was used for system UID apps.
99# Just need enough to relabel it and to unlink removed package files.
100# Directory access covered by earlier rule above.
101allow installd system_data_file:notdevfile_class_set { getattr relabelfrom unlink };
102
103# Manage /data/data subdirectories, including initially labeling them
104# upon creation via setfilecon or running restorecon_recursive,
105# setting owner/mode, creating symlinks within them, and deleting them
106# upon package uninstall.
107# Types extracted from seapp_contexts type= fields.
108allow installd {
109    system_app_data_file
110    bluetooth_data_file
111    nfc_data_file
112    radio_data_file
113    shell_data_file
114    app_data_file
115    privapp_data_file
116}:dir { create_dir_perms relabelfrom relabelto };
117
118allow installd {
119    system_app_data_file
120    bluetooth_data_file
121    nfc_data_file
122    radio_data_file
123    shell_data_file
124    app_data_file
125    privapp_data_file
126}:notdevfile_class_set { create_file_perms relabelfrom relabelto };
127
128# Similar for the files under /data/misc/profiles/
129allow installd user_profile_data_file:dir create_dir_perms;
130allow installd user_profile_data_file:file create_file_perms;
131allow installd user_profile_data_file:dir rmdir;
132allow installd user_profile_data_file:file unlink;
133
134# Files created/updated by profman dumps.
135allow installd profman_dump_data_file:dir { search add_name write };
136allow installd profman_dump_data_file:file { create setattr open write };
137
138# Create and use pty created by android_fork_execvp().
139allow installd devpts:chr_file rw_file_perms;
140
141# execute toybox for app relocation
142allow installd toolbox_exec:file rx_file_perms;
143
144# Allow installd to publish a binder service and make binder calls.
145binder_use(installd)
146add_service(installd, installd_service)
147allow installd dumpstate:fifo_file  { getattr write };
148
149# Allow installd to call into the system server so it can check permissions.
150binder_call(installd, system_server)
151allow installd permission_service:service_manager find;
152
153# Allow installd to read and write quotas
154allow installd block_device:dir { search };
155allow installd labeledfs:filesystem { quotaget quotamod };
156
157# Allow installd to delete from /data/preloads when trimming data caches
158# TODO b/34690396 Remove when time-based purge policy for preloads is implemented in system_server
159allow installd preloads_data_file:file { r_file_perms unlink };
160allow installd preloads_data_file:dir { r_dir_perms write remove_name rmdir };
161allow installd preloads_media_file:file { r_file_perms unlink };
162allow installd preloads_media_file:dir { r_dir_perms write remove_name rmdir };
163
164###
165### Neverallow rules
166###
167
168# only system_server, installd and dumpstate may interact with installd over binder
169neverallow { domain -system_server -dumpstate -installd } installd_service:service_manager find;
170neverallow { domain -system_server -dumpstate } installd:binder call;
171neverallow installd {
172    domain
173    -ashmemd
174    -system_server
175    -servicemanager
176    userdebug_or_eng(`-su')
177}:binder call;
178