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