1*e4a36f41SAndroid Build Coastguard Worker# fastbootd (used in recovery init.rc for /sbin/fastbootd) 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 fastbootd, 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 fastbootd is only allowed the domain rules. 9*e4a36f41SAndroid Build Coastguard Workerrecovery_only(` 10*e4a36f41SAndroid Build Coastguard Worker # fastbootd can only use HALs in passthrough mode 11*e4a36f41SAndroid Build Coastguard Worker passthrough_hal_client_domain(fastbootd, hal_bootctl) 12*e4a36f41SAndroid Build Coastguard Worker 13*e4a36f41SAndroid Build Coastguard Worker # Access /dev/usb-ffs/fastbootd/ep0 14*e4a36f41SAndroid Build Coastguard Worker allow fastbootd functionfs:dir search; 15*e4a36f41SAndroid Build Coastguard Worker allow fastbootd functionfs:file rw_file_perms; 16*e4a36f41SAndroid Build Coastguard Worker 17*e4a36f41SAndroid Build Coastguard Worker allowxperm fastbootd functionfs:file ioctl { FUNCTIONFS_ENDPOINT_DESC }; 18*e4a36f41SAndroid Build Coastguard Worker # Log to serial 19*e4a36f41SAndroid Build Coastguard Worker allow fastbootd kmsg_device:chr_file { open getattr write }; 20*e4a36f41SAndroid Build Coastguard Worker 21*e4a36f41SAndroid Build Coastguard Worker # battery info 22*e4a36f41SAndroid Build Coastguard Worker allow fastbootd sysfs_batteryinfo:file r_file_perms; 23*e4a36f41SAndroid Build Coastguard Worker 24*e4a36f41SAndroid Build Coastguard Worker allow fastbootd device:dir r_dir_perms; 25*e4a36f41SAndroid Build Coastguard Worker 26*e4a36f41SAndroid Build Coastguard Worker # Reboot the device 27*e4a36f41SAndroid Build Coastguard Worker set_prop(fastbootd, powerctl_prop) 28*e4a36f41SAndroid Build Coastguard Worker 29*e4a36f41SAndroid Build Coastguard Worker # Read serial number of the device from system properties 30*e4a36f41SAndroid Build Coastguard Worker get_prop(fastbootd, serialno_prop) 31*e4a36f41SAndroid Build Coastguard Worker 32*e4a36f41SAndroid Build Coastguard Worker # For dev/block/by-name dir 33*e4a36f41SAndroid Build Coastguard Worker allow fastbootd block_device:dir r_dir_perms; 34*e4a36f41SAndroid Build Coastguard Worker 35*e4a36f41SAndroid Build Coastguard Worker # Needed for DM_DEV_CREATE ioctl call 36*e4a36f41SAndroid Build Coastguard Worker allow fastbootd self:capability sys_admin; 37*e4a36f41SAndroid Build Coastguard Worker 38*e4a36f41SAndroid Build Coastguard Worker # Set sys.usb.ffs.ready. 39*e4a36f41SAndroid Build Coastguard Worker set_prop(fastbootd, ffs_prop) 40*e4a36f41SAndroid Build Coastguard Worker set_prop(fastbootd, exported_ffs_prop) 41*e4a36f41SAndroid Build Coastguard Worker 42*e4a36f41SAndroid Build Coastguard Worker unix_socket_connect(fastbootd, recovery, recovery) 43*e4a36f41SAndroid Build Coastguard Worker 44*e4a36f41SAndroid Build Coastguard Worker # Required for flashing 45*e4a36f41SAndroid Build Coastguard Worker allow fastbootd dm_device:chr_file rw_file_perms; 46*e4a36f41SAndroid Build Coastguard Worker allow fastbootd dm_device:blk_file rw_file_perms; 47*e4a36f41SAndroid Build Coastguard Worker 48*e4a36f41SAndroid Build Coastguard Worker allow fastbootd super_block_device_type:blk_file rw_file_perms; 49*e4a36f41SAndroid Build Coastguard Worker allow fastbootd { 50*e4a36f41SAndroid Build Coastguard Worker boot_block_device 51*e4a36f41SAndroid Build Coastguard Worker metadata_block_device 52*e4a36f41SAndroid Build Coastguard Worker system_block_device 53*e4a36f41SAndroid Build Coastguard Worker userdata_block_device 54*e4a36f41SAndroid Build Coastguard Worker }:blk_file { w_file_perms getattr ioctl }; 55*e4a36f41SAndroid Build Coastguard Worker 56*e4a36f41SAndroid Build Coastguard Worker # For disabling/wiping GSI. 57*e4a36f41SAndroid Build Coastguard Worker allow fastbootd metadata_block_device:blk_file r_file_perms; 58*e4a36f41SAndroid Build Coastguard Worker allow fastbootd {rootfs tmpfs}:dir mounton; 59*e4a36f41SAndroid Build Coastguard Worker allow fastbootd metadata_file:dir search; 60*e4a36f41SAndroid Build Coastguard Worker allow fastbootd gsi_metadata_file:dir r_dir_perms; 61*e4a36f41SAndroid Build Coastguard Worker allow fastbootd gsi_metadata_file:file rw_file_perms; 62*e4a36f41SAndroid Build Coastguard Worker 63*e4a36f41SAndroid Build Coastguard Worker allowxperm fastbootd super_block_device_type:blk_file ioctl { BLKIOMIN BLKALIGNOFF }; 64*e4a36f41SAndroid Build Coastguard Worker 65*e4a36f41SAndroid Build Coastguard Worker allowxperm fastbootd { 66*e4a36f41SAndroid Build Coastguard Worker metadata_block_device 67*e4a36f41SAndroid Build Coastguard Worker userdata_block_device 68*e4a36f41SAndroid Build Coastguard Worker dm_device 69*e4a36f41SAndroid Build Coastguard Worker }:blk_file ioctl { BLKSECDISCARD BLKDISCARD }; 70*e4a36f41SAndroid Build Coastguard Worker 71*e4a36f41SAndroid Build Coastguard Worker allow fastbootd misc_block_device:blk_file rw_file_perms; 72*e4a36f41SAndroid Build Coastguard Worker 73*e4a36f41SAndroid Build Coastguard Worker allow fastbootd proc_cmdline:file r_file_perms; 74*e4a36f41SAndroid Build Coastguard Worker allow fastbootd rootfs:dir r_dir_perms; 75*e4a36f41SAndroid Build Coastguard Worker 76*e4a36f41SAndroid Build Coastguard Worker # Needed to read fstab node from device tree. 77*e4a36f41SAndroid Build Coastguard Worker allow fastbootd sysfs_dt_firmware_android:file r_file_perms; 78*e4a36f41SAndroid Build Coastguard Worker allow fastbootd sysfs_dt_firmware_android:dir r_dir_perms; 79*e4a36f41SAndroid Build Coastguard Worker 80*e4a36f41SAndroid Build Coastguard Worker # Needed for realpath() call to resolve symlinks. 81*e4a36f41SAndroid Build Coastguard Worker allow fastbootd block_device:dir getattr; 82*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(` 83*e4a36f41SAndroid Build Coastguard Worker # Refined manipulation of /mnt/scratch, without these perms resorts 84*e4a36f41SAndroid Build Coastguard Worker # to deleting scratch partition when partition(s) are flashed. 85*e4a36f41SAndroid Build Coastguard Worker allow fastbootd self:process setfscreate; 86*e4a36f41SAndroid Build Coastguard Worker allow fastbootd cache_file:dir search; 87*e4a36f41SAndroid Build Coastguard Worker allow fastbootd proc_filesystems:file { getattr open read }; 88*e4a36f41SAndroid Build Coastguard Worker allow fastbootd self:capability sys_rawio; 89*e4a36f41SAndroid Build Coastguard Worker dontaudit fastbootd kernel:system module_request; 90*e4a36f41SAndroid Build Coastguard Worker allowxperm fastbootd dev_type:blk_file ioctl BLKROSET; 91*e4a36f41SAndroid Build Coastguard Worker allow fastbootd overlayfs_file:dir { create_dir_perms mounton }; 92*e4a36f41SAndroid Build Coastguard Worker allow fastbootd { 93*e4a36f41SAndroid Build Coastguard Worker system_file_type 94*e4a36f41SAndroid Build Coastguard Worker unlabeled 95*e4a36f41SAndroid Build Coastguard Worker vendor_file_type 96*e4a36f41SAndroid Build Coastguard Worker }:dir { remove_name rmdir search write }; 97*e4a36f41SAndroid Build Coastguard Worker allow fastbootd { 98*e4a36f41SAndroid Build Coastguard Worker overlayfs_file 99*e4a36f41SAndroid Build Coastguard Worker system_file_type 100*e4a36f41SAndroid Build Coastguard Worker unlabeled 101*e4a36f41SAndroid Build Coastguard Worker vendor_file_type 102*e4a36f41SAndroid Build Coastguard Worker }:{ file lnk_file } unlink; 103*e4a36f41SAndroid Build Coastguard Worker allow fastbootd tmpfs:dir rw_dir_perms; 104*e4a36f41SAndroid Build Coastguard Worker allow fastbootd labeledfs:filesystem { mount unmount }; 105*e4a36f41SAndroid Build Coastguard Worker get_prop(fastbootd, persistent_properties_ready_prop) 106*e4a36f41SAndroid Build Coastguard Worker ') 107*e4a36f41SAndroid Build Coastguard Worker') 108*e4a36f41SAndroid Build Coastguard Worker 109*e4a36f41SAndroid Build Coastguard Worker### 110*e4a36f41SAndroid Build Coastguard Worker### neverallow rules 111*e4a36f41SAndroid Build Coastguard Worker### 112*e4a36f41SAndroid Build Coastguard Worker 113*e4a36f41SAndroid Build Coastguard Worker# Write permission is required to wipe userdata 114*e4a36f41SAndroid Build Coastguard Worker# until recovery supports vold. 115*e4a36f41SAndroid Build Coastguard Workerneverallow fastbootd { 116*e4a36f41SAndroid Build Coastguard Worker data_file_type 117*e4a36f41SAndroid Build Coastguard Worker}:file { no_x_file_perms }; 118