recovery.te 5.6 KB

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