1*e4a36f41SAndroid Build Coastguard Worker# Domain for the otapreopt executable, running under postinstall_dexopt 2*e4a36f41SAndroid Build Coastguard Worker# 3*e4a36f41SAndroid Build Coastguard Worker# Note: otapreopt is a driver for dex2oat, and reuses parts of installd. As such, 4*e4a36f41SAndroid Build Coastguard Worker# this is derived and adapted from installd.te. 5*e4a36f41SAndroid Build Coastguard Worker 6*e4a36f41SAndroid Build Coastguard Workertype postinstall_dexopt, domain, coredomain, mlstrustedsubject; 7*e4a36f41SAndroid Build Coastguard Workertype postinstall_dexopt_exec, system_file_type, exec_type, file_type; 8*e4a36f41SAndroid Build Coastguard Workertype postinstall_dexopt_tmpfs, file_type; 9*e4a36f41SAndroid Build Coastguard Worker 10*e4a36f41SAndroid Build Coastguard Worker# Run dex2oat/patchoat in its own sandbox. 11*e4a36f41SAndroid Build Coastguard Worker# We have to manually transition, as we don't have an entrypoint. 12*e4a36f41SAndroid Build Coastguard Worker# - Case where dex2oat is in a non-flattened APEX, which has retained 13*e4a36f41SAndroid Build Coastguard Worker# the correct type (`dex2oat_exec`). 14*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(postinstall_dexopt, dex2oat_exec, dex2oat) 15*e4a36f41SAndroid Build Coastguard Worker# - Case where dex2oat is in a flattened APEX, which has been tagged 16*e4a36f41SAndroid Build Coastguard Worker# with the `postinstall_file` type by update_engine. 17*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(postinstall_dexopt, postinstall_file, dex2oat) 18*e4a36f41SAndroid Build Coastguard Worker 19*e4a36f41SAndroid Build Coastguard Worker# Run derive_classpath to get the current BCP. 20*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(postinstall_dexopt, derive_classpath_exec, derive_classpath) 21*e4a36f41SAndroid Build Coastguard Worker# Allow postinstall_dexopt to make a tempfile for derive_classpath to write into 22*e4a36f41SAndroid Build Coastguard Workertmpfs_domain(postinstall_dexopt); 23*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt postinstall_dexopt_tmpfs:file open; 24*e4a36f41SAndroid Build Coastguard Worker 25*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt self:global_capability_class_set { chown dac_override dac_read_search fowner fsetid setgid setuid }; 26*e4a36f41SAndroid Build Coastguard Worker 27*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt postinstall_file:filesystem getattr; 28*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt postinstall_file:dir { getattr read search }; 29*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt postinstall_file:lnk_file { getattr read }; 30*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt proc_filesystems:file { getattr open read }; 31*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt rootfs:file r_file_perms; 32*e4a36f41SAndroid Build Coastguard Worker 33*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt tmpfs:file read; 34*e4a36f41SAndroid Build Coastguard Worker 35*e4a36f41SAndroid Build Coastguard Worker# Allow access odsign verification status 36*e4a36f41SAndroid Build Coastguard Workerget_prop(postinstall_dexopt, odsign_prop) 37*e4a36f41SAndroid Build Coastguard Worker 38*e4a36f41SAndroid Build Coastguard Worker# Allow access to /postinstall/apex. 39*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt postinstall_apex_mnt_dir:dir { getattr search }; 40*e4a36f41SAndroid Build Coastguard Worker 41*e4a36f41SAndroid Build Coastguard Worker# Note: /data/ota is created by init (see system/core/rootdir/init.rc) to avoid giving access 42*e4a36f41SAndroid Build Coastguard Worker# here and having to relabel the directory. 43*e4a36f41SAndroid Build Coastguard Worker 44*e4a36f41SAndroid Build Coastguard Worker# Read app data (APKs) as input to dex2oat. 45*e4a36f41SAndroid Build Coastguard Workerr_dir_file(postinstall_dexopt, apk_data_file) 46*e4a36f41SAndroid Build Coastguard Worker# Read vendor app data (APKs) as input to dex2oat. 47*e4a36f41SAndroid Build Coastguard Workerr_dir_file(postinstall_dexopt, vendor_app_file) 48*e4a36f41SAndroid Build Coastguard Worker# Read vendor overlay files (APKs) as input to dex2oat. 49*e4a36f41SAndroid Build Coastguard Workerr_dir_file(postinstall_dexopt, vendor_overlay_file) 50*e4a36f41SAndroid Build Coastguard Worker# Vendor overlay can be found in vendor apex 51*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt vendor_apex_metadata_file:dir { getattr search }; 52*e4a36f41SAndroid Build Coastguard Worker# Access to app oat directory. 53*e4a36f41SAndroid Build Coastguard Workerr_dir_file(postinstall_dexopt, dalvikcache_data_file) 54*e4a36f41SAndroid Build Coastguard Worker 55*e4a36f41SAndroid Build Coastguard Worker# Read profile data. 56*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt { user_profile_root_file user_profile_data_file }:dir { getattr search }; 57*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt user_profile_data_file:file r_file_perms; 58*e4a36f41SAndroid Build Coastguard Worker# Suppress deletion denial (we do not want to update the profile). 59*e4a36f41SAndroid Build Coastguard Workerdontaudit postinstall_dexopt user_profile_data_file:file { write }; 60*e4a36f41SAndroid Build Coastguard Worker 61*e4a36f41SAndroid Build Coastguard Worker# Write to /data/ota(/*). Create symlinks in /data/ota(/*) 62*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt ota_data_file:dir create_dir_perms; 63*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt ota_data_file:file create_file_perms; 64*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt ota_data_file:lnk_file create_file_perms; 65*e4a36f41SAndroid Build Coastguard Worker 66*e4a36f41SAndroid Build Coastguard Worker# Need to write .b files, which are dalvikcache_data_file, not ota_data_file. 67*e4a36f41SAndroid Build Coastguard Worker# TODO: See whether we can apply ota_data_file? 68*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt dalvikcache_data_file:dir rw_dir_perms; 69*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt dalvikcache_data_file:file create_file_perms; 70*e4a36f41SAndroid Build Coastguard Worker 71*e4a36f41SAndroid Build Coastguard Worker# Allow labeling of files under /data/app/com.example/oat/ 72*e4a36f41SAndroid Build Coastguard Worker# TODO: Restrict to .b suffix? 73*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt dalvikcache_data_file:dir relabelto; 74*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt dalvikcache_data_file:file { relabelto link }; 75*e4a36f41SAndroid Build Coastguard Worker 76*e4a36f41SAndroid Build Coastguard Worker# Check validity of SELinux context before use. 77*e4a36f41SAndroid Build Coastguard Workerselinux_check_context(postinstall_dexopt) 78*e4a36f41SAndroid Build Coastguard Workerselinux_check_access(postinstall_dexopt) 79*e4a36f41SAndroid Build Coastguard Worker 80*e4a36f41SAndroid Build Coastguard Worker 81*e4a36f41SAndroid Build Coastguard Worker# Postinstall wants to know about our child. 82*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt postinstall:process sigchld; 83*e4a36f41SAndroid Build Coastguard Worker 84*e4a36f41SAndroid Build Coastguard Worker# Allow otapreopt to use file descriptors from otapreopt_chroot. 85*e4a36f41SAndroid Build Coastguard Worker# TODO: Probably we can actually close file descriptors... 86*e4a36f41SAndroid Build Coastguard Workerallow postinstall_dexopt otapreopt_chroot:fd use; 87*e4a36f41SAndroid Build Coastguard Worker 88*e4a36f41SAndroid Build Coastguard Worker# Allow postinstall_dexopt to access the runtime feature flag properties. 89*e4a36f41SAndroid Build Coastguard Workerget_prop(postinstall_dexopt, device_config_runtime_native_prop) 90*e4a36f41SAndroid Build Coastguard Workerget_prop(postinstall_dexopt, device_config_runtime_native_boot_prop) 91