xref: /aosp_15_r20/system/sepolicy/private/recovery.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Workertypeattribute recovery coredomain;
2*e4a36f41SAndroid Build Coastguard Worker
3*e4a36f41SAndroid Build Coastguard Worker# The allow rules are only included in the recovery policy.
4*e4a36f41SAndroid Build Coastguard Worker# Otherwise recovery is only allowed the domain rules.
5*e4a36f41SAndroid Build Coastguard Workerrecovery_only(`
6*e4a36f41SAndroid Build Coastguard Worker  # Reboot the device
7*e4a36f41SAndroid Build Coastguard Worker  set_prop(recovery, powerctl_prop)
8*e4a36f41SAndroid Build Coastguard Worker
9*e4a36f41SAndroid Build Coastguard Worker  # Read serial number of the device from system properties
10*e4a36f41SAndroid Build Coastguard Worker  get_prop(recovery, serialno_prop)
11*e4a36f41SAndroid Build Coastguard Worker
12*e4a36f41SAndroid Build Coastguard Worker  # Set sys.usb.ffs.ready when starting minadbd for sideload.
13*e4a36f41SAndroid Build Coastguard Worker  get_prop(recovery, ffs_config_prop)
14*e4a36f41SAndroid Build Coastguard Worker  set_prop(recovery, ffs_control_prop)
15*e4a36f41SAndroid Build Coastguard Worker
16*e4a36f41SAndroid Build Coastguard Worker  # Set sys.usb.config when switching into fastboot.
17*e4a36f41SAndroid Build Coastguard Worker  set_prop(recovery, usb_control_prop)
18*e4a36f41SAndroid Build Coastguard Worker  set_prop(recovery, usb_prop)
19*e4a36f41SAndroid Build Coastguard Worker
20*e4a36f41SAndroid Build Coastguard Worker  # Read ro.boot.bootreason
21*e4a36f41SAndroid Build Coastguard Worker  get_prop(recovery, bootloader_boot_reason_prop)
22*e4a36f41SAndroid Build Coastguard Worker
23*e4a36f41SAndroid Build Coastguard Worker  # Read storage properties (for correctly formatting filesystems)
24*e4a36f41SAndroid Build Coastguard Worker  get_prop(recovery, storage_config_prop)
25*e4a36f41SAndroid Build Coastguard Worker
26*e4a36f41SAndroid Build Coastguard Worker  set_prop(recovery, gsid_prop)
27*e4a36f41SAndroid Build Coastguard Worker
28*e4a36f41SAndroid Build Coastguard Worker  # These are needed to allow recovery to manage network
29*e4a36f41SAndroid Build Coastguard Worker  allow recovery self:netlink_route_socket { create write read nlmsg_readpriv nlmsg_read };
30*e4a36f41SAndroid Build Coastguard Worker  allow recovery self:global_capability_class_set net_admin;
31*e4a36f41SAndroid Build Coastguard Worker  allow recovery self:tcp_socket { create ioctl };
32*e4a36f41SAndroid Build Coastguard Worker  allowxperm recovery self:tcp_socket ioctl { SIOCGIFFLAGS SIOCSIFFLAGS };
33*e4a36f41SAndroid Build Coastguard Worker
34*e4a36f41SAndroid Build Coastguard Worker  # Start snapuserd for merging VABC updates
35*e4a36f41SAndroid Build Coastguard Worker  set_prop(recovery, ctl_snapuserd_prop)
36*e4a36f41SAndroid Build Coastguard Worker
37*e4a36f41SAndroid Build Coastguard Worker  # Needed to communicate with snapuserd to complete merges.
38*e4a36f41SAndroid Build Coastguard Worker  allow recovery snapuserd_socket:sock_file write;
39*e4a36f41SAndroid Build Coastguard Worker  allow recovery snapuserd:unix_stream_socket connectto;
40*e4a36f41SAndroid Build Coastguard Worker  allow recovery dm_user_device:dir r_dir_perms;
41*e4a36f41SAndroid Build Coastguard Worker  get_prop(recovery, snapuserd_prop)
42*e4a36f41SAndroid Build Coastguard Worker
43*e4a36f41SAndroid Build Coastguard Worker  # Set fastbootd protocol property
44*e4a36f41SAndroid Build Coastguard Worker  set_prop(recovery, fastbootd_protocol_prop)
45*e4a36f41SAndroid Build Coastguard Worker
46*e4a36f41SAndroid Build Coastguard Worker  get_prop(recovery, recovery_config_prop)
47*e4a36f41SAndroid Build Coastguard Worker
48*e4a36f41SAndroid Build Coastguard Worker  # Needed to read bootconfig parameters through libfs_mgr
49*e4a36f41SAndroid Build Coastguard Worker  allow recovery proc_bootconfig:file r_file_perms;
50*e4a36f41SAndroid Build Coastguard Worker
51*e4a36f41SAndroid Build Coastguard Worker  # Allow recovery to perform an update as update_engine would do.
52*e4a36f41SAndroid Build Coastguard Worker  typeattribute recovery update_engine_common;
53*e4a36f41SAndroid Build Coastguard Worker  # Recovery can use HIDL HALs in passthrough mode
54*e4a36f41SAndroid Build Coastguard Worker  passthrough_hal_client_domain(recovery, hal_bootctl)
55*e4a36f41SAndroid Build Coastguard Worker
56*e4a36f41SAndroid Build Coastguard Worker  # Recovery can use AIDL HALs in binder mode
57*e4a36f41SAndroid Build Coastguard Worker  binder_use(recovery)
58*e4a36f41SAndroid Build Coastguard Worker  hal_client_domain(recovery, hal_health)
59*e4a36f41SAndroid Build Coastguard Worker
60*e4a36f41SAndroid Build Coastguard Worker  allow recovery self:global_capability_class_set {
61*e4a36f41SAndroid Build Coastguard Worker    chown
62*e4a36f41SAndroid Build Coastguard Worker    dac_override
63*e4a36f41SAndroid Build Coastguard Worker    dac_read_search
64*e4a36f41SAndroid Build Coastguard Worker    fowner
65*e4a36f41SAndroid Build Coastguard Worker    setuid
66*e4a36f41SAndroid Build Coastguard Worker    setgid
67*e4a36f41SAndroid Build Coastguard Worker    sys_admin
68*e4a36f41SAndroid Build Coastguard Worker    sys_tty_config
69*e4a36f41SAndroid Build Coastguard Worker  };
70*e4a36f41SAndroid Build Coastguard Worker
71*e4a36f41SAndroid Build Coastguard Worker  # Run helpers from / or /system without changing domain.
72*e4a36f41SAndroid Build Coastguard Worker  r_dir_file(recovery, rootfs)
73*e4a36f41SAndroid Build Coastguard Worker  allow recovery rootfs:file execute_no_trans;
74*e4a36f41SAndroid Build Coastguard Worker  allow recovery system_file:file execute_no_trans;
75*e4a36f41SAndroid Build Coastguard Worker  allow recovery toolbox_exec:file rx_file_perms;
76*e4a36f41SAndroid Build Coastguard Worker
77*e4a36f41SAndroid Build Coastguard Worker  # Mount filesystems.
78*e4a36f41SAndroid Build Coastguard Worker  allow recovery rootfs:dir mounton;
79*e4a36f41SAndroid Build Coastguard Worker  allow recovery tmpfs:dir mounton;
80*e4a36f41SAndroid Build Coastguard Worker  allow recovery { fs_type enforce_debugfs_restriction(`-debugfs_type') }:filesystem ~relabelto;
81*e4a36f41SAndroid Build Coastguard Worker  allow recovery unlabeled:filesystem ~relabelto;
82*e4a36f41SAndroid Build Coastguard Worker  allow recovery contextmount_type:filesystem relabelto;
83*e4a36f41SAndroid Build Coastguard Worker
84*e4a36f41SAndroid Build Coastguard Worker  # We may be asked to set an SELinux label for a type not known to the
85*e4a36f41SAndroid Build Coastguard Worker  # currently loaded policy. Allow it.
86*e4a36f41SAndroid Build Coastguard Worker  allow recovery unlabeled:{ file lnk_file } { create_file_perms relabelfrom relabelto };
87*e4a36f41SAndroid Build Coastguard Worker  allow recovery unlabeled:dir { create_dir_perms relabelfrom relabelto };
88*e4a36f41SAndroid Build Coastguard Worker
89*e4a36f41SAndroid Build Coastguard Worker  # Get file contexts
90*e4a36f41SAndroid Build Coastguard Worker  allow recovery file_contexts_file:file r_file_perms;
91*e4a36f41SAndroid Build Coastguard Worker
92*e4a36f41SAndroid Build Coastguard Worker  # Write to /proc/sys/vm/drop_caches
93*e4a36f41SAndroid Build Coastguard Worker  allow recovery proc_drop_caches:file w_file_perms;
94*e4a36f41SAndroid Build Coastguard Worker
95*e4a36f41SAndroid Build Coastguard Worker  # Read /proc/swaps
96*e4a36f41SAndroid Build Coastguard Worker  allow recovery proc_swaps:file r_file_perms;
97*e4a36f41SAndroid Build Coastguard Worker
98*e4a36f41SAndroid Build Coastguard Worker  # Read kernel config through libvintf for OTA matching
99*e4a36f41SAndroid Build Coastguard Worker  allow recovery config_gz:file { open read getattr };
100*e4a36f41SAndroid Build Coastguard Worker
101*e4a36f41SAndroid Build Coastguard Worker  # Write to /sys/class/android_usb/android0/enable.
102*e4a36f41SAndroid Build Coastguard Worker  r_dir_file(recovery, sysfs_android_usb)
103*e4a36f41SAndroid Build Coastguard Worker  allow recovery sysfs_android_usb:file w_file_perms;
104*e4a36f41SAndroid Build Coastguard Worker
105*e4a36f41SAndroid Build Coastguard Worker  # Write to /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq.
106*e4a36f41SAndroid Build Coastguard Worker  allow recovery sysfs_devices_system_cpu:file w_file_perms;
107*e4a36f41SAndroid Build Coastguard Worker
108*e4a36f41SAndroid Build Coastguard Worker  allow recovery sysfs_batteryinfo:file r_file_perms;
109*e4a36f41SAndroid Build Coastguard Worker
110*e4a36f41SAndroid Build Coastguard Worker  # Read /sysfs/fs/ext4/features
111*e4a36f41SAndroid Build Coastguard Worker  r_dir_file(recovery, sysfs_fs_ext4_features)
112*e4a36f41SAndroid Build Coastguard Worker
113*e4a36f41SAndroid Build Coastguard Worker  # Read from /sys/class/leds/lcd-backlight/max_brightness and write to /s/c/l/l/brightness to
114*e4a36f41SAndroid Build Coastguard Worker  # control backlight brightness.
115*e4a36f41SAndroid Build Coastguard Worker  allow recovery sysfs_leds:dir r_dir_perms;
116*e4a36f41SAndroid Build Coastguard Worker  allow recovery sysfs_leds:file rw_file_perms;
117*e4a36f41SAndroid Build Coastguard Worker  allow recovery sysfs_leds:lnk_file read;
118*e4a36f41SAndroid Build Coastguard Worker
119*e4a36f41SAndroid Build Coastguard Worker  allow recovery kernel:system syslog_read;
120*e4a36f41SAndroid Build Coastguard Worker
121*e4a36f41SAndroid Build Coastguard Worker  # Access /dev/usb-ffs/adb/ep0
122*e4a36f41SAndroid Build Coastguard Worker  allow recovery functionfs:dir search;
123*e4a36f41SAndroid Build Coastguard Worker  allow recovery functionfs:file rw_file_perms;
124*e4a36f41SAndroid Build Coastguard Worker  allowxperm recovery functionfs:file ioctl FUNCTIONFS_ENDPOINT_DESC;
125*e4a36f41SAndroid Build Coastguard Worker
126*e4a36f41SAndroid Build Coastguard Worker  # Access to /sys/fs/selinux/policyvers for compatibility check
127*e4a36f41SAndroid Build Coastguard Worker  allow recovery selinuxfs:file r_file_perms;
128*e4a36f41SAndroid Build Coastguard Worker
129*e4a36f41SAndroid Build Coastguard Worker  # Required to e.g. wipe userdata/cache.
130*e4a36f41SAndroid Build Coastguard Worker  allow recovery device:dir r_dir_perms;
131*e4a36f41SAndroid Build Coastguard Worker  allow recovery block_device:dir r_dir_perms;
132*e4a36f41SAndroid Build Coastguard Worker  allow recovery dev_type:blk_file rw_file_perms;
133*e4a36f41SAndroid Build Coastguard Worker  allowxperm recovery { userdata_block_device metadata_block_device cache_block_device }:blk_file ioctl BLKPBSZGET;
134*e4a36f41SAndroid Build Coastguard Worker
135*e4a36f41SAndroid Build Coastguard Worker  # GUI
136*e4a36f41SAndroid Build Coastguard Worker  allow recovery graphics_device:chr_file rw_file_perms;
137*e4a36f41SAndroid Build Coastguard Worker  allow recovery graphics_device:dir r_dir_perms;
138*e4a36f41SAndroid Build Coastguard Worker  allow recovery input_device:dir r_dir_perms;
139*e4a36f41SAndroid Build Coastguard Worker  allow recovery input_device:chr_file r_file_perms;
140*e4a36f41SAndroid Build Coastguard Worker  allow recovery tty_device:chr_file rw_file_perms;
141*e4a36f41SAndroid Build Coastguard Worker
142*e4a36f41SAndroid Build Coastguard Worker  # Create /tmp/recovery.log and execute /tmp/update_binary.
143*e4a36f41SAndroid Build Coastguard Worker  allow recovery tmpfs:file { create_file_perms x_file_perms };
144*e4a36f41SAndroid Build Coastguard Worker  allow recovery tmpfs:dir create_dir_perms;
145*e4a36f41SAndroid Build Coastguard Worker
146*e4a36f41SAndroid Build Coastguard Worker  # Manage files on /cache and /cache/recovery
147*e4a36f41SAndroid Build Coastguard Worker  allow recovery { cache_file cache_recovery_file }:dir create_dir_perms;
148*e4a36f41SAndroid Build Coastguard Worker  allow recovery { cache_file cache_recovery_file }:file create_file_perms;
149*e4a36f41SAndroid Build Coastguard Worker
150*e4a36f41SAndroid Build Coastguard Worker  # Read /sys/class/thermal/*/temp for thermal info.
151*e4a36f41SAndroid Build Coastguard Worker  r_dir_file(recovery, sysfs_thermal)
152*e4a36f41SAndroid Build Coastguard Worker
153*e4a36f41SAndroid Build Coastguard Worker  # Read files on /oem.
154*e4a36f41SAndroid Build Coastguard Worker  r_dir_file(recovery, oemfs);
155*e4a36f41SAndroid Build Coastguard Worker
156*e4a36f41SAndroid Build Coastguard Worker  # Use setfscreatecon() to label files for OTA updates.
157*e4a36f41SAndroid Build Coastguard Worker  allow recovery self:process setfscreate;
158*e4a36f41SAndroid Build Coastguard Worker
159*e4a36f41SAndroid Build Coastguard Worker  # Allow recovery to create a fuse filesystem, and read files from it.
160*e4a36f41SAndroid Build Coastguard Worker  allow recovery fuse_device:chr_file rw_file_perms;
161*e4a36f41SAndroid Build Coastguard Worker  allow recovery fuse:dir r_dir_perms;
162*e4a36f41SAndroid Build Coastguard Worker  allow recovery fuse:file r_file_perms;
163*e4a36f41SAndroid Build Coastguard Worker
164*e4a36f41SAndroid Build Coastguard Worker  wakelock_use(recovery)
165*e4a36f41SAndroid Build Coastguard Worker
166*e4a36f41SAndroid Build Coastguard Worker  # This line seems suspect, as it should not really need to
167*e4a36f41SAndroid Build Coastguard Worker  # set scheduling parameters for a kernel domain task.
168*e4a36f41SAndroid Build Coastguard Worker  allow recovery kernel:process setsched;
169*e4a36f41SAndroid Build Coastguard Worker
170*e4a36f41SAndroid Build Coastguard Worker  # These are needed to update dynamic partitions in recovery.
171*e4a36f41SAndroid Build Coastguard Worker  r_dir_file(recovery, sysfs_dm)
172*e4a36f41SAndroid Build Coastguard Worker  allowxperm recovery super_block_device_type:blk_file ioctl { BLKIOMIN BLKALIGNOFF };
173*e4a36f41SAndroid Build Coastguard Worker
174*e4a36f41SAndroid Build Coastguard Worker  # Allow using libfiemap/gsid directly (no binder in recovery).
175*e4a36f41SAndroid Build Coastguard Worker  allow recovery gsi_metadata_file_type:dir search;
176*e4a36f41SAndroid Build Coastguard Worker  allow recovery ota_metadata_file:dir rw_dir_perms;
177*e4a36f41SAndroid Build Coastguard Worker  allow recovery ota_metadata_file:file create_file_perms;
178*e4a36f41SAndroid Build Coastguard Worker
179*e4a36f41SAndroid Build Coastguard Worker  # Allow mounting /metadata for writing update states
180*e4a36f41SAndroid Build Coastguard Worker  allow recovery metadata_file:dir { getattr mounton };
181*e4a36f41SAndroid Build Coastguard Worker
182*e4a36f41SAndroid Build Coastguard Worker  # Recovery uses liblogwrap to write fsck logs to kmsg, liblogwrap requires devpts.
183*e4a36f41SAndroid Build Coastguard Worker  allow recovery devpts:chr_file rw_file_perms;
184*e4a36f41SAndroid Build Coastguard Worker  allow recovery kmsg_device:chr_file { getattr w_file_perms };
185*e4a36f41SAndroid Build Coastguard Worker')
186*e4a36f41SAndroid Build Coastguard Worker
187*e4a36f41SAndroid Build Coastguard Worker###
188*e4a36f41SAndroid Build Coastguard Worker### neverallow rules
189*e4a36f41SAndroid Build Coastguard Worker###
190*e4a36f41SAndroid Build Coastguard Worker
191*e4a36f41SAndroid Build Coastguard Worker# Recovery should never touch /data.
192*e4a36f41SAndroid Build Coastguard Worker#
193*e4a36f41SAndroid Build Coastguard Worker# In particular, if /data is encrypted, it is not accessible
194*e4a36f41SAndroid Build Coastguard Worker# to recovery anyway.
195*e4a36f41SAndroid Build Coastguard Worker#
196*e4a36f41SAndroid Build Coastguard Worker# For now, we only enforce write/execute restrictions, as domain.te
197*e4a36f41SAndroid Build Coastguard Worker# contains a number of read-only rules that apply to all
198*e4a36f41SAndroid Build Coastguard Worker# domains, including recovery.
199*e4a36f41SAndroid Build Coastguard Worker#
200*e4a36f41SAndroid Build Coastguard Worker# TODO: tighten this up further.
201*e4a36f41SAndroid Build Coastguard Workerneverallow recovery {
202*e4a36f41SAndroid Build Coastguard Worker   data_file_type
203*e4a36f41SAndroid Build Coastguard Worker   -cache_file
204*e4a36f41SAndroid Build Coastguard Worker   -cache_recovery_file
205*e4a36f41SAndroid Build Coastguard Worker  with_native_coverage(`-method_trace_data_file')
206*e4a36f41SAndroid Build Coastguard Worker}:file { no_w_file_perms no_x_file_perms };
207*e4a36f41SAndroid Build Coastguard Workerneverallow recovery {
208*e4a36f41SAndroid Build Coastguard Worker   data_file_type
209*e4a36f41SAndroid Build Coastguard Worker   -cache_file
210*e4a36f41SAndroid Build Coastguard Worker   -cache_recovery_file
211*e4a36f41SAndroid Build Coastguard Worker  with_native_coverage(`-method_trace_data_file')
212*e4a36f41SAndroid Build Coastguard Worker}:dir no_w_dir_perms;
213