1*e4a36f41SAndroid Build Coastguard Worker# recovery console (used in recovery init.rc for /sbin/recovery) 2*e4a36f41SAndroid Build Coastguard Worker 3*e4a36f41SAndroid Build Coastguard Worker# Declare the domain unconditionally so we can always reference it 4*e4a36f41SAndroid Build Coastguard Worker# in neverallow rules. 5*e4a36f41SAndroid Build Coastguard Workertype recovery, domain; 6*e4a36f41SAndroid Build Coastguard Worker 7*e4a36f41SAndroid Build Coastguard Worker# But the allow rules are only included in the recovery policy. 8*e4a36f41SAndroid Build Coastguard Worker# Otherwise recovery is only allowed the domain rules. 9*e4a36f41SAndroid Build Coastguard Workerrecovery_only(` 10*e4a36f41SAndroid Build Coastguard Worker # Allow recovery to perform an update as update_engine would do. 11*e4a36f41SAndroid Build Coastguard Worker typeattribute recovery update_engine_common; 12*e4a36f41SAndroid Build Coastguard Worker # Recovery can use HIDL HALs in passthrough mode 13*e4a36f41SAndroid Build Coastguard Worker passthrough_hal_client_domain(recovery, hal_bootctl) 14*e4a36f41SAndroid Build Coastguard Worker 15*e4a36f41SAndroid Build Coastguard Worker # Recovery can use AIDL HALs in binder mode 16*e4a36f41SAndroid Build Coastguard Worker binder_use(recovery) 17*e4a36f41SAndroid Build Coastguard Worker hal_client_domain(recovery, hal_health) 18*e4a36f41SAndroid Build Coastguard Worker 19*e4a36f41SAndroid Build Coastguard Worker allow recovery self:global_capability_class_set { 20*e4a36f41SAndroid Build Coastguard Worker chown 21*e4a36f41SAndroid Build Coastguard Worker dac_override 22*e4a36f41SAndroid Build Coastguard Worker dac_read_search 23*e4a36f41SAndroid Build Coastguard Worker fowner 24*e4a36f41SAndroid Build Coastguard Worker setuid 25*e4a36f41SAndroid Build Coastguard Worker setgid 26*e4a36f41SAndroid Build Coastguard Worker sys_admin 27*e4a36f41SAndroid Build Coastguard Worker sys_tty_config 28*e4a36f41SAndroid Build Coastguard Worker }; 29*e4a36f41SAndroid Build Coastguard Worker 30*e4a36f41SAndroid Build Coastguard Worker # Run helpers from / or /system without changing domain. 31*e4a36f41SAndroid Build Coastguard Worker r_dir_file(recovery, rootfs) 32*e4a36f41SAndroid Build Coastguard Worker allow recovery rootfs:file execute_no_trans; 33*e4a36f41SAndroid Build Coastguard Worker allow recovery system_file:file execute_no_trans; 34*e4a36f41SAndroid Build Coastguard Worker allow recovery toolbox_exec:file rx_file_perms; 35*e4a36f41SAndroid Build Coastguard Worker 36*e4a36f41SAndroid Build Coastguard Worker # Mount filesystems. 37*e4a36f41SAndroid Build Coastguard Worker allow recovery rootfs:dir mounton; 38*e4a36f41SAndroid Build Coastguard Worker allow recovery tmpfs:dir mounton; 39*e4a36f41SAndroid Build Coastguard Worker allow recovery { fs_type enforce_debugfs_restriction(`-debugfs_type') }:filesystem ~relabelto; 40*e4a36f41SAndroid Build Coastguard Worker allow recovery unlabeled:filesystem ~relabelto; 41*e4a36f41SAndroid Build Coastguard Worker allow recovery contextmount_type:filesystem relabelto; 42*e4a36f41SAndroid Build Coastguard Worker 43*e4a36f41SAndroid Build Coastguard Worker # We may be asked to set an SELinux label for a type not known to the 44*e4a36f41SAndroid Build Coastguard Worker # currently loaded policy. Allow it. 45*e4a36f41SAndroid Build Coastguard Worker allow recovery unlabeled:{ file lnk_file } { create_file_perms relabelfrom relabelto }; 46*e4a36f41SAndroid Build Coastguard Worker allow recovery unlabeled:dir { create_dir_perms relabelfrom relabelto }; 47*e4a36f41SAndroid Build Coastguard Worker 48*e4a36f41SAndroid Build Coastguard Worker # Get file contexts 49*e4a36f41SAndroid Build Coastguard Worker allow recovery file_contexts_file:file r_file_perms; 50*e4a36f41SAndroid Build Coastguard Worker 51*e4a36f41SAndroid Build Coastguard Worker # Write to /proc/sys/vm/drop_caches 52*e4a36f41SAndroid Build Coastguard Worker allow recovery proc_drop_caches:file w_file_perms; 53*e4a36f41SAndroid Build Coastguard Worker 54*e4a36f41SAndroid Build Coastguard Worker # Read /proc/swaps 55*e4a36f41SAndroid Build Coastguard Worker allow recovery proc_swaps:file r_file_perms; 56*e4a36f41SAndroid Build Coastguard Worker 57*e4a36f41SAndroid Build Coastguard Worker # Read kernel config through libvintf for OTA matching 58*e4a36f41SAndroid Build Coastguard Worker allow recovery config_gz:file { open read getattr }; 59*e4a36f41SAndroid Build Coastguard Worker 60*e4a36f41SAndroid Build Coastguard Worker # Write to /sys/class/android_usb/android0/enable. 61*e4a36f41SAndroid Build Coastguard Worker r_dir_file(recovery, sysfs_android_usb) 62*e4a36f41SAndroid Build Coastguard Worker allow recovery sysfs_android_usb:file w_file_perms; 63*e4a36f41SAndroid Build Coastguard Worker 64*e4a36f41SAndroid Build Coastguard Worker # Write to /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq. 65*e4a36f41SAndroid Build Coastguard Worker allow recovery sysfs_devices_system_cpu:file w_file_perms; 66*e4a36f41SAndroid Build Coastguard Worker 67*e4a36f41SAndroid Build Coastguard Worker allow recovery sysfs_batteryinfo:file r_file_perms; 68*e4a36f41SAndroid Build Coastguard Worker 69*e4a36f41SAndroid Build Coastguard Worker # Read /sysfs/fs/ext4/features 70*e4a36f41SAndroid Build Coastguard Worker r_dir_file(recovery, sysfs_fs_ext4_features) 71*e4a36f41SAndroid Build Coastguard Worker 72*e4a36f41SAndroid Build Coastguard Worker # Read from /sys/class/leds/lcd-backlight/max_brightness and write to /s/c/l/l/brightness to 73*e4a36f41SAndroid Build Coastguard Worker # control backlight brightness. 74*e4a36f41SAndroid Build Coastguard Worker allow recovery sysfs_leds:dir r_dir_perms; 75*e4a36f41SAndroid Build Coastguard Worker allow recovery sysfs_leds:file rw_file_perms; 76*e4a36f41SAndroid Build Coastguard Worker allow recovery sysfs_leds:lnk_file read; 77*e4a36f41SAndroid Build Coastguard Worker 78*e4a36f41SAndroid Build Coastguard Worker allow recovery kernel:system syslog_read; 79*e4a36f41SAndroid Build Coastguard Worker 80*e4a36f41SAndroid Build Coastguard Worker # Access /dev/usb-ffs/adb/ep0 81*e4a36f41SAndroid Build Coastguard Worker allow recovery functionfs:dir search; 82*e4a36f41SAndroid Build Coastguard Worker allow recovery functionfs:file rw_file_perms; 83*e4a36f41SAndroid Build Coastguard Worker allowxperm recovery functionfs:file ioctl FUNCTIONFS_ENDPOINT_DESC; 84*e4a36f41SAndroid Build Coastguard Worker 85*e4a36f41SAndroid Build Coastguard Worker # Access to /sys/fs/selinux/policyvers for compatibility check 86*e4a36f41SAndroid Build Coastguard Worker allow recovery selinuxfs:file r_file_perms; 87*e4a36f41SAndroid Build Coastguard Worker 88*e4a36f41SAndroid Build Coastguard Worker # Required to e.g. wipe userdata/cache. 89*e4a36f41SAndroid Build Coastguard Worker allow recovery device:dir r_dir_perms; 90*e4a36f41SAndroid Build Coastguard Worker allow recovery block_device:dir r_dir_perms; 91*e4a36f41SAndroid Build Coastguard Worker allow recovery dev_type:blk_file rw_file_perms; 92*e4a36f41SAndroid Build Coastguard Worker allowxperm recovery { userdata_block_device metadata_block_device cache_block_device }:blk_file ioctl BLKPBSZGET; 93*e4a36f41SAndroid Build Coastguard Worker 94*e4a36f41SAndroid Build Coastguard Worker # GUI 95*e4a36f41SAndroid Build Coastguard Worker allow recovery graphics_device:chr_file rw_file_perms; 96*e4a36f41SAndroid Build Coastguard Worker allow recovery graphics_device:dir r_dir_perms; 97*e4a36f41SAndroid Build Coastguard Worker allow recovery input_device:dir r_dir_perms; 98*e4a36f41SAndroid Build Coastguard Worker allow recovery input_device:chr_file r_file_perms; 99*e4a36f41SAndroid Build Coastguard Worker allow recovery tty_device:chr_file rw_file_perms; 100*e4a36f41SAndroid Build Coastguard Worker 101*e4a36f41SAndroid Build Coastguard Worker # Create /tmp/recovery.log and execute /tmp/update_binary. 102*e4a36f41SAndroid Build Coastguard Worker allow recovery tmpfs:file { create_file_perms x_file_perms }; 103*e4a36f41SAndroid Build Coastguard Worker allow recovery tmpfs:dir create_dir_perms; 104*e4a36f41SAndroid Build Coastguard Worker 105*e4a36f41SAndroid Build Coastguard Worker # Manage files on /cache and /cache/recovery 106*e4a36f41SAndroid Build Coastguard Worker allow recovery { cache_file cache_recovery_file }:dir create_dir_perms; 107*e4a36f41SAndroid Build Coastguard Worker allow recovery { cache_file cache_recovery_file }:file create_file_perms; 108*e4a36f41SAndroid Build Coastguard Worker 109*e4a36f41SAndroid Build Coastguard Worker # Read /sys/class/thermal/*/temp for thermal info. 110*e4a36f41SAndroid Build Coastguard Worker r_dir_file(recovery, sysfs_thermal) 111*e4a36f41SAndroid Build Coastguard Worker 112*e4a36f41SAndroid Build Coastguard Worker # Read files on /oem. 113*e4a36f41SAndroid Build Coastguard Worker r_dir_file(recovery, oemfs); 114*e4a36f41SAndroid Build Coastguard Worker 115*e4a36f41SAndroid Build Coastguard Worker # Use setfscreatecon() to label files for OTA updates. 116*e4a36f41SAndroid Build Coastguard Worker allow recovery self:process setfscreate; 117*e4a36f41SAndroid Build Coastguard Worker 118*e4a36f41SAndroid Build Coastguard Worker # Allow recovery to create a fuse filesystem, and read files from it. 119*e4a36f41SAndroid Build Coastguard Worker allow recovery fuse_device:chr_file rw_file_perms; 120*e4a36f41SAndroid Build Coastguard Worker allow recovery fuse:dir r_dir_perms; 121*e4a36f41SAndroid Build Coastguard Worker allow recovery fuse:file r_file_perms; 122*e4a36f41SAndroid Build Coastguard Worker 123*e4a36f41SAndroid Build Coastguard Worker wakelock_use(recovery) 124*e4a36f41SAndroid Build Coastguard Worker 125*e4a36f41SAndroid Build Coastguard Worker # This line seems suspect, as it should not really need to 126*e4a36f41SAndroid Build Coastguard Worker # set scheduling parameters for a kernel domain task. 127*e4a36f41SAndroid Build Coastguard Worker allow recovery kernel:process setsched; 128*e4a36f41SAndroid Build Coastguard Worker 129*e4a36f41SAndroid Build Coastguard Worker # These are needed to update dynamic partitions in recovery. 130*e4a36f41SAndroid Build Coastguard Worker r_dir_file(recovery, sysfs_dm) 131*e4a36f41SAndroid Build Coastguard Worker allowxperm recovery super_block_device_type:blk_file ioctl { BLKIOMIN BLKALIGNOFF }; 132*e4a36f41SAndroid Build Coastguard Worker 133*e4a36f41SAndroid Build Coastguard Worker # Allow using libfiemap/gsid directly (no binder in recovery). 134*e4a36f41SAndroid Build Coastguard Worker allow recovery gsi_metadata_file_type:dir search; 135*e4a36f41SAndroid Build Coastguard Worker allow recovery ota_metadata_file:dir rw_dir_perms; 136*e4a36f41SAndroid Build Coastguard Worker allow recovery ota_metadata_file:file create_file_perms; 137*e4a36f41SAndroid Build Coastguard Worker 138*e4a36f41SAndroid Build Coastguard Worker # Allow mounting /metadata for writing update states 139*e4a36f41SAndroid Build Coastguard Worker allow recovery metadata_file:dir { getattr mounton }; 140*e4a36f41SAndroid Build Coastguard Worker 141*e4a36f41SAndroid Build Coastguard Worker # Recovery uses liblogwrap to write fsck logs to kmsg, liblogwrap requires devpts. 142*e4a36f41SAndroid Build Coastguard Worker allow recovery devpts:chr_file rw_file_perms; 143*e4a36f41SAndroid Build Coastguard Worker allow recovery kmsg_device:chr_file { getattr w_file_perms }; 144*e4a36f41SAndroid Build Coastguard Worker') 145*e4a36f41SAndroid Build Coastguard Worker 146*e4a36f41SAndroid Build Coastguard Worker### 147*e4a36f41SAndroid Build Coastguard Worker### neverallow rules 148*e4a36f41SAndroid Build Coastguard Worker### 149*e4a36f41SAndroid Build Coastguard Worker 150*e4a36f41SAndroid Build Coastguard Worker# Recovery should never touch /data. 151*e4a36f41SAndroid Build Coastguard Worker# 152*e4a36f41SAndroid Build Coastguard Worker# In particular, if /data is encrypted, it is not accessible 153*e4a36f41SAndroid Build Coastguard Worker# to recovery anyway. 154*e4a36f41SAndroid Build Coastguard Worker# 155*e4a36f41SAndroid Build Coastguard Worker# For now, we only enforce write/execute restrictions, as domain.te 156*e4a36f41SAndroid Build Coastguard Worker# contains a number of read-only rules that apply to all 157*e4a36f41SAndroid Build Coastguard Worker# domains, including recovery. 158*e4a36f41SAndroid Build Coastguard Worker# 159*e4a36f41SAndroid Build Coastguard Worker# TODO: tighten this up further. 160*e4a36f41SAndroid Build Coastguard Workerneverallow recovery { 161*e4a36f41SAndroid Build Coastguard Worker data_file_type 162*e4a36f41SAndroid Build Coastguard Worker -cache_file 163*e4a36f41SAndroid Build Coastguard Worker -cache_recovery_file 164*e4a36f41SAndroid Build Coastguard Worker with_native_coverage(`-method_trace_data_file') 165*e4a36f41SAndroid Build Coastguard Worker}:file { no_w_file_perms no_x_file_perms }; 166*e4a36f41SAndroid Build Coastguard Workerneverallow recovery { 167*e4a36f41SAndroid Build Coastguard Worker data_file_type 168*e4a36f41SAndroid Build Coastguard Worker -cache_file 169*e4a36f41SAndroid Build Coastguard Worker -cache_recovery_file 170*e4a36f41SAndroid Build Coastguard Worker with_native_coverage(`-method_trace_data_file') 171*e4a36f41SAndroid Build Coastguard Worker}:dir no_w_dir_perms; 172