1# installer daemon
2type installd, domain, domain_deprecated;
3type installd_exec, exec_type, file_type;
4
5init_daemon_domain(installd)
6typeattribute installd mlstrustedsubject;
7allow installd self:capability { chown dac_override fowner fsetid setgid setuid };
8
9# Allow labeling of files under /data/app/com.example/oat/
10allow installd dalvikcache_data_file:dir relabelto;
11allow installd dalvikcache_data_file:file { relabelto link };
12
13# Allow movement of APK files between volumes
14allow installd apk_data_file:dir { create_dir_perms relabelfrom };
15allow installd apk_data_file:file { create_file_perms relabelfrom link };
16allow installd apk_data_file:lnk_file { create read unlink };
17
18allow installd asec_apk_file:file r_file_perms;
19allow installd apk_tmp_file:file { r_file_perms unlink };
20allow installd apk_tmp_file:dir { relabelfrom create_dir_perms };
21allow installd oemfs:dir r_dir_perms;
22allow installd oemfs:file r_file_perms;
23allow installd cgroup:dir create_dir_perms;
24allow installd mnt_expand_file:dir { search getattr };
25# Check validity of SELinux context before use.
26selinux_check_context(installd)
27# Read /seapp_contexts and /data/security/seapp_contexts
28security_access_policy(installd)
29
30# Search /data/app-asec and stat files in it.
31allow installd asec_image_file:dir search;
32allow installd asec_image_file:file getattr;
33
34# Create /data/user and /data/user/0 if necessary.
35# Also required to initially create /data/data subdirectories
36# and lib symlinks before the setfilecon call.  May want to
37# move symlink creation after setfilecon in installd.
38allow installd system_data_file:dir create_dir_perms;
39allow installd system_data_file:lnk_file { create setattr unlink };
40
41# Upgrade /data/media for multi-user if necessary.
42allow installd media_rw_data_file:dir create_dir_perms;
43allow installd media_rw_data_file:file { getattr unlink };
44# restorecon new /data/media directory.
45allow installd system_data_file:dir relabelfrom;
46allow installd media_rw_data_file:dir relabelto;
47
48# Upgrade /data/misc/keychain for multi-user if necessary.
49allow installd misc_user_data_file:dir create_dir_perms;
50allow installd misc_user_data_file:file create_file_perms;
51allow installd keychain_data_file:dir create_dir_perms;
52allow installd keychain_data_file:file {r_file_perms unlink};
53
54# Create /data/.layout_version.* file
55type_transition installd system_data_file:file install_data_file;
56allow installd install_data_file:file create_file_perms;
57
58# Create files under /data/dalvik-cache.
59allow installd dalvikcache_data_file:dir create_dir_perms;
60allow installd dalvikcache_data_file:file create_file_perms;
61
62# Create files under /data/resource-cache.
63allow installd resourcecache_data_file:dir rw_dir_perms;
64allow installd resourcecache_data_file:file create_file_perms;
65
66# Run dex2oat in its own sandbox.
67domain_auto_trans(installd, dex2oat_exec, dex2oat)
68
69# Run profman in its own sandbox.
70domain_auto_trans(installd, profman_exec, profman)
71
72# Run idmap in its own sandbox.
73domain_auto_trans(installd, idmap_exec, idmap)
74
75# Run otapreopt in its own sandbox.
76domain_auto_trans(installd, otapreopt_chroot_exec, otapreopt_chroot)
77# otapreopt_chroot will transition into postinstall_dexopt, which will spawn a child.
78allow installd postinstall_dexopt:process sigchld;
79
80# Upgrade from unlabeled userdata.
81# Just need enough to remove and/or relabel it.
82allow installd unlabeled:dir { getattr search relabelfrom rw_dir_perms rmdir };
83allow installd unlabeled:notdevfile_class_set { getattr relabelfrom rename unlink setattr };
84# Read pkg.apk file for input during dexopt.
85allow installd unlabeled:file r_file_perms;
86
87# Upgrade from before system_app_data_file was used for system UID apps.
88# Just need enough to relabel it and to unlink removed package files.
89# Directory access covered by earlier rule above.
90allow installd system_data_file:notdevfile_class_set { getattr relabelfrom unlink };
91
92# Manage /data/data subdirectories, including initially labeling them
93# upon creation via setfilecon or running restorecon_recursive,
94# setting owner/mode, creating symlinks within them, and deleting them
95# upon package uninstall.
96# Types extracted from seapp_contexts type= fields.
97allow installd {
98    system_app_data_file
99    bluetooth_data_file
100    nfc_data_file
101    radio_data_file
102    shell_data_file
103    app_data_file
104    autoplay_data_file
105}:dir { create_dir_perms relabelfrom relabelto };
106
107allow installd {
108    system_app_data_file
109    bluetooth_data_file
110    nfc_data_file
111    radio_data_file
112    shell_data_file
113    app_data_file
114    autoplay_data_file
115}:notdevfile_class_set { create_file_perms relabelfrom relabelto };
116
117# Similar for the files under /data/misc/profiles/
118allow installd user_profile_data_file:dir create_dir_perms;
119allow installd user_profile_data_file:file create_file_perms;
120allow installd user_profile_data_file:dir rmdir;
121allow installd user_profile_data_file:file unlink;
122allow installd user_profile_foreign_dex_data_file:dir { add_name getattr rmdir open read write search remove_name };
123allow installd user_profile_foreign_dex_data_file:file { getattr rename unlink };
124
125# Files created/updated by profman dumps.
126allow installd profman_dump_data_file:dir { search add_name write };
127allow installd profman_dump_data_file:file { create setattr open write };
128
129# Create and use pty created by android_fork_execvp().
130allow installd devpts:chr_file rw_file_perms;
131
132# execute toybox for app relocation
133allow installd toolbox_exec:file rx_file_perms;
134