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 creating and writing APEX files/dirs in the SEPolicy metadata dir 17*e4a36f41SAndroid Build Coastguard Workerallow apexd sepolicy_metadata_file:dir create_dir_perms; 18*e4a36f41SAndroid Build Coastguard Workerallow apexd sepolicy_metadata_file:file create_file_perms; 19*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to setup fs-verity for SEPolicy files in metadata 20*e4a36f41SAndroid Build Coastguard Workerallowxperm apexd sepolicy_metadata_file:file ioctl { 21*e4a36f41SAndroid Build Coastguard Worker FS_IOC_ENABLE_VERITY FS_IOC_MEASURE_VERITY 22*e4a36f41SAndroid Build Coastguard Worker}; 23*e4a36f41SAndroid Build Coastguard Worker 24*e4a36f41SAndroid Build Coastguard Worker# Allow reserving space on /data/apex/ota_reserved for apex decompression 25*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_ota_reserved_file:dir create_dir_perms; 26*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_ota_reserved_file:file create_file_perms; 27*e4a36f41SAndroid Build Coastguard Worker 28*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to create files and directories for snapshots of apex data 29*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_data_file_type:dir { create_dir_perms relabelto }; 30*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_data_file_type:file { create_file_perms relabelto }; 31*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_module_data_file:dir { create_dir_perms relabelfrom }; 32*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_module_data_file:file { create_file_perms relabelfrom }; 33*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_rollback_data_file:dir create_dir_perms; 34*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_rollback_data_file:file create_file_perms; 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 dev_type:dir r_dir_perms; 56*e4a36f41SAndroid Build Coastguard Workerallow apexd dev_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 Workerallow apexd apex_info_file:file mounton; 90*e4a36f41SAndroid Build Coastguard Worker 91*e4a36f41SAndroid Build Coastguard Worker# allow apexd to unlink apex files in /data/apex/active 92*e4a36f41SAndroid Build Coastguard Worker# note that apexd won't be able to unlink files in /data/app-staging/session_XXXX, 93*e4a36f41SAndroid Build Coastguard Worker# because it doesn't have write permission for staging_data_file object. 94*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:file unlink; 95*e4a36f41SAndroid Build Coastguard Worker 96*e4a36f41SAndroid Build Coastguard Worker# allow apexd to read files from /data/app-staging and hardlink them to /data/apex. 97*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:dir r_dir_perms; 98*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:file { r_file_perms link }; 99*e4a36f41SAndroid Build Coastguard Worker# # Allow relabeling file created in /data/apex/decompressed 100*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:file relabelto; 101*e4a36f41SAndroid Build Coastguard Worker 102*e4a36f41SAndroid Build Coastguard Worker# allow apexd to read files from /vendor/apex 103*e4a36f41SAndroid Build Coastguard Workerallow apexd vendor_apex_file:dir r_dir_perms; 104*e4a36f41SAndroid Build Coastguard Workerallow apexd vendor_apex_file:file r_file_perms; 105*e4a36f41SAndroid Build Coastguard Worker 106*e4a36f41SAndroid Build Coastguard Worker# Unmount and mount filesystems 107*e4a36f41SAndroid Build Coastguard Workerallow apexd labeledfs:filesystem { mount unmount }; 108*e4a36f41SAndroid Build Coastguard Worker 109*e4a36f41SAndroid Build Coastguard Worker# /sys directory tree traversal 110*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_type:dir search; 111*e4a36f41SAndroid Build Coastguard Worker# Access to /sys/class/block 112*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_type:dir r_dir_perms; 113*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_type:file r_file_perms; 114*e4a36f41SAndroid Build Coastguard Worker# Configure read-ahead of dm-verity and loop devices 115*e4a36f41SAndroid Build Coastguard Worker# for dm-X 116*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_dm:dir r_dir_perms; 117*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_dm:file rw_file_perms; 118*e4a36f41SAndroid Build Coastguard Worker# for loopX 119*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_loop:dir r_dir_perms; 120*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_loop:file rw_file_perms; 121*e4a36f41SAndroid Build Coastguard Worker 122*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to log to the kernel. 123*e4a36f41SAndroid Build Coastguard Workerallow apexd kmsg_device:chr_file w_file_perms; 124*e4a36f41SAndroid Build Coastguard Worker 125*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to reboot device. Required for rollbacks of apexes that are 126*e4a36f41SAndroid Build Coastguard Worker# not covered by rollback manager. 127*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, powerctl_prop) 128*e4a36f41SAndroid Build Coastguard Worker 129*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to stop itself 130*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, ctl_apexd_prop) 131*e4a36f41SAndroid Build Coastguard Worker 132*e4a36f41SAndroid Build Coastguard Worker# Find the vold service, and call into vold to manage FS checkpoints 133*e4a36f41SAndroid Build Coastguard Workerallow apexd vold_service:service_manager find; 134*e4a36f41SAndroid Build Coastguard Workerbinder_call(apexd, vold) 135*e4a36f41SAndroid Build Coastguard Worker 136*e4a36f41SAndroid Build Coastguard Worker# apexd is using bootstrap bionic 137*e4a36f41SAndroid Build Coastguard Workeruse_bootstrap_libs(apexd) 138*e4a36f41SAndroid Build Coastguard Worker 139*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to be invoked with logwrapper from init during userspace reboot. 140*e4a36f41SAndroid Build Coastguard Workerallow apexd devpts:chr_file { read write }; 141*e4a36f41SAndroid Build Coastguard Worker 142*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to create pts files via logwrap_fork_exec for its own use, to pass to 143*e4a36f41SAndroid Build Coastguard Worker# other processes 144*e4a36f41SAndroid Build Coastguard Workercreate_pty(apexd) 145*e4a36f41SAndroid Build Coastguard Worker 146*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read file contexts when performing restorecon of snapshots. 147*e4a36f41SAndroid Build Coastguard Workerallow apexd file_contexts_file:file r_file_perms; 148*e4a36f41SAndroid Build Coastguard Worker 149*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to execute toybox for snapshot & restore 150*e4a36f41SAndroid Build Coastguard Workerallow apexd toolbox_exec:file rx_file_perms; 151*e4a36f41SAndroid Build Coastguard Worker 152*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to release compressed blocks in case /data is f2fs-compressed fs. 153*e4a36f41SAndroid Build Coastguard Workerallowxperm apexd staging_data_file:file ioctl { 154*e4a36f41SAndroid Build Coastguard Worker FS_IOC_GETFLAGS 155*e4a36f41SAndroid Build Coastguard Worker F2FS_IOC_RELEASE_COMPRESS_BLOCKS 156*e4a36f41SAndroid Build Coastguard Worker}; 157*e4a36f41SAndroid Build Coastguard Worker 158*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read ro.cold_boot_done prop. 159*e4a36f41SAndroid Build Coastguard Worker# apexd uses it to decide whether it needs to keep retrying polling for loop device. 160*e4a36f41SAndroid Build Coastguard Workerget_prop(apexd, cold_boot_done_prop) 161*e4a36f41SAndroid Build Coastguard Worker 162*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read per-device configuration properties. 163*e4a36f41SAndroid Build Coastguard Workerget_prop(apexd, apexd_config_prop) 164*e4a36f41SAndroid Build Coastguard Worker 165*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read apex selection properties. 166*e4a36f41SAndroid Build Coastguard Worker# These are used to choose between multi-installed APEXes at activation time. 167*e4a36f41SAndroid Build Coastguard Workerget_prop(apexd, apexd_select_prop) 168*e4a36f41SAndroid Build Coastguard Worker# 169*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read apexd_payload_metadata_prop 170*e4a36f41SAndroid Build Coastguard Workerget_prop(apexd, apexd_payload_metadata_prop) 171*e4a36f41SAndroid Build Coastguard Worker 172*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init } apex_data_file:dir no_w_dir_perms; 173*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init } apex_metadata_file:dir no_w_dir_perms; 174*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -kernel } apex_data_file:file no_w_file_perms; 175*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -kernel } apex_metadata_file:file no_w_file_perms; 176*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd } apex_mnt_dir:lnk_file no_w_file_perms; 177*e4a36f41SAndroid Build Coastguard Worker 178*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_module_data_file:dir no_w_dir_perms; 179*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_module_data_file:file no_w_file_perms; 180*e4a36f41SAndroid Build Coastguard Worker 181*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_rollback_data_file:dir no_w_dir_perms; 182*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_rollback_data_file:file no_w_file_perms; 183*e4a36f41SAndroid Build Coastguard Worker 184*e4a36f41SAndroid Build Coastguard Worker# only apexd can set apexd sysprop 185*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, apexd_prop) 186*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init } apexd_prop:property_service set; 187*e4a36f41SAndroid Build Coastguard Worker 188*e4a36f41SAndroid Build Coastguard Worker# only apexd can write apex-info-list.xml 189*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd } apex_info_file:file no_w_file_perms; 190*e4a36f41SAndroid Build Coastguard Worker 191*e4a36f41SAndroid Build Coastguard Worker# Only apexd and init should be allowed to manage /apex mounts 192*e4a36f41SAndroid Build Coastguard Worker# A note on otapreopt_chroot. It used to mount APEXes during postainstall stage of A/B OTAs, 193*e4a36f41SAndroid Build Coastguard Worker# but starting from S it just calls into apexd to prepare /apex for otapreoprt. Once the sepolicies 194*e4a36f41SAndroid Build Coastguard Worker# around otapreopt_chroot are cleaned up we should be able to remove it from the lists below. 195*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -otapreopt_chroot } apex_mnt_dir:filesystem { mount unmount }; 196*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -otapreopt_chroot } apex_mnt_dir:dir { mounton }; 197*e4a36f41SAndroid Build Coastguard Worker 198*e4a36f41SAndroid Build Coastguard Worker# Allow for use in postinstall 199*e4a36f41SAndroid Build Coastguard Workerallow apexd otapreopt_chroot:fd use; 200*e4a36f41SAndroid Build Coastguard Workerallow apexd postinstall_apex_mnt_dir:dir { create_dir_perms mounton }; 201*e4a36f41SAndroid Build Coastguard Workerallow apexd postinstall_apex_mnt_dir:file { create_file_perms relabelfrom }; 202*e4a36f41SAndroid Build Coastguard Workerallow apexd postinstall_apex_mnt_dir:lnk_file create; 203*e4a36f41SAndroid Build Coastguard Workerallow apexd proc_filesystems:file r_file_perms; 204*e4a36f41SAndroid Build Coastguard Worker 205*e4a36f41SAndroid Build Coastguard Worker# Allow calling derive_classpath to gather BCP information for staged sessions 206*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(apexd, derive_classpath_exec, apexd_derive_classpath); 207