• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1typeattribute apexd coredomain;
2
3init_daemon_domain(apexd)
4
5# Allow creating, reading and writing of APEX files/dirs in the APEX data dir
6allow apexd apex_data_file:dir create_dir_perms;
7allow apexd apex_data_file:file create_file_perms;
8# Allow relabeling file created in /data/apex/decompressed
9allow apexd apex_data_file:file relabelfrom;
10
11# Allow creating, reading and writing of APEX files/dirs in the APEX metadata dir
12allow apexd metadata_file:dir search;
13allow apexd apex_metadata_file:dir create_dir_perms;
14allow apexd apex_metadata_file:file create_file_perms;
15
16# Allow reserving space on /data/apex/ota_reserved for apex decompression
17allow apexd apex_ota_reserved_file:dir create_dir_perms;
18allow apexd apex_ota_reserved_file:file create_file_perms;
19
20# Allow apexd to create files and directories for snapshots of apex data
21allow apexd apex_data_file_type:dir { create_dir_perms relabelto };
22allow apexd apex_data_file_type:file { create_file_perms relabelto };
23allow apexd apex_module_data_file:dir { create_dir_perms relabelfrom };
24allow apexd apex_module_data_file:file { create_file_perms relabelfrom };
25allow apexd apex_rollback_data_file:dir create_dir_perms;
26allow apexd apex_rollback_data_file:file create_file_perms;
27
28# Allow apexd to read /data/misc_de and the directories under it, in order to
29# snapshot and restore apex data for all users.
30allow apexd {
31    system_userdir_file
32    system_data_file
33}:dir r_dir_perms;
34
35# allow apexd to create loop devices with /dev/loop-control
36allow apexd loop_control_device:chr_file rw_file_perms;
37# allow apexd to access loop devices
38allow apexd loop_device:blk_file rw_file_perms;
39allowxperm apexd loop_device:blk_file ioctl {
40  LOOP_GET_STATUS64
41  LOOP_SET_STATUS64
42  LOOP_SET_FD
43  LOOP_SET_BLOCK_SIZE
44  LOOP_SET_DIRECT_IO
45  LOOP_CLR_FD
46  BLKFLSBUF
47  LOOP_CONFIGURE
48};
49# Allow apexd to access /dev/block
50allow apexd dev_type:dir r_dir_perms;
51allow apexd dev_type:blk_file getattr;
52
53#allow apexd to access virtual disks
54allow apexd vd_device:blk_file r_file_perms;
55
56# allow apexd to access /dev/block/dm-* (device-mapper entries)
57allow apexd dm_device:chr_file rw_file_perms;
58allow apexd dm_device:blk_file rw_file_perms;
59
60# sys_admin is required to access the device-mapper and mount
61# dac_override, chown, and fowner are needed for snapshot and restore
62allow apexd self:global_capability_class_set { sys_admin chown dac_override dac_read_search fowner };
63
64# Note: fsetid is deliberately not included above. fsetid checks are
65# triggered by chmod on a directory or file owned by a group other
66# than one of the groups assigned to the current process to see if
67# the setgid bit should be cleared, regardless of whether the setgid
68# bit was even set.  We do not appear to truly need this capability
69# for apexd to operate.
70dontaudit apexd self:global_capability_class_set fsetid;
71
72# allow apexd to create a mount point in /apex
73allow apexd apex_mnt_dir:dir create_dir_perms;
74# allow apexd to mount in /apex
75allow apexd apex_mnt_dir:filesystem { mount unmount };
76allow apexd apex_mnt_dir:dir mounton;
77# allow apexd to create symlinks in /apex
78allow apexd apex_mnt_dir:lnk_file create_file_perms;
79# allow apexd to create /apex/apex-info-list.xml and relabel to apex_info_file
80allow apexd apex_mnt_dir:file { create_file_perms relabelfrom mounton };
81allow apexd apex_info_file:file relabelto;
82# apexd needs to update /apex/apex-info-list.xml after non-staged APEX update.
83allow apexd apex_info_file:file rw_file_perms;
84
85# allow apexd to unlink apex files in /data/apex/active
86# note that apexd won't be able to unlink files in /data/app-staging/session_XXXX,
87# because it doesn't have write permission for staging_data_file object.
88allow apexd staging_data_file:file unlink;
89
90# allow apexd to read files from /data/app-staging and hardlink them to /data/apex.
91allow apexd staging_data_file:dir r_dir_perms;
92allow apexd staging_data_file:file { r_file_perms link };
93# # Allow relabeling file created in /data/apex/decompressed
94allow apexd staging_data_file:file relabelto;
95
96# allow apexd to read files from /vendor/apex
97r_dir_file(apexd, vendor_apex_file)
98r_dir_file(apexd, vendor_apex_metadata_file)
99
100# Unmount and mount filesystems
101allow apexd labeledfs:filesystem { mount unmount };
102
103# /sys directory tree traversal
104allow apexd sysfs_type:dir search;
105# Access to /sys/class/block
106allow apexd sysfs_type:dir r_dir_perms;
107allow apexd sysfs_type:file r_file_perms;
108# Configure read-ahead of dm-verity and loop devices
109# for dm-X
110allow apexd sysfs_dm:dir r_dir_perms;
111allow apexd sysfs_dm:file rw_file_perms;
112# for loopX
113allow apexd sysfs_loop:dir r_dir_perms;
114allow apexd sysfs_loop:file rw_file_perms;
115
116# Allow apexd to log to the kernel.
117allow apexd kmsg_device:chr_file w_file_perms;
118
119# Allow apexd to reboot device. Required for rollbacks of apexes that are
120# not covered by rollback manager.
121set_prop(apexd, powerctl_prop)
122
123# Allow apexd to stop itself
124set_prop(apexd, ctl_apexd_prop)
125
126# Allow apexd to send control messages to load/unload apex from init
127set_prop(apexd, ctl_apex_load_prop)
128
129# Find the vold service, and call into vold to manage FS checkpoints
130allow apexd vold_service:service_manager find;
131binder_call(apexd, vold)
132
133# apexd is using bootstrap bionic
134use_bootstrap_libs(apexd)
135
136# Allow apexd to be invoked with logwrapper from init during userspace reboot.
137allow apexd devpts:chr_file { read write };
138
139# Allow apexd to create pts files via logwrap_fork_exec for its own use, to pass to
140# other processes
141create_pty(apexd)
142
143# Allow apexd to read file contexts when performing restorecon of snapshots.
144allow apexd file_contexts_file:file r_file_perms;
145
146# Allow apexd to execute toybox for snapshot & restore
147allow apexd toolbox_exec:file rx_file_perms;
148
149# Allow apexd to release compressed blocks in case /data is f2fs-compressed fs.
150allowxperm apexd staging_data_file:file ioctl {
151  FS_IOC_GETFLAGS
152  F2FS_IOC_RELEASE_COMPRESS_BLOCKS
153};
154
155# Allow apexd to read ro.cold_boot_done prop.
156# apexd uses it to decide whether it needs to keep retrying polling for loop device.
157get_prop(apexd, cold_boot_done_prop)
158
159# Allow apexd to read per-device configuration properties.
160get_prop(apexd, apexd_config_prop)
161
162# Allow apexd to read apex selection properties.
163# These are used to choose between multi-installed APEXes at activation time.
164get_prop(apexd, apexd_select_prop)
165#
166# Allow apexd to read apexd_payload_metadata_prop
167get_prop(apexd, apexd_payload_metadata_prop)
168
169neverallow { domain -apexd -init } apex_data_file:dir no_w_dir_perms;
170neverallow { domain -apexd -init } apex_metadata_file:dir no_w_dir_perms;
171neverallow { domain -apexd -init -kernel } apex_data_file:file no_w_file_perms;
172neverallow { domain -apexd -init -kernel } apex_metadata_file:file no_w_file_perms;
173neverallow { domain -apexd } apex_mnt_dir:lnk_file no_w_file_perms;
174
175neverallow { domain -apexd -init -vold_prepare_subdirs } apex_module_data_file:dir no_w_dir_perms;
176neverallow { domain -apexd -init -vold_prepare_subdirs } apex_module_data_file:file no_w_file_perms;
177
178neverallow { domain -apexd -init -vold_prepare_subdirs } apex_rollback_data_file:dir no_w_dir_perms;
179neverallow { domain -apexd -init -vold_prepare_subdirs } apex_rollback_data_file:file no_w_file_perms;
180
181# only apexd can set apexd sysprop
182set_prop(apexd, apexd_prop)
183neverallow { domain -apexd -init } apexd_prop:property_service set;
184
185# only apexd can write apex-info-list.xml
186neverallow { domain -apexd } apex_info_file:file no_w_file_perms;
187
188# Only apexd and init should be allowed to manage /apex mounts
189# A note on otapreopt_chroot. It used to mount APEXes during postainstall stage of A/B OTAs,
190# but starting from S it just calls into apexd to prepare /apex for otapreoprt. Once the sepolicies
191# around otapreopt_chroot are cleaned up we should be able to remove it from the lists below.
192neverallow { domain -apexd -init -otapreopt_chroot } apex_mnt_dir:filesystem { mount unmount };
193neverallow { domain -apexd -init -otapreopt_chroot } apex_mnt_dir:dir { mounton };
194
195# Allow for use in postinstall
196allow apexd otapreopt_chroot:fd use;
197allow apexd postinstall_apex_mnt_dir:dir { create_dir_perms mounton };
198allow apexd postinstall_apex_mnt_dir:file { create_file_perms relabelfrom };
199allow apexd postinstall_apex_mnt_dir:lnk_file create;
200allow apexd proc_filesystems:file r_file_perms;
201
202# Allow calling derive_classpath to gather BCP information for staged sessions
203domain_auto_trans(apexd, derive_classpath_exec, apexd_derive_classpath);
204
205# Allow set apex ready property
206set_prop(apexd, apex_ready_prop)
207