blob: c0a2bd0d1e1c9bbfb0c8a5a1d99bf697806baa11 [file] [log] [blame]
Stephen Smalley6d10ca82014-01-13 09:45:45 -05001# recovery console (used in recovery init.rc for /sbin/recovery)
Stephen Smalleye60723a2014-05-29 16:40:15 -04002
3# Declare the domain unconditionally so we can always reference it
4# in neverallow rules.
Stephen Smalley6d10ca82014-01-13 09:45:45 -05005type recovery, domain;
Stephen Smalley6d10ca82014-01-13 09:45:45 -05006
Stephen Smalleye60723a2014-05-29 16:40:15 -04007# But the allow rules are only included in the recovery policy.
8# Otherwise recovery is only allowed the domain rules.
9recovery_only(`
Ethan Yonkerbf7fd2b2014-12-16 14:23:00 -060010 # Allow recovery to set permissive mode
11 permissive recovery;
12
Stephen Smalley1095d692014-06-19 12:15:22 -040013 allow recovery self:capability { chown dac_override fowner fsetid setfcap setuid setgid sys_admin sys_tty_config };
Nick Kralevich03dbf072014-06-03 16:16:21 -070014
Stephen Smalleye60723a2014-05-29 16:40:15 -040015 # Set security contexts on files that are not known to the loaded policy.
16 allow recovery self:capability2 mac_admin;
Stephen Smalley6d10ca82014-01-13 09:45:45 -050017
Stephen Smalleyf3c3a1a2014-06-19 09:07:17 -040018 # Run helpers from / or /system without changing domain.
19 allow recovery rootfs:file execute_no_trans;
20 allow recovery system_file:file execute_no_trans;
21
Stephen Smalleye60723a2014-05-29 16:40:15 -040022 # Mount filesystems.
Nick Kralevich03dbf072014-06-03 16:16:21 -070023 allow recovery rootfs:dir mounton;
Stephen Smalley75e2ef92014-06-16 13:05:38 -040024 allow recovery fs_type:filesystem ~relabelto;
25 allow recovery unlabeled:filesystem ~relabelto;
26 allow recovery contextmount_type:filesystem relabelto;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040027
Maarten Derks7a09aea2017-06-14 13:34:48 +020028 allow recovery selinuxfs:file rw_file_perms;
29
Nick Kralevicha03d7612014-06-04 23:43:03 -070030 # Create and relabel files and directories under /system.
31 allow recovery exec_type:{ file lnk_file } { create_file_perms relabelfrom relabelto };
32 allow recovery system_file:{ file lnk_file } { create_file_perms relabelfrom relabelto };
33 allow recovery system_file:dir { create_dir_perms relabelfrom relabelto };
34
Nick Kralevich558710c2014-07-07 13:19:24 -070035 # We may be asked to set an SELinux label for a type not known to the
36 # currently loaded policy. Allow it.
Nick Kralevich5fad3d92014-10-23 12:12:58 -070037 allow recovery unlabeled:{ file lnk_file } { create_file_perms relabelfrom relabelto };
Nick Kralevich558710c2014-07-07 13:19:24 -070038 allow recovery unlabeled:dir { create_dir_perms relabelfrom relabelto };
39
Nick Kralevichff409bb2014-06-15 09:40:12 -070040 # 0eb17d944704b3eb140bb9dded299d3be3aed77e in build/ added SELinux
41 # support to OTAs. However, that code has a bug. When an update occurs,
42 # some directories are inappropriately labeled as exec_type. This is
43 # only transient, and subsequent steps in the OTA script correct this
Nick Kralevichb76966d2015-03-05 14:58:30 -080044 # mistake. New devices are moving to block based OTAs, so this is not
45 # worth fixing. b/15575013
Nick Kralevichff409bb2014-06-15 09:40:12 -070046 allow recovery exec_type:dir { create_dir_perms relabelfrom relabelto };
Nick Kralevichff409bb2014-06-15 09:40:12 -070047
Nick Kralevicha03d7612014-06-04 23:43:03 -070048 # Write to /proc/sys/vm/drop_caches
Jeff Sharkeyc9605962015-05-14 20:55:31 -070049 allow recovery proc_drop_caches:file w_file_perms;
Nick Kralevich03ce5122014-05-20 11:09:16 -070050
Stephen Smalley1095d692014-06-19 12:15:22 -040051 # Write to /sys/class/android_usb/android0/enable.
52 # TODO: create more specific label?
53 allow recovery sysfs:file w_file_perms;
54
Patrick Tjinbd050a82014-12-09 12:43:26 -080055 access_kmsg(recovery)
56
Doug Zongkerbad4e912014-07-10 13:40:25 -070057 # Access /dev/android_adb or /dev/usb-ffs/adb/ep0
Stephen Smalley1095d692014-06-19 12:15:22 -040058 allow recovery adb_device:chr_file rw_file_perms;
Doug Zongkerbad4e912014-07-10 13:40:25 -070059 allow recovery functionfs:dir search;
60 allow recovery functionfs:file rw_file_perms;
Stephen Smalley1095d692014-06-19 12:15:22 -040061
Stephen Smalleye60723a2014-05-29 16:40:15 -040062 # Required to e.g. wipe userdata/cache.
Nick Kralevichff409bb2014-06-15 09:40:12 -070063 allow recovery device:dir r_dir_perms;
Nick Kralevich03dbf072014-06-03 16:16:21 -070064 allow recovery block_device:dir r_dir_perms;
Stephen Smalleye60723a2014-05-29 16:40:15 -040065 allow recovery dev_type:blk_file rw_file_perms;
Stephen Smalley3f40d4f2014-02-11 14:40:14 -050066
Stephen Smalleye60723a2014-05-29 16:40:15 -040067 # GUI
68 allow recovery self:process execmem;
69 allow recovery ashmem_device:chr_file execute;
Nick Kralevich03dbf072014-06-03 16:16:21 -070070 allow recovery graphics_device:chr_file rw_file_perms;
71 allow recovery graphics_device:dir r_dir_perms;
72 allow recovery input_device:dir r_dir_perms;
73 allow recovery input_device:chr_file r_file_perms;
Nick Kralevich8b7ca452014-06-07 11:48:35 -070074 allow recovery tty_device:chr_file rw_file_perms;
Stephen Smalley356f4be2014-05-23 11:26:19 -040075
Nick Kralevich03dbf072014-06-03 16:16:21 -070076 # 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
80 # Manage files on /cache
81 allow recovery cache_file:dir create_dir_perms;
82 allow recovery cache_file:file create_file_perms;
83
Tao Baod2457892015-06-10 15:52:49 -070084 # Read files on /oem.
85 r_dir_file(recovery, oemfs);
86
Nick Kralevich03dbf072014-06-03 16:16:21 -070087 # Reboot the device
William Roberts2f5a6a92015-05-04 18:22:45 -070088 set_prop(recovery, powerctl_prop)
Stephen Smalleye60723a2014-05-29 16:40:15 -040089
Stephen Smalleyfee49152014-06-19 10:27:02 -040090 # Start/stop adbd via ctl.start adbd
William Roberts2f5a6a92015-05-04 18:22:45 -070091 set_prop(recovery, ctl_default_prop)
Stephen Smalleyfee49152014-06-19 10:27:02 -040092
Stephen Smalleye60723a2014-05-29 16:40:15 -040093 # Use setfscreatecon() to label files for OTA updates.
94 allow recovery self:process setfscreate;
Nick Kralevich03dbf072014-06-03 16:16:21 -070095
Stephen Smalley374b2a12014-07-08 14:45:09 -040096 # Allow recovery to create a fuse filesystem, and read files from it.
Doug Zongker93d849b2014-07-02 10:28:20 -070097 allow recovery fuse_device:chr_file rw_file_perms;
Stephen Smalley374b2a12014-07-08 14:45:09 -040098 allow recovery fuse:dir r_dir_perms;
99 allow recovery fuse:file r_file_perms;
Doug Zongker93d849b2014-07-02 10:28:20 -0700100
Nick Kralevich03dbf072014-06-03 16:16:21 -0700101 wakelock_use(recovery)
Nick Kralevich8b7ca452014-06-07 11:48:35 -0700102
Nick Kralevichf4e69022014-06-09 20:35:51 -0700103 # This line seems suspect, as it should not really need to
Nick Kralevich8b7ca452014-06-07 11:48:35 -0700104 # set scheduling parameters for a kernel domain task.
Nick Kralevich03dbf072014-06-03 16:16:21 -0700105 allow recovery kernel:process setsched;
Stephen Smalleye60723a2014-05-29 16:40:15 -0400106')
Nick Kralevicha17a2662014-11-05 15:30:41 -0800107
108###
109### neverallow rules
110###
111
112# Recovery should never touch /data.
113#
114# In particular, if /data is encrypted, it is not accessible
115# to recovery anyway.
116#
117# For now, we only enforce write/execute restrictions, as domain.te
118# contains a number of read-only rules that apply to all
119# domains, including recovery.
120#
121# TODO: tighten this up further.
122neverallow recovery data_file_type:file { no_w_file_perms no_x_file_perms };
123neverallow recovery data_file_type:dir no_w_dir_perms;