1# recovery console (used in recovery init.rc for /sbin/recovery)
2
3# Declare the domain unconditionally so we can always reference it
4# in neverallow rules.
5type recovery, domain, domain_deprecated;
6
7# But the allow rules are only included in the recovery policy.
8# Otherwise recovery is only allowed the domain rules.
9recovery_only(`
10  allow recovery self:capability { chown dac_override fowner fsetid setfcap setuid setgid sys_admin sys_tty_config };
11
12  # Set security contexts on files that are not known to the loaded policy.
13  allow recovery self:capability2 mac_admin;
14
15  # Run helpers from / or /system without changing domain.
16  allow recovery rootfs:file execute_no_trans;
17  allow recovery system_file:file execute_no_trans;
18  allow recovery toolbox_exec:file rx_file_perms;
19
20  # Mount filesystems.
21  allow recovery rootfs:dir mounton;
22  allow recovery fs_type:filesystem ~relabelto;
23  allow recovery unlabeled:filesystem ~relabelto;
24  allow recovery contextmount_type:filesystem relabelto;
25
26  # Create and relabel files and directories under /system.
27  allow recovery exec_type:{ file lnk_file } { create_file_perms relabelfrom relabelto };
28  allow recovery system_file:{ file lnk_file } { create_file_perms relabelfrom relabelto };
29  allow recovery system_file:dir { create_dir_perms relabelfrom relabelto };
30
31  # We may be asked to set an SELinux label for a type not known to the
32  # currently loaded policy. Allow it.
33  allow recovery unlabeled:{ file lnk_file } { create_file_perms relabelfrom relabelto };
34  allow recovery unlabeled:dir { create_dir_perms relabelfrom relabelto };
35
36  # 0eb17d944704b3eb140bb9dded299d3be3aed77e in build/ added SELinux
37  # support to OTAs. However, that code has a bug. When an update occurs,
38  # some directories are inappropriately labeled as exec_type. This is
39  # only transient, and subsequent steps in the OTA script correct this
40  # mistake. New devices are moving to block based OTAs, so this is not
41  # worth fixing. b/15575013
42  allow recovery exec_type:dir { create_dir_perms relabelfrom relabelto };
43
44  # Write to /proc/sys/vm/drop_caches
45  allow recovery proc_drop_caches:file w_file_perms;
46
47  # Write to /sys/class/android_usb/android0/enable.
48  # TODO: create more specific label?
49  allow recovery sysfs:file w_file_perms;
50
51  allow recovery sysfs_batteryinfo:file r_file_perms;
52
53  allow recovery kernel:system syslog_read;
54
55  # Access /dev/android_adb or /dev/usb-ffs/adb/ep0
56  allow recovery adb_device:chr_file rw_file_perms;
57  allow recovery functionfs:dir search;
58  allow recovery functionfs:file rw_file_perms;
59
60  # Required to e.g. wipe userdata/cache.
61  allow recovery device:dir r_dir_perms;
62  allow recovery block_device:dir r_dir_perms;
63  allow recovery dev_type:blk_file rw_file_perms;
64
65  # GUI
66  allow recovery self:process execmem;
67  allow recovery ashmem_device:chr_file execute;
68  allow recovery graphics_device:chr_file rw_file_perms;
69  allow recovery graphics_device:dir r_dir_perms;
70  allow recovery input_device:dir r_dir_perms;
71  allow recovery input_device:chr_file r_file_perms;
72  allow recovery tty_device:chr_file rw_file_perms;
73
74  # Create /tmp/recovery.log and execute /tmp/update_binary.
75  allow recovery tmpfs:file { create_file_perms x_file_perms };
76  allow recovery tmpfs:dir create_dir_perms;
77
78  # Manage files on /cache and /cache/recovery
79  allow recovery { cache_file cache_recovery_file }:dir create_dir_perms;
80  allow recovery { cache_file cache_recovery_file }:file create_file_perms;
81
82  # Read files on /oem.
83  r_dir_file(recovery, oemfs);
84
85  # Reboot the device
86  set_prop(recovery, powerctl_prop)
87
88  # Start/stop adbd via ctl.start adbd
89  set_prop(recovery, ctl_default_prop)
90
91  # Use setfscreatecon() to label files for OTA updates.
92  allow recovery self:process setfscreate;
93
94  # Allow recovery to create a fuse filesystem, and read files from it.
95  allow recovery fuse_device:chr_file rw_file_perms;
96  allow recovery fuse:dir r_dir_perms;
97  allow recovery fuse:file r_file_perms;
98
99  wakelock_use(recovery)
100
101  # This line seems suspect, as it should not really need to
102  # set scheduling parameters for a kernel domain task.
103  allow recovery kernel:process setsched;
104')
105
106###
107### neverallow rules
108###
109
110# Recovery should never touch /data.
111#
112# In particular, if /data is encrypted, it is not accessible
113# to recovery anyway.
114#
115# For now, we only enforce write/execute restrictions, as domain.te
116# contains a number of read-only rules that apply to all
117# domains, including recovery.
118#
119# TODO: tighten this up further.
120neverallow recovery data_file_type:file { no_w_file_perms no_x_file_perms };
121neverallow recovery data_file_type:dir no_w_dir_perms;
122