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