recovery.te 4.47 KB
Newer Older
1
# recovery console (used in recovery init.rc for /sbin/recovery)
2 3 4

# Declare the domain unconditionally so we can always reference it
# in neverallow rules.
5
type recovery, domain, domain_deprecated;
6

7 8 9
# But the allow rules are only included in the recovery policy.
# Otherwise recovery is only allowed the domain rules.
recovery_only(`
Stephen Smalley's avatar
Stephen Smalley committed
10
  allow recovery self:capability { chown dac_override fowner fsetid setfcap setuid setgid sys_admin sys_tty_config };
Nick Kralevich's avatar
Nick Kralevich committed
11

12 13
  # Set security contexts on files that are not known to the loaded policy.
  allow recovery self:capability2 mac_admin;
14

15 16 17
  # Run helpers from / or /system without changing domain.
  allow recovery rootfs:file execute_no_trans;
  allow recovery system_file:file execute_no_trans;
18
  allow recovery toolbox_exec:file rx_file_perms;
19

20
  # Mount filesystems.
Nick Kralevich's avatar
Nick Kralevich committed
21
  allow recovery rootfs:dir mounton;
22 23 24
  allow recovery fs_type:filesystem ~relabelto;
  allow recovery unlabeled:filesystem ~relabelto;
  allow recovery contextmount_type:filesystem relabelto;
25

Nick Kralevich's avatar
Nick Kralevich committed
26 27 28 29 30
  # Create and relabel files and directories under /system.
  allow recovery exec_type:{ file lnk_file } { create_file_perms relabelfrom relabelto };
  allow recovery system_file:{ file lnk_file } { create_file_perms relabelfrom relabelto };
  allow recovery system_file:dir { create_dir_perms relabelfrom relabelto };

31 32
  # We may be asked to set an SELinux label for a type not known to the
  # currently loaded policy. Allow it.
33
  allow recovery unlabeled:{ file lnk_file } { create_file_perms relabelfrom relabelto };
34 35
  allow recovery unlabeled:dir { create_dir_perms relabelfrom relabelto };

36 37 38 39
  # 0eb17d944704b3eb140bb9dded299d3be3aed77e in build/ added SELinux
  # support to OTAs. However, that code has a bug. When an update occurs,
  # some directories are inappropriately labeled as exec_type. This is
  # only transient, and subsequent steps in the OTA script correct this
40 41
  # mistake. New devices are moving to block based OTAs, so this is not
  # worth fixing. b/15575013
42 43
  allow recovery exec_type:dir { create_dir_perms relabelfrom relabelto };

Nick Kralevich's avatar
Nick Kralevich committed
44
  # Write to /proc/sys/vm/drop_caches
45
  allow recovery proc_drop_caches:file w_file_perms;
46

Stephen Smalley's avatar
Stephen Smalley committed
47 48 49 50
  # Write to /sys/class/android_usb/android0/enable.
  # TODO: create more specific label?
  allow recovery sysfs:file w_file_perms;

51 52
  access_kmsg(recovery)

53
  # Access /dev/android_adb or /dev/usb-ffs/adb/ep0
Stephen Smalley's avatar
Stephen Smalley committed
54
  allow recovery adb_device:chr_file rw_file_perms;
55 56
  allow recovery functionfs:dir search;
  allow recovery functionfs:file rw_file_perms;
Stephen Smalley's avatar
Stephen Smalley committed
57

58
  # Required to e.g. wipe userdata/cache.
59
  allow recovery device:dir r_dir_perms;
Nick Kralevich's avatar
Nick Kralevich committed
60
  allow recovery block_device:dir r_dir_perms;
61
  allow recovery dev_type:blk_file rw_file_perms;
62

63 64 65
  # GUI
  allow recovery self:process execmem;
  allow recovery ashmem_device:chr_file execute;
Nick Kralevich's avatar
Nick Kralevich committed
66 67 68 69
  allow recovery graphics_device:chr_file rw_file_perms;
  allow recovery graphics_device:dir r_dir_perms;
  allow recovery input_device:dir r_dir_perms;
  allow recovery input_device:chr_file r_file_perms;
Nick Kralevich's avatar
Nick Kralevich committed
70
  allow recovery tty_device:chr_file rw_file_perms;
Nick Kralevich's avatar
Nick Kralevich committed
71 72 73 74

  # Create /tmp/recovery.log and execute /tmp/update_binary.
  allow recovery tmpfs:file { create_file_perms x_file_perms };
  allow recovery tmpfs:dir create_dir_perms;
75

76 77 78
  # Manage files on /cache and /cache/recovery
  allow recovery { cache_file cache_recovery_file }:dir create_dir_perms;
  allow recovery { cache_file cache_recovery_file }:file create_file_perms;
Nick Kralevich's avatar
Nick Kralevich committed
79

80 81 82
  # Read files on /oem.
  r_dir_file(recovery, oemfs);

Nick Kralevich's avatar
Nick Kralevich committed
83
  # Reboot the device
84
  set_prop(recovery, powerctl_prop)
85

86
  # Start/stop adbd via ctl.start adbd
87
  set_prop(recovery, ctl_default_prop)
88

89 90
  # Use setfscreatecon() to label files for OTA updates.
  allow recovery self:process setfscreate;
Nick Kralevich's avatar
Nick Kralevich committed
91

92
  # Allow recovery to create a fuse filesystem, and read files from it.
93
  allow recovery fuse_device:chr_file rw_file_perms;
94 95
  allow recovery fuse:dir r_dir_perms;
  allow recovery fuse:file r_file_perms;
96

Nick Kralevich's avatar
Nick Kralevich committed
97
  wakelock_use(recovery)
Nick Kralevich's avatar
Nick Kralevich committed
98

99
  # This line seems suspect, as it should not really need to
Nick Kralevich's avatar
Nick Kralevich committed
100
  # set scheduling parameters for a kernel domain task.
Nick Kralevich's avatar
Nick Kralevich committed
101
  allow recovery kernel:process setsched;
102
')
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

###
### neverallow rules
###

# Recovery should never touch /data.
#
# In particular, if /data is encrypted, it is not accessible
# to recovery anyway.
#
# For now, we only enforce write/execute restrictions, as domain.te
# contains a number of read-only rules that apply to all
# domains, including recovery.
#
# TODO: tighten this up further.
neverallow recovery data_file_type:file { no_w_file_perms no_x_file_perms };
neverallow recovery data_file_type:dir no_w_dir_perms;