xref: /aosp_15_r20/system/sepolicy/prebuilts/api/202404/public/init.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# init is its own domain.
2*e4a36f41SAndroid Build Coastguard Workertype init, domain, mlstrustedsubject;
3*e4a36f41SAndroid Build Coastguard Workertype init_exec, system_file_type, exec_type, file_type;
4*e4a36f41SAndroid Build Coastguard Workertype init_tmpfs, file_type;
5*e4a36f41SAndroid Build Coastguard Worker
6*e4a36f41SAndroid Build Coastguard Worker# /dev/__null__ node created by init.
7*e4a36f41SAndroid Build Coastguard Workerallow init tmpfs:chr_file { create setattr unlink rw_file_perms };
8*e4a36f41SAndroid Build Coastguard Worker
9*e4a36f41SAndroid Build Coastguard Worker#
10*e4a36f41SAndroid Build Coastguard Worker# init direct restorecon calls.
11*e4a36f41SAndroid Build Coastguard Worker#
12*e4a36f41SAndroid Build Coastguard Worker# /dev/kmsg
13*e4a36f41SAndroid Build Coastguard Workerallow init tmpfs:chr_file relabelfrom;
14*e4a36f41SAndroid Build Coastguard Workerallow init kmsg_device:chr_file { getattr write relabelto };
15*e4a36f41SAndroid Build Coastguard Worker# /dev/kmsg_debug
16*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
17*e4a36f41SAndroid Build Coastguard Worker  allow init kmsg_debug_device:chr_file { open write relabelto };
18*e4a36f41SAndroid Build Coastguard Worker')
19*e4a36f41SAndroid Build Coastguard Worker
20*e4a36f41SAndroid Build Coastguard Worker# allow init to mount and unmount debugfs in debug builds
21*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
22*e4a36f41SAndroid Build Coastguard Worker  allow init debugfs:dir mounton;
23*e4a36f41SAndroid Build Coastguard Worker')
24*e4a36f41SAndroid Build Coastguard Worker
25*e4a36f41SAndroid Build Coastguard Worker# /dev/__properties__
26*e4a36f41SAndroid Build Coastguard Workerallow init properties_device:dir relabelto;
27*e4a36f41SAndroid Build Coastguard Workerallow init properties_serial:file { write relabelto };
28*e4a36f41SAndroid Build Coastguard Workerallow init property_type:file { append create getattr map open read relabelto rename setattr unlink write };
29*e4a36f41SAndroid Build Coastguard Worker# /dev/__properties__/property_info and /dev/__properties/appcompat_override/property_info
30*e4a36f41SAndroid Build Coastguard Workerallow init properties_device:file create_file_perms;
31*e4a36f41SAndroid Build Coastguard Workerallow init property_info:file relabelto;
32*e4a36f41SAndroid Build Coastguard Worker# /dev/event-log-tags
33*e4a36f41SAndroid Build Coastguard Workerallow init device:file relabelfrom;
34*e4a36f41SAndroid Build Coastguard Workerallow init runtime_event_log_tags_file:file { open write setattr relabelto create };
35*e4a36f41SAndroid Build Coastguard Worker# /dev/socket
36*e4a36f41SAndroid Build Coastguard Workerallow init { device socket_device dm_user_device }:dir relabelto;
37*e4a36f41SAndroid Build Coastguard Worker# allow init to establish connection and communicate with lmkd
38*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(init, lmkd, lmkd)
39*e4a36f41SAndroid Build Coastguard Worker# Relabel /dev nodes created in first stage init: /dev/console, /dev/null, /dev/ptmx, /dev/random
40*e4a36f41SAndroid Build Coastguard Worker# and /dev/urandom
41*e4a36f41SAndroid Build Coastguard Workerallow init { console_device null_device ptmx_device random_device } : chr_file relabelto;
42*e4a36f41SAndroid Build Coastguard Worker# /dev/device-mapper, /dev/block(/.*)?
43*e4a36f41SAndroid Build Coastguard Workerallow init tmpfs:{ chr_file blk_file } relabelfrom;
44*e4a36f41SAndroid Build Coastguard Workerallow init tmpfs:blk_file getattr;
45*e4a36f41SAndroid Build Coastguard Workerallow init block_device:{ dir blk_file lnk_file } relabelto;
46*e4a36f41SAndroid Build Coastguard Workerallow init dm_device:{ chr_file blk_file } relabelto;
47*e4a36f41SAndroid Build Coastguard Workerallow init dm_user_device:chr_file relabelto;
48*e4a36f41SAndroid Build Coastguard Workerallow init kernel:fd use;
49*e4a36f41SAndroid Build Coastguard Worker# restorecon for early mount device symlinks
50*e4a36f41SAndroid Build Coastguard Workerallow init tmpfs:lnk_file { getattr read relabelfrom };
51*e4a36f41SAndroid Build Coastguard Workerallow init {
52*e4a36f41SAndroid Build Coastguard Worker  metadata_block_device
53*e4a36f41SAndroid Build Coastguard Worker  misc_block_device
54*e4a36f41SAndroid Build Coastguard Worker  recovery_block_device
55*e4a36f41SAndroid Build Coastguard Worker  system_block_device
56*e4a36f41SAndroid Build Coastguard Worker  userdata_block_device
57*e4a36f41SAndroid Build Coastguard Worker}:{ blk_file lnk_file } relabelto;
58*e4a36f41SAndroid Build Coastguard Worker
59*e4a36f41SAndroid Build Coastguard Workerallow init dtbo_block_device:lnk_file relabelto;
60*e4a36f41SAndroid Build Coastguard Workerallow init super_block_device:lnk_file relabelto;
61*e4a36f41SAndroid Build Coastguard Worker
62*e4a36f41SAndroid Build Coastguard Worker# Create /mnt/sdcard -> /storage/self/primary symlink.
63*e4a36f41SAndroid Build Coastguard Workerallow init mnt_sdcard_file:lnk_file create;
64*e4a36f41SAndroid Build Coastguard Worker
65*e4a36f41SAndroid Build Coastguard Worker# setrlimit
66*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set sys_resource;
67*e4a36f41SAndroid Build Coastguard Worker
68*e4a36f41SAndroid Build Coastguard Worker# Remove /dev/.booting and load /debug_ramdisk/* files
69*e4a36f41SAndroid Build Coastguard Workerallow init tmpfs:file { getattr unlink };
70*e4a36f41SAndroid Build Coastguard Worker
71*e4a36f41SAndroid Build Coastguard Worker# Access pty created for fsck.
72*e4a36f41SAndroid Build Coastguard Workerallow init devpts:chr_file { read write open };
73*e4a36f41SAndroid Build Coastguard Worker
74*e4a36f41SAndroid Build Coastguard Worker# Create /dev/fscklogs files.
75*e4a36f41SAndroid Build Coastguard Workerallow init fscklogs:file create_file_perms;
76*e4a36f41SAndroid Build Coastguard Worker
77*e4a36f41SAndroid Build Coastguard Worker# Access /dev/__null__ node created prior to initial policy load.
78*e4a36f41SAndroid Build Coastguard Workerallow init tmpfs:chr_file write;
79*e4a36f41SAndroid Build Coastguard Worker
80*e4a36f41SAndroid Build Coastguard Worker# Access /dev/console.
81*e4a36f41SAndroid Build Coastguard Workerallow init console_device:chr_file rw_file_perms;
82*e4a36f41SAndroid Build Coastguard Worker
83*e4a36f41SAndroid Build Coastguard Worker# Access /dev/tty0.
84*e4a36f41SAndroid Build Coastguard Workerallow init tty_device:chr_file rw_file_perms;
85*e4a36f41SAndroid Build Coastguard Worker
86*e4a36f41SAndroid Build Coastguard Worker# Call mount(2).
87*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set sys_admin;
88*e4a36f41SAndroid Build Coastguard Worker
89*e4a36f41SAndroid Build Coastguard Worker# Call setns(2).
90*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set sys_chroot;
91*e4a36f41SAndroid Build Coastguard Worker
92*e4a36f41SAndroid Build Coastguard Worker# Create and mount on directories in /.
93*e4a36f41SAndroid Build Coastguard Workerallow init rootfs:dir create_dir_perms;
94*e4a36f41SAndroid Build Coastguard Workerallow init {
95*e4a36f41SAndroid Build Coastguard Worker    rootfs
96*e4a36f41SAndroid Build Coastguard Worker    cache_file
97*e4a36f41SAndroid Build Coastguard Worker    cgroup
98*e4a36f41SAndroid Build Coastguard Worker    linkerconfig_file
99*e4a36f41SAndroid Build Coastguard Worker    storage_file
100*e4a36f41SAndroid Build Coastguard Worker    mnt_user_file
101*e4a36f41SAndroid Build Coastguard Worker    system_data_file
102*e4a36f41SAndroid Build Coastguard Worker    system_data_root_file
103*e4a36f41SAndroid Build Coastguard Worker    system_dlkm_file
104*e4a36f41SAndroid Build Coastguard Worker    system_file
105*e4a36f41SAndroid Build Coastguard Worker    vendor_file
106*e4a36f41SAndroid Build Coastguard Worker    postinstall_mnt_dir
107*e4a36f41SAndroid Build Coastguard Worker    mirror_data_file
108*e4a36f41SAndroid Build Coastguard Worker    shell_data_file
109*e4a36f41SAndroid Build Coastguard Worker}:dir mounton;
110*e4a36f41SAndroid Build Coastguard Worker
111*e4a36f41SAndroid Build Coastguard Worker# Mount bpf fs on sys/fs/bpf
112*e4a36f41SAndroid Build Coastguard Workerallow init fs_bpf:dir mounton;
113*e4a36f41SAndroid Build Coastguard Worker
114*e4a36f41SAndroid Build Coastguard Worker# Mount on /dev/usb-ffs/adb.
115*e4a36f41SAndroid Build Coastguard Workerallow init device:dir mounton;
116*e4a36f41SAndroid Build Coastguard Worker
117*e4a36f41SAndroid Build Coastguard Worker# Mount tmpfs on /apex
118*e4a36f41SAndroid Build Coastguard Workerallow init apex_mnt_dir:dir mounton;
119*e4a36f41SAndroid Build Coastguard Worker
120*e4a36f41SAndroid Build Coastguard Worker# Bind-mount on /system/apex/com.android.art
121*e4a36f41SAndroid Build Coastguard Workerallow init art_apex_dir:dir mounton;
122*e4a36f41SAndroid Build Coastguard Worker
123*e4a36f41SAndroid Build Coastguard Worker# Create and remove symlinks in /.
124*e4a36f41SAndroid Build Coastguard Workerallow init rootfs:lnk_file { create unlink };
125*e4a36f41SAndroid Build Coastguard Worker
126*e4a36f41SAndroid Build Coastguard Worker# Mount debugfs on /sys/kernel/debug.
127*e4a36f41SAndroid Build Coastguard Workerallow init sysfs:dir mounton;
128*e4a36f41SAndroid Build Coastguard Worker
129*e4a36f41SAndroid Build Coastguard Worker# Create cgroups mount points in tmpfs and mount cgroups on them.
130*e4a36f41SAndroid Build Coastguard Workerallow init tmpfs:dir create_dir_perms;
131*e4a36f41SAndroid Build Coastguard Workerallow init tmpfs:dir mounton;
132*e4a36f41SAndroid Build Coastguard Workerallow init cgroup:dir create_dir_perms;
133*e4a36f41SAndroid Build Coastguard Workerallow init cgroup:file rw_file_perms;
134*e4a36f41SAndroid Build Coastguard Workerallow init cgroup_rc_file:file rw_file_perms;
135*e4a36f41SAndroid Build Coastguard Workerallow init cgroup_desc_file:file r_file_perms;
136*e4a36f41SAndroid Build Coastguard Workerallow init cgroup_desc_api_file:file r_file_perms;
137*e4a36f41SAndroid Build Coastguard Workerallow init vendor_cgroup_desc_file:file r_file_perms;
138*e4a36f41SAndroid Build Coastguard Workerallow init cgroup_v2:dir { mounton create_dir_perms};
139*e4a36f41SAndroid Build Coastguard Workerallow init cgroup_v2:file rw_file_perms;
140*e4a36f41SAndroid Build Coastguard Worker
141*e4a36f41SAndroid Build Coastguard Worker# /config
142*e4a36f41SAndroid Build Coastguard Workerallow init configfs:dir mounton;
143*e4a36f41SAndroid Build Coastguard Workerallow init configfs:dir create_dir_perms;
144*e4a36f41SAndroid Build Coastguard Workerallow init configfs:{ file lnk_file } create_file_perms;
145*e4a36f41SAndroid Build Coastguard Worker
146*e4a36f41SAndroid Build Coastguard Worker# /metadata
147*e4a36f41SAndroid Build Coastguard Workerallow init metadata_file:dir mounton;
148*e4a36f41SAndroid Build Coastguard Worker
149*e4a36f41SAndroid Build Coastguard Worker# Run restorecon on /dev
150*e4a36f41SAndroid Build Coastguard Workerallow init tmpfs:dir relabelfrom;
151*e4a36f41SAndroid Build Coastguard Worker
152*e4a36f41SAndroid Build Coastguard Worker# Create directories under /dev/cpuctl after chowning it to system.
153*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set { dac_override dac_read_search };
154*e4a36f41SAndroid Build Coastguard Worker
155*e4a36f41SAndroid Build Coastguard Worker# Set system clock.
156*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set sys_time;
157*e4a36f41SAndroid Build Coastguard Worker
158*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set { sys_rawio mknod };
159*e4a36f41SAndroid Build Coastguard Worker
160*e4a36f41SAndroid Build Coastguard Worker# Mounting filesystems from block devices.
161*e4a36f41SAndroid Build Coastguard Workerallow init dev_type:blk_file r_file_perms;
162*e4a36f41SAndroid Build Coastguard Workerallowxperm init dev_type:blk_file ioctl BLKROSET;
163*e4a36f41SAndroid Build Coastguard Workerallowxperm init system_data_root_file:dir ioctl F2FS_IOC_SHUTDOWN;
164*e4a36f41SAndroid Build Coastguard Worker
165*e4a36f41SAndroid Build Coastguard Worker# Mounting filesystems.
166*e4a36f41SAndroid Build Coastguard Worker# Only allow relabelto for types used in context= mount options,
167*e4a36f41SAndroid Build Coastguard Worker# which should all be assigned the contextmount_type attribute.
168*e4a36f41SAndroid Build Coastguard Worker# This can be done in device-specific policy via type or typeattribute
169*e4a36f41SAndroid Build Coastguard Worker# declarations.
170*e4a36f41SAndroid Build Coastguard Workerallow init {
171*e4a36f41SAndroid Build Coastguard Worker  fs_type
172*e4a36f41SAndroid Build Coastguard Worker  enforce_debugfs_restriction(`-debugfs_type')
173*e4a36f41SAndroid Build Coastguard Worker}:filesystem ~relabelto;
174*e4a36f41SAndroid Build Coastguard Worker
175*e4a36f41SAndroid Build Coastguard Worker# Allow init to mount/unmount debugfs in non-user builds.
176*e4a36f41SAndroid Build Coastguard Workerenforce_debugfs_restriction(`
177*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`allow init debugfs_type:filesystem { mount unmount };')
178*e4a36f41SAndroid Build Coastguard Worker')
179*e4a36f41SAndroid Build Coastguard Worker
180*e4a36f41SAndroid Build Coastguard Worker# Allow init to mount tracefs in /sys/kernel/tracing
181*e4a36f41SAndroid Build Coastguard Workerallow init debugfs_tracing_debug:filesystem mount;
182*e4a36f41SAndroid Build Coastguard Worker
183*e4a36f41SAndroid Build Coastguard Workerallow init unlabeled:filesystem ~relabelto;
184*e4a36f41SAndroid Build Coastguard Workerallow init contextmount_type:filesystem relabelto;
185*e4a36f41SAndroid Build Coastguard Worker
186*e4a36f41SAndroid Build Coastguard Worker# Allow read-only access to context= mounted filesystems.
187*e4a36f41SAndroid Build Coastguard Workerallow init contextmount_type:dir r_dir_perms;
188*e4a36f41SAndroid Build Coastguard Workerallow init contextmount_type:notdevfile_class_set r_file_perms;
189*e4a36f41SAndroid Build Coastguard Worker
190*e4a36f41SAndroid Build Coastguard Worker# restorecon /adb_keys or any other rootfs files and directories to a more
191*e4a36f41SAndroid Build Coastguard Worker# specific type.
192*e4a36f41SAndroid Build Coastguard Workerallow init rootfs:{ dir file } relabelfrom;
193*e4a36f41SAndroid Build Coastguard Worker
194*e4a36f41SAndroid Build Coastguard Worker# mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files.
195*e4a36f41SAndroid Build Coastguard Worker# chown/chmod require open+read+setattr required for open()+fchown/fchmod().
196*e4a36f41SAndroid Build Coastguard Worker# system/core/init.rc requires at least cache_file and data_file_type.
197*e4a36f41SAndroid Build Coastguard Worker# init.<board>.rc files often include device-specific types, so
198*e4a36f41SAndroid Build Coastguard Worker# we just allow all file types except /system files here.
199*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set { chown fowner fsetid };
200*e4a36f41SAndroid Build Coastguard Worker
201*e4a36f41SAndroid Build Coastguard Workerallow init {
202*e4a36f41SAndroid Build Coastguard Worker  file_type
203*e4a36f41SAndroid Build Coastguard Worker  -app_data_file
204*e4a36f41SAndroid Build Coastguard Worker  -bpffs_type
205*e4a36f41SAndroid Build Coastguard Worker  -exec_type
206*e4a36f41SAndroid Build Coastguard Worker  -misc_logd_file
207*e4a36f41SAndroid Build Coastguard Worker  -nativetest_data_file
208*e4a36f41SAndroid Build Coastguard Worker  -privapp_data_file
209*e4a36f41SAndroid Build Coastguard Worker  -system_app_data_file
210*e4a36f41SAndroid Build Coastguard Worker  -system_dlkm_file_type
211*e4a36f41SAndroid Build Coastguard Worker  -system_file_type
212*e4a36f41SAndroid Build Coastguard Worker  -vendor_file_type
213*e4a36f41SAndroid Build Coastguard Worker}:dir { create search getattr open read setattr ioctl };
214*e4a36f41SAndroid Build Coastguard Worker
215*e4a36f41SAndroid Build Coastguard Workerallow init {
216*e4a36f41SAndroid Build Coastguard Worker  file_type
217*e4a36f41SAndroid Build Coastguard Worker  -app_data_file
218*e4a36f41SAndroid Build Coastguard Worker  -bpffs_type
219*e4a36f41SAndroid Build Coastguard Worker  -credstore_data_file
220*e4a36f41SAndroid Build Coastguard Worker  -exec_type
221*e4a36f41SAndroid Build Coastguard Worker  -keystore_data_file
222*e4a36f41SAndroid Build Coastguard Worker  -media_userdir_file
223*e4a36f41SAndroid Build Coastguard Worker  -misc_logd_file
224*e4a36f41SAndroid Build Coastguard Worker  -nativetest_data_file
225*e4a36f41SAndroid Build Coastguard Worker  -privapp_data_file
226*e4a36f41SAndroid Build Coastguard Worker  -shell_data_file
227*e4a36f41SAndroid Build Coastguard Worker  -system_app_data_file
228*e4a36f41SAndroid Build Coastguard Worker  -system_dlkm_file_type
229*e4a36f41SAndroid Build Coastguard Worker  -system_file_type
230*e4a36f41SAndroid Build Coastguard Worker  -system_userdir_file
231*e4a36f41SAndroid Build Coastguard Worker  -vendor_file_type
232*e4a36f41SAndroid Build Coastguard Worker  -vendor_userdir_file
233*e4a36f41SAndroid Build Coastguard Worker  -vold_data_file
234*e4a36f41SAndroid Build Coastguard Worker}:dir { write add_name remove_name rmdir relabelfrom };
235*e4a36f41SAndroid Build Coastguard Worker
236*e4a36f41SAndroid Build Coastguard Workerallow init {
237*e4a36f41SAndroid Build Coastguard Worker  file_type
238*e4a36f41SAndroid Build Coastguard Worker  -apex_info_file
239*e4a36f41SAndroid Build Coastguard Worker  -app_data_file
240*e4a36f41SAndroid Build Coastguard Worker  -bpffs_type
241*e4a36f41SAndroid Build Coastguard Worker  -exec_type
242*e4a36f41SAndroid Build Coastguard Worker  -gsi_data_file
243*e4a36f41SAndroid Build Coastguard Worker  -credstore_data_file
244*e4a36f41SAndroid Build Coastguard Worker  -keystore_data_file
245*e4a36f41SAndroid Build Coastguard Worker  -misc_logd_file
246*e4a36f41SAndroid Build Coastguard Worker  -nativetest_data_file
247*e4a36f41SAndroid Build Coastguard Worker  -privapp_data_file
248*e4a36f41SAndroid Build Coastguard Worker  -runtime_event_log_tags_file
249*e4a36f41SAndroid Build Coastguard Worker  -shell_data_file
250*e4a36f41SAndroid Build Coastguard Worker  -system_app_data_file
251*e4a36f41SAndroid Build Coastguard Worker  -system_dlkm_file_type
252*e4a36f41SAndroid Build Coastguard Worker  -system_file_type
253*e4a36f41SAndroid Build Coastguard Worker  -vendor_file_type
254*e4a36f41SAndroid Build Coastguard Worker  -vold_data_file
255*e4a36f41SAndroid Build Coastguard Worker  enforce_debugfs_restriction(`-debugfs_type')
256*e4a36f41SAndroid Build Coastguard Worker}:file { create getattr open read write setattr relabelfrom unlink map };
257*e4a36f41SAndroid Build Coastguard Worker
258*e4a36f41SAndroid Build Coastguard Workerallow init tracefs_type:file { create_file_perms relabelfrom };
259*e4a36f41SAndroid Build Coastguard Worker
260*e4a36f41SAndroid Build Coastguard Worker# Allow init to read /apex/apex-info-list.xml for preinstalled paths of APEXes to determine
261*e4a36f41SAndroid Build Coastguard Worker# subcontext for action/service defined in APEXes.
262*e4a36f41SAndroid Build Coastguard Workerallow init apex_info_file:file r_file_perms;
263*e4a36f41SAndroid Build Coastguard Worker
264*e4a36f41SAndroid Build Coastguard Workerallow init {
265*e4a36f41SAndroid Build Coastguard Worker  file_type
266*e4a36f41SAndroid Build Coastguard Worker  -app_data_file
267*e4a36f41SAndroid Build Coastguard Worker  -bpffs_type
268*e4a36f41SAndroid Build Coastguard Worker  -exec_type
269*e4a36f41SAndroid Build Coastguard Worker  -gsi_data_file
270*e4a36f41SAndroid Build Coastguard Worker  -credstore_data_file
271*e4a36f41SAndroid Build Coastguard Worker  -keystore_data_file
272*e4a36f41SAndroid Build Coastguard Worker  -misc_logd_file
273*e4a36f41SAndroid Build Coastguard Worker  -nativetest_data_file
274*e4a36f41SAndroid Build Coastguard Worker  -privapp_data_file
275*e4a36f41SAndroid Build Coastguard Worker  -shell_data_file
276*e4a36f41SAndroid Build Coastguard Worker  -system_app_data_file
277*e4a36f41SAndroid Build Coastguard Worker  -system_dlkm_file_type
278*e4a36f41SAndroid Build Coastguard Worker  -system_file_type
279*e4a36f41SAndroid Build Coastguard Worker  -vendor_file_type
280*e4a36f41SAndroid Build Coastguard Worker  -vold_data_file
281*e4a36f41SAndroid Build Coastguard Worker}:{ sock_file fifo_file } { create getattr open read setattr relabelfrom unlink };
282*e4a36f41SAndroid Build Coastguard Worker
283*e4a36f41SAndroid Build Coastguard Workerallow init {
284*e4a36f41SAndroid Build Coastguard Worker  file_type
285*e4a36f41SAndroid Build Coastguard Worker  -apex_mnt_dir
286*e4a36f41SAndroid Build Coastguard Worker  -app_data_file
287*e4a36f41SAndroid Build Coastguard Worker  -bpffs_type
288*e4a36f41SAndroid Build Coastguard Worker  -exec_type
289*e4a36f41SAndroid Build Coastguard Worker  -gsi_data_file
290*e4a36f41SAndroid Build Coastguard Worker  -credstore_data_file
291*e4a36f41SAndroid Build Coastguard Worker  -keystore_data_file
292*e4a36f41SAndroid Build Coastguard Worker  -misc_logd_file
293*e4a36f41SAndroid Build Coastguard Worker  -nativetest_data_file
294*e4a36f41SAndroid Build Coastguard Worker  -privapp_data_file
295*e4a36f41SAndroid Build Coastguard Worker  -shell_data_file
296*e4a36f41SAndroid Build Coastguard Worker  -system_app_data_file
297*e4a36f41SAndroid Build Coastguard Worker  -system_dlkm_file_type
298*e4a36f41SAndroid Build Coastguard Worker  -system_file_type
299*e4a36f41SAndroid Build Coastguard Worker  -vendor_file_type
300*e4a36f41SAndroid Build Coastguard Worker  -vold_data_file
301*e4a36f41SAndroid Build Coastguard Worker}:lnk_file { create getattr setattr relabelfrom unlink };
302*e4a36f41SAndroid Build Coastguard Worker
303*e4a36f41SAndroid Build Coastguard Workerallow init cache_file:lnk_file r_file_perms;
304*e4a36f41SAndroid Build Coastguard Worker
305*e4a36f41SAndroid Build Coastguard Workerallow init {
306*e4a36f41SAndroid Build Coastguard Worker  file_type
307*e4a36f41SAndroid Build Coastguard Worker  -bpffs_type
308*e4a36f41SAndroid Build Coastguard Worker  -system_dlkm_file_type
309*e4a36f41SAndroid Build Coastguard Worker  -system_file_type
310*e4a36f41SAndroid Build Coastguard Worker  -vendor_file_type
311*e4a36f41SAndroid Build Coastguard Worker  -exec_type
312*e4a36f41SAndroid Build Coastguard Worker  -app_data_file
313*e4a36f41SAndroid Build Coastguard Worker  -privapp_data_file
314*e4a36f41SAndroid Build Coastguard Worker}:dir_file_class_set relabelto;
315*e4a36f41SAndroid Build Coastguard Worker
316*e4a36f41SAndroid Build Coastguard Workerallow init { sysfs no_debugfs_restriction(`debugfs') debugfs_tracing debugfs_tracing_debug }:{ dir file lnk_file } { getattr relabelfrom };
317*e4a36f41SAndroid Build Coastguard Workerallow init { sysfs_type no_debugfs_restriction(`debugfs_type') tracefs_type }:{ dir file lnk_file } { relabelto getattr };
318*e4a36f41SAndroid Build Coastguard Workerallow init dev_type:dir create_dir_perms;
319*e4a36f41SAndroid Build Coastguard Workerallow init dev_type:lnk_file create;
320*e4a36f41SAndroid Build Coastguard Worker
321*e4a36f41SAndroid Build Coastguard Worker# Disable tracing by writing to /sys/kernel/debug/tracing/tracing_on
322*e4a36f41SAndroid Build Coastguard Workerallow init debugfs_tracing:file w_file_perms;
323*e4a36f41SAndroid Build Coastguard Worker
324*e4a36f41SAndroid Build Coastguard Worker# Setup and control wifi event tracing (see wifi-events.rc)
325*e4a36f41SAndroid Build Coastguard Workerallow init debugfs_tracing_instances:dir create_dir_perms;
326*e4a36f41SAndroid Build Coastguard Workerallow init debugfs_tracing_instances:file w_file_perms;
327*e4a36f41SAndroid Build Coastguard Workerallow init debugfs_wifi_tracing:file w_file_perms;
328*e4a36f41SAndroid Build Coastguard Worker
329*e4a36f41SAndroid Build Coastguard Worker# chown/chmod on pseudo files.
330*e4a36f41SAndroid Build Coastguard Workerallow init {
331*e4a36f41SAndroid Build Coastguard Worker  fs_type
332*e4a36f41SAndroid Build Coastguard Worker  -bpffs_type
333*e4a36f41SAndroid Build Coastguard Worker  -contextmount_type
334*e4a36f41SAndroid Build Coastguard Worker  -keychord_device
335*e4a36f41SAndroid Build Coastguard Worker  -proc_type
336*e4a36f41SAndroid Build Coastguard Worker  -sdcard_type
337*e4a36f41SAndroid Build Coastguard Worker  -fusefs_type
338*e4a36f41SAndroid Build Coastguard Worker  -sysfs_type
339*e4a36f41SAndroid Build Coastguard Worker  -rootfs
340*e4a36f41SAndroid Build Coastguard Worker  enforce_debugfs_restriction(`-debugfs_type')
341*e4a36f41SAndroid Build Coastguard Worker}:file { open read setattr };
342*e4a36f41SAndroid Build Coastguard Workerallow init {
343*e4a36f41SAndroid Build Coastguard Worker  fs_type
344*e4a36f41SAndroid Build Coastguard Worker  -bpffs_type
345*e4a36f41SAndroid Build Coastguard Worker  -contextmount_type
346*e4a36f41SAndroid Build Coastguard Worker  -sdcard_type
347*e4a36f41SAndroid Build Coastguard Worker  -fusefs_type
348*e4a36f41SAndroid Build Coastguard Worker  -rootfs
349*e4a36f41SAndroid Build Coastguard Worker}:dir { open read setattr search };
350*e4a36f41SAndroid Build Coastguard Worker
351*e4a36f41SAndroid Build Coastguard Workerallow init {
352*e4a36f41SAndroid Build Coastguard Worker  binder_device
353*e4a36f41SAndroid Build Coastguard Worker  console_device
354*e4a36f41SAndroid Build Coastguard Worker  devpts
355*e4a36f41SAndroid Build Coastguard Worker  dm_device
356*e4a36f41SAndroid Build Coastguard Worker  hwbinder_device
357*e4a36f41SAndroid Build Coastguard Worker  input_device
358*e4a36f41SAndroid Build Coastguard Worker  kmsg_device
359*e4a36f41SAndroid Build Coastguard Worker  null_device
360*e4a36f41SAndroid Build Coastguard Worker  owntty_device
361*e4a36f41SAndroid Build Coastguard Worker  pmsg_device
362*e4a36f41SAndroid Build Coastguard Worker  ptmx_device
363*e4a36f41SAndroid Build Coastguard Worker  random_device
364*e4a36f41SAndroid Build Coastguard Worker  tty_device
365*e4a36f41SAndroid Build Coastguard Worker  zero_device
366*e4a36f41SAndroid Build Coastguard Worker}:chr_file { read open };
367*e4a36f41SAndroid Build Coastguard Worker
368*e4a36f41SAndroid Build Coastguard Worker# Unlabeled file access for upgrades from 4.2.
369*e4a36f41SAndroid Build Coastguard Workerallow init unlabeled:dir { create_dir_perms relabelfrom };
370*e4a36f41SAndroid Build Coastguard Workerallow init unlabeled:notdevfile_class_set { create_file_perms relabelfrom };
371*e4a36f41SAndroid Build Coastguard Worker
372*e4a36f41SAndroid Build Coastguard Worker# Any operation that can modify the kernel ring buffer, e.g. clear
373*e4a36f41SAndroid Build Coastguard Worker# or a read that consumes the messages that were read.
374*e4a36f41SAndroid Build Coastguard Workerallow init kernel:system syslog_mod;
375*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability2_class_set syslog;
376*e4a36f41SAndroid Build Coastguard Worker
377*e4a36f41SAndroid Build Coastguard Worker# init access to /proc.
378*e4a36f41SAndroid Build Coastguard Workerr_dir_file(init, proc_net_type)
379*e4a36f41SAndroid Build Coastguard Workerallow init proc_filesystems:file r_file_perms;
380*e4a36f41SAndroid Build Coastguard Worker
381*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
382*e4a36f41SAndroid Build Coastguard Worker  # Overlayfs workdir write access check during mount to permit remount,rw
383*e4a36f41SAndroid Build Coastguard Worker  allow init overlayfs_file:dir { relabelfrom mounton write };
384*e4a36f41SAndroid Build Coastguard Worker  allow init overlayfs_file:file { append rename };
385*e4a36f41SAndroid Build Coastguard Worker  allow init overlayfs_file:chr_file unlink;
386*e4a36f41SAndroid Build Coastguard Worker  allow init system_block_device:blk_file { write };
387*e4a36f41SAndroid Build Coastguard Worker')
388*e4a36f41SAndroid Build Coastguard Worker
389*e4a36f41SAndroid Build Coastguard Workerallow init {
390*e4a36f41SAndroid Build Coastguard Worker  proc # b/67049235 processes /proc/<pid>/* files are mislabeled.
391*e4a36f41SAndroid Build Coastguard Worker  proc_bootconfig
392*e4a36f41SAndroid Build Coastguard Worker  proc_cmdline
393*e4a36f41SAndroid Build Coastguard Worker  proc_diskstats
394*e4a36f41SAndroid Build Coastguard Worker  proc_kmsg # Open /proc/kmsg for logd service.
395*e4a36f41SAndroid Build Coastguard Worker  proc_meminfo
396*e4a36f41SAndroid Build Coastguard Worker  proc_stat # Read /proc/stat for bootchart.
397*e4a36f41SAndroid Build Coastguard Worker  proc_uptime
398*e4a36f41SAndroid Build Coastguard Worker  proc_version
399*e4a36f41SAndroid Build Coastguard Worker}:file r_file_perms;
400*e4a36f41SAndroid Build Coastguard Worker
401*e4a36f41SAndroid Build Coastguard Workerallow init {
402*e4a36f41SAndroid Build Coastguard Worker  proc_abi
403*e4a36f41SAndroid Build Coastguard Worker  proc_cpu_alignment
404*e4a36f41SAndroid Build Coastguard Worker  proc_dirty
405*e4a36f41SAndroid Build Coastguard Worker  proc_hostname
406*e4a36f41SAndroid Build Coastguard Worker  proc_hung_task
407*e4a36f41SAndroid Build Coastguard Worker  proc_extra_free_kbytes
408*e4a36f41SAndroid Build Coastguard Worker  proc_net_type
409*e4a36f41SAndroid Build Coastguard Worker  proc_max_map_count
410*e4a36f41SAndroid Build Coastguard Worker  proc_min_free_order_shift
411*e4a36f41SAndroid Build Coastguard Worker  proc_overcommit_memory      # /proc/sys/vm/overcommit_memory
412*e4a36f41SAndroid Build Coastguard Worker  proc_panic
413*e4a36f41SAndroid Build Coastguard Worker  proc_page_cluster
414*e4a36f41SAndroid Build Coastguard Worker  proc_perf
415*e4a36f41SAndroid Build Coastguard Worker  proc_sched
416*e4a36f41SAndroid Build Coastguard Worker  proc_sysrq
417*e4a36f41SAndroid Build Coastguard Worker  proc_watermark_boost_factor
418*e4a36f41SAndroid Build Coastguard Worker}:file w_file_perms;
419*e4a36f41SAndroid Build Coastguard Worker
420*e4a36f41SAndroid Build Coastguard Workerallow init {
421*e4a36f41SAndroid Build Coastguard Worker  proc_security
422*e4a36f41SAndroid Build Coastguard Worker}:file rw_file_perms;
423*e4a36f41SAndroid Build Coastguard Worker
424*e4a36f41SAndroid Build Coastguard Worker# init chmod/chown access to /proc files.
425*e4a36f41SAndroid Build Coastguard Workerallow init {
426*e4a36f41SAndroid Build Coastguard Worker  proc_cmdline
427*e4a36f41SAndroid Build Coastguard Worker  proc_bootconfig
428*e4a36f41SAndroid Build Coastguard Worker  proc_kmsg
429*e4a36f41SAndroid Build Coastguard Worker  proc_net
430*e4a36f41SAndroid Build Coastguard Worker  proc_pagetypeinfo
431*e4a36f41SAndroid Build Coastguard Worker  proc_qtaguid_stat
432*e4a36f41SAndroid Build Coastguard Worker  proc_slabinfo
433*e4a36f41SAndroid Build Coastguard Worker  proc_sysrq
434*e4a36f41SAndroid Build Coastguard Worker  proc_qtaguid_ctrl
435*e4a36f41SAndroid Build Coastguard Worker  proc_vmallocinfo
436*e4a36f41SAndroid Build Coastguard Worker}:file setattr;
437*e4a36f41SAndroid Build Coastguard Worker
438*e4a36f41SAndroid Build Coastguard Worker# init access to /sys files.
439*e4a36f41SAndroid Build Coastguard Workerallow init {
440*e4a36f41SAndroid Build Coastguard Worker  sysfs_android_usb
441*e4a36f41SAndroid Build Coastguard Worker  sysfs_dm_verity
442*e4a36f41SAndroid Build Coastguard Worker  sysfs_leds
443*e4a36f41SAndroid Build Coastguard Worker  sysfs_power
444*e4a36f41SAndroid Build Coastguard Worker  sysfs_fs_f2fs
445*e4a36f41SAndroid Build Coastguard Worker  sysfs_dm
446*e4a36f41SAndroid Build Coastguard Worker  sysfs_lru_gen_enabled
447*e4a36f41SAndroid Build Coastguard Worker}:file w_file_perms;
448*e4a36f41SAndroid Build Coastguard Worker
449*e4a36f41SAndroid Build Coastguard Workerallow init {
450*e4a36f41SAndroid Build Coastguard Worker  sysfs_dt_firmware_android
451*e4a36f41SAndroid Build Coastguard Worker  sysfs_fs_ext4_features
452*e4a36f41SAndroid Build Coastguard Worker}:file r_file_perms;
453*e4a36f41SAndroid Build Coastguard Worker
454*e4a36f41SAndroid Build Coastguard Workerallow init {
455*e4a36f41SAndroid Build Coastguard Worker  sysfs_zram
456*e4a36f41SAndroid Build Coastguard Worker}:file rw_file_perms;
457*e4a36f41SAndroid Build Coastguard Worker
458*e4a36f41SAndroid Build Coastguard Worker# allow init to create loop devices with /dev/loop-control
459*e4a36f41SAndroid Build Coastguard Workerallow init loop_control_device:chr_file rw_file_perms;
460*e4a36f41SAndroid Build Coastguard Workerallow init loop_device:blk_file rw_file_perms;
461*e4a36f41SAndroid Build Coastguard Workerallowxperm init loop_device:blk_file ioctl {
462*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_FD
463*e4a36f41SAndroid Build Coastguard Worker  LOOP_CLR_FD
464*e4a36f41SAndroid Build Coastguard Worker  LOOP_CTL_GET_FREE
465*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_BLOCK_SIZE
466*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_DIRECT_IO
467*e4a36f41SAndroid Build Coastguard Worker  LOOP_GET_STATUS
468*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_STATUS64
469*e4a36f41SAndroid Build Coastguard Worker};
470*e4a36f41SAndroid Build Coastguard Worker
471*e4a36f41SAndroid Build Coastguard Worker# Allow init to write to vibrator/trigger
472*e4a36f41SAndroid Build Coastguard Workerallow init sysfs_vibrator:file w_file_perms;
473*e4a36f41SAndroid Build Coastguard Worker
474*e4a36f41SAndroid Build Coastguard Worker# init chmod/chown access to /sys files.
475*e4a36f41SAndroid Build Coastguard Workerallow init {
476*e4a36f41SAndroid Build Coastguard Worker  sysfs_android_usb
477*e4a36f41SAndroid Build Coastguard Worker  sysfs_devices_system_cpu
478*e4a36f41SAndroid Build Coastguard Worker  sysfs_ipv4
479*e4a36f41SAndroid Build Coastguard Worker  sysfs_leds
480*e4a36f41SAndroid Build Coastguard Worker  sysfs_lowmemorykiller
481*e4a36f41SAndroid Build Coastguard Worker  sysfs_power
482*e4a36f41SAndroid Build Coastguard Worker  sysfs_vibrator
483*e4a36f41SAndroid Build Coastguard Worker  sysfs_wake_lock
484*e4a36f41SAndroid Build Coastguard Worker  sysfs_zram
485*e4a36f41SAndroid Build Coastguard Worker}:file setattr;
486*e4a36f41SAndroid Build Coastguard Worker
487*e4a36f41SAndroid Build Coastguard Worker# Set usermodehelpers.
488*e4a36f41SAndroid Build Coastguard Workerallow init { usermodehelper sysfs_usermodehelper }:file rw_file_perms;
489*e4a36f41SAndroid Build Coastguard Worker
490*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set net_admin;
491*e4a36f41SAndroid Build Coastguard Worker
492*e4a36f41SAndroid Build Coastguard Worker# Reboot.
493*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set sys_boot;
494*e4a36f41SAndroid Build Coastguard Worker
495*e4a36f41SAndroid Build Coastguard Worker# Init will create /data/misc/logd when the property persist.logd.logpersistd is "logcatd".
496*e4a36f41SAndroid Build Coastguard Worker# Init will also walk through the directory as part of a recursive restorecon.
497*e4a36f41SAndroid Build Coastguard Workerallow init misc_logd_file:dir { add_name open create read getattr setattr search write };
498*e4a36f41SAndroid Build Coastguard Workerallow init misc_logd_file:file { open create getattr setattr write };
499*e4a36f41SAndroid Build Coastguard Worker
500*e4a36f41SAndroid Build Coastguard Worker# Support "adb shell stop"
501*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set kill;
502*e4a36f41SAndroid Build Coastguard Workerallow init domain:process { getpgid sigkill signal };
503*e4a36f41SAndroid Build Coastguard Worker
504*e4a36f41SAndroid Build Coastguard Worker# Init creates credstore's directory on boot, and walks through
505*e4a36f41SAndroid Build Coastguard Worker# the directory as part of a recursive restorecon.
506*e4a36f41SAndroid Build Coastguard Workerallow init credstore_data_file:dir { open create read getattr setattr search };
507*e4a36f41SAndroid Build Coastguard Workerallow init credstore_data_file:file { getattr };
508*e4a36f41SAndroid Build Coastguard Worker
509*e4a36f41SAndroid Build Coastguard Worker# Init creates keystore's directory on boot, and walks through
510*e4a36f41SAndroid Build Coastguard Worker# the directory as part of a recursive restorecon.
511*e4a36f41SAndroid Build Coastguard Workerallow init keystore_data_file:dir { open create read getattr setattr search };
512*e4a36f41SAndroid Build Coastguard Workerallow init keystore_data_file:file { getattr };
513*e4a36f41SAndroid Build Coastguard Worker
514*e4a36f41SAndroid Build Coastguard Worker# Init creates vold's directory on boot, and walks through
515*e4a36f41SAndroid Build Coastguard Worker# the directory as part of a recursive restorecon.
516*e4a36f41SAndroid Build Coastguard Workerallow init vold_data_file:dir { open create read getattr setattr search };
517*e4a36f41SAndroid Build Coastguard Workerallow init vold_data_file:file { getattr };
518*e4a36f41SAndroid Build Coastguard Worker
519*e4a36f41SAndroid Build Coastguard Worker# Init creates /data/local/tmp at boot
520*e4a36f41SAndroid Build Coastguard Workerallow init shell_data_file:dir { open create read getattr setattr search };
521*e4a36f41SAndroid Build Coastguard Workerallow init shell_data_file:file { getattr };
522*e4a36f41SAndroid Build Coastguard Worker
523*e4a36f41SAndroid Build Coastguard Worker# Set UID, GID, and adjust capability bounding set for services.
524*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set { setuid setgid setpcap };
525*e4a36f41SAndroid Build Coastguard Worker
526*e4a36f41SAndroid Build Coastguard Worker# For bootchart to read the /proc/$pid/cmdline file of each process,
527*e4a36f41SAndroid Build Coastguard Worker# we need to have following line to allow init to have access
528*e4a36f41SAndroid Build Coastguard Worker# to different domains.
529*e4a36f41SAndroid Build Coastguard Workerr_dir_file(init, domain)
530*e4a36f41SAndroid Build Coastguard Worker
531*e4a36f41SAndroid Build Coastguard Worker# Use setexeccon(), setfscreatecon(), and setsockcreatecon().
532*e4a36f41SAndroid Build Coastguard Worker# setexec is for services with seclabel options.
533*e4a36f41SAndroid Build Coastguard Worker# setfscreate is for labeling directories and socket files.
534*e4a36f41SAndroid Build Coastguard Worker# setsockcreate is for labeling local/unix domain sockets.
535*e4a36f41SAndroid Build Coastguard Workerallow init self:process { setexec setfscreate setsockcreate };
536*e4a36f41SAndroid Build Coastguard Worker
537*e4a36f41SAndroid Build Coastguard Worker# Get file context
538*e4a36f41SAndroid Build Coastguard Workerallow init file_contexts_file:file r_file_perms;
539*e4a36f41SAndroid Build Coastguard Worker
540*e4a36f41SAndroid Build Coastguard Worker# sepolicy access
541*e4a36f41SAndroid Build Coastguard Workerallow init sepolicy_file:file r_file_perms;
542*e4a36f41SAndroid Build Coastguard Worker
543*e4a36f41SAndroid Build Coastguard Worker# Perform SELinux access checks on setting properties.
544*e4a36f41SAndroid Build Coastguard Workerselinux_check_access(init)
545*e4a36f41SAndroid Build Coastguard Worker
546*e4a36f41SAndroid Build Coastguard Worker# Ask the kernel for the new context on services to label their sockets.
547*e4a36f41SAndroid Build Coastguard Workerallow init kernel:security compute_create;
548*e4a36f41SAndroid Build Coastguard Worker
549*e4a36f41SAndroid Build Coastguard Worker# Create sockets for the services.
550*e4a36f41SAndroid Build Coastguard Workerallow init domain:unix_stream_socket { create bind setopt };
551*e4a36f41SAndroid Build Coastguard Workerallow init domain:unix_dgram_socket { create bind setopt };
552*e4a36f41SAndroid Build Coastguard Worker
553*e4a36f41SAndroid Build Coastguard Worker# Create /data/property and files within it.
554*e4a36f41SAndroid Build Coastguard Workerallow init property_data_file:dir create_dir_perms;
555*e4a36f41SAndroid Build Coastguard Workerallow init property_data_file:file create_file_perms;
556*e4a36f41SAndroid Build Coastguard Worker
557*e4a36f41SAndroid Build Coastguard Worker# Set any property.
558*e4a36f41SAndroid Build Coastguard Workerallow init property_type:property_service set;
559*e4a36f41SAndroid Build Coastguard Worker
560*e4a36f41SAndroid Build Coastguard Worker# Send an SELinux userspace denial to the kernel audit subsystem,
561*e4a36f41SAndroid Build Coastguard Worker# so it can be picked up and processed by logd. These denials are
562*e4a36f41SAndroid Build Coastguard Worker# generated when an attempt to set a property is denied by policy.
563*e4a36f41SAndroid Build Coastguard Workerallow init self:netlink_audit_socket { create_socket_perms_no_ioctl nlmsg_relay };
564*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set audit_write;
565*e4a36f41SAndroid Build Coastguard Worker
566*e4a36f41SAndroid Build Coastguard Worker# Run "ifup lo" to bring up the localhost interface
567*e4a36f41SAndroid Build Coastguard Workerallow init self:udp_socket { create ioctl };
568*e4a36f41SAndroid Build Coastguard Worker# in addition to unpriv ioctls granted to all domains, init also needs:
569*e4a36f41SAndroid Build Coastguard Workerallowxperm init self:udp_socket ioctl SIOCSIFFLAGS;
570*e4a36f41SAndroid Build Coastguard Workerallow init self:global_capability_class_set net_raw;
571*e4a36f41SAndroid Build Coastguard Worker
572*e4a36f41SAndroid Build Coastguard Worker# Set scheduling info for psi monitor thread.
573*e4a36f41SAndroid Build Coastguard Worker# TODO: delete or revise this line b/131761776
574*e4a36f41SAndroid Build Coastguard Workerallow init kernel:process { getsched setsched };
575*e4a36f41SAndroid Build Coastguard Worker
576*e4a36f41SAndroid Build Coastguard Worker# swapon() needs write access to swap device
577*e4a36f41SAndroid Build Coastguard Worker# system/core/fs_mgr/fs_mgr.c - fs_mgr_swapon_all
578*e4a36f41SAndroid Build Coastguard Workerallow init swap_block_device:blk_file rw_file_perms;
579*e4a36f41SAndroid Build Coastguard Worker
580*e4a36f41SAndroid Build Coastguard Worker# Create and access /dev files without a specific type,
581*e4a36f41SAndroid Build Coastguard Worker# e.g. /dev/.coldboot_done, /dev/.booting
582*e4a36f41SAndroid Build Coastguard Worker# TODO:  Move these files into their own type unless they are
583*e4a36f41SAndroid Build Coastguard Worker# only ever accessed by init.
584*e4a36f41SAndroid Build Coastguard Workerallow init device:file create_file_perms;
585*e4a36f41SAndroid Build Coastguard Worker
586*e4a36f41SAndroid Build Coastguard Worker# keychord retrieval from /dev/input/ devices
587*e4a36f41SAndroid Build Coastguard Workerallow init input_device:dir r_dir_perms;
588*e4a36f41SAndroid Build Coastguard Workerallow init input_device:chr_file rw_file_perms;
589*e4a36f41SAndroid Build Coastguard Worker
590*e4a36f41SAndroid Build Coastguard Worker# Access device mapper for setting up dm-verity
591*e4a36f41SAndroid Build Coastguard Workerallow init dm_device:chr_file rw_file_perms;
592*e4a36f41SAndroid Build Coastguard Workerallow init dm_device:blk_file rw_file_perms;
593*e4a36f41SAndroid Build Coastguard Worker
594*e4a36f41SAndroid Build Coastguard Worker# Access dm-user for OTA boot
595*e4a36f41SAndroid Build Coastguard Workerallow init dm_user_device:chr_file rw_file_perms;
596*e4a36f41SAndroid Build Coastguard Worker
597*e4a36f41SAndroid Build Coastguard Worker# Access metadata block device for storing dm-verity state
598*e4a36f41SAndroid Build Coastguard Workerallow init metadata_block_device:blk_file rw_file_perms;
599*e4a36f41SAndroid Build Coastguard Worker
600*e4a36f41SAndroid Build Coastguard Worker# Read /sys/fs/pstore/console-ramoops to detect restarts caused
601*e4a36f41SAndroid Build Coastguard Worker# by dm-verity detecting corrupted blocks
602*e4a36f41SAndroid Build Coastguard Workerallow init pstorefs:dir search;
603*e4a36f41SAndroid Build Coastguard Workerallow init pstorefs:file r_file_perms;
604*e4a36f41SAndroid Build Coastguard Workerallow init kernel:system syslog_read;
605*e4a36f41SAndroid Build Coastguard Worker
606*e4a36f41SAndroid Build Coastguard Worker# linux keyring configuration
607*e4a36f41SAndroid Build Coastguard Workerallow init init:key { write search setattr };
608*e4a36f41SAndroid Build Coastguard Worker
609*e4a36f41SAndroid Build Coastguard Worker# Allow init to create /data/unencrypted
610*e4a36f41SAndroid Build Coastguard Workerallow init unencrypted_data_file:dir create_dir_perms;
611*e4a36f41SAndroid Build Coastguard Worker
612*e4a36f41SAndroid Build Coastguard Worker# Set encryption policy on dirs in /data
613*e4a36f41SAndroid Build Coastguard Workerallowxperm init { data_file_type unlabeled }:dir ioctl {
614*e4a36f41SAndroid Build Coastguard Worker  FS_IOC_GET_ENCRYPTION_POLICY
615*e4a36f41SAndroid Build Coastguard Worker  FS_IOC_SET_ENCRYPTION_POLICY
616*e4a36f41SAndroid Build Coastguard Worker};
617*e4a36f41SAndroid Build Coastguard Worker
618*e4a36f41SAndroid Build Coastguard Worker# Raw writes to misc block device
619*e4a36f41SAndroid Build Coastguard Workerallow init misc_block_device:blk_file w_file_perms;
620*e4a36f41SAndroid Build Coastguard Worker
621*e4a36f41SAndroid Build Coastguard Workerr_dir_file(init, system_file)
622*e4a36f41SAndroid Build Coastguard Workerr_dir_file(init, system_dlkm_file_type)
623*e4a36f41SAndroid Build Coastguard Workerr_dir_file(init, vendor_file_type)
624*e4a36f41SAndroid Build Coastguard Worker
625*e4a36f41SAndroid Build Coastguard Workerallow init system_data_file:file { getattr read };
626*e4a36f41SAndroid Build Coastguard Workerallow init system_data_file:lnk_file r_file_perms;
627*e4a36f41SAndroid Build Coastguard Worker
628*e4a36f41SAndroid Build Coastguard Worker# For init to be able to run shell scripts from vendor
629*e4a36f41SAndroid Build Coastguard Workerallow init vendor_shell_exec:file execute;
630*e4a36f41SAndroid Build Coastguard Worker
631*e4a36f41SAndroid Build Coastguard Worker# Metadata setup
632*e4a36f41SAndroid Build Coastguard Workerallow init vold_metadata_file:dir create_dir_perms;
633*e4a36f41SAndroid Build Coastguard Workerallow init vold_metadata_file:file getattr;
634*e4a36f41SAndroid Build Coastguard Workerallow init metadata_bootstat_file:dir create_dir_perms;
635*e4a36f41SAndroid Build Coastguard Workerallow init metadata_bootstat_file:file w_file_perms;
636*e4a36f41SAndroid Build Coastguard Workerallow init userspace_reboot_metadata_file:file w_file_perms;
637*e4a36f41SAndroid Build Coastguard Worker
638*e4a36f41SAndroid Build Coastguard Worker# Allow init to touch PSI monitors
639*e4a36f41SAndroid Build Coastguard Workerallow init proc_pressure_mem:file { rw_file_perms setattr };
640*e4a36f41SAndroid Build Coastguard Worker
641*e4a36f41SAndroid Build Coastguard Worker# init is using bootstrap bionic
642*e4a36f41SAndroid Build Coastguard Workeruse_bootstrap_libs(init)
643*e4a36f41SAndroid Build Coastguard Worker
644*e4a36f41SAndroid Build Coastguard Worker# stat the root dir of fuse filesystems (for the mount handler)
645*e4a36f41SAndroid Build Coastguard Workerallow init fuse:dir { search getattr };
646*e4a36f41SAndroid Build Coastguard Worker
647*e4a36f41SAndroid Build Coastguard Worker# allow filesystem tuning
648*e4a36f41SAndroid Build Coastguard Workerallow init userdata_sysdev:file create_file_perms;
649*e4a36f41SAndroid Build Coastguard Worker
650*e4a36f41SAndroid Build Coastguard Worker# allow disk tuning
651*e4a36f41SAndroid Build Coastguard Workerallow init rootdisk_sysdev:file create_file_perms;
652*e4a36f41SAndroid Build Coastguard Worker
653*e4a36f41SAndroid Build Coastguard Worker###
654*e4a36f41SAndroid Build Coastguard Worker### neverallow rules
655*e4a36f41SAndroid Build Coastguard Worker###
656*e4a36f41SAndroid Build Coastguard Worker
657*e4a36f41SAndroid Build Coastguard Worker# The init domain is only entered via an exec based transition from the
658*e4a36f41SAndroid Build Coastguard Worker# kernel domain, never via setcon().
659*e4a36f41SAndroid Build Coastguard Workerneverallow domain init:process dyntransition;
660*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -kernel } init:process transition;
661*e4a36f41SAndroid Build Coastguard Workerneverallow init { file_type fs_type -init_exec }:file entrypoint;
662*e4a36f41SAndroid Build Coastguard Worker
663*e4a36f41SAndroid Build Coastguard Worker# Never read/follow symlinks created by shell or untrusted apps.
664*e4a36f41SAndroid Build Coastguard Workerneverallow init shell_data_file:lnk_file read;
665*e4a36f41SAndroid Build Coastguard Workerneverallow init app_data_file_type:lnk_file read;
666*e4a36f41SAndroid Build Coastguard Worker
667*e4a36f41SAndroid Build Coastguard Worker# init should never execute a program without changing to another domain.
668*e4a36f41SAndroid Build Coastguard Workerneverallow init { file_type fs_type }:file execute_no_trans;
669*e4a36f41SAndroid Build Coastguard Worker
670*e4a36f41SAndroid Build Coastguard Worker# The use of sensitive environment variables, such as LD_PRELOAD, is disallowed
671*e4a36f41SAndroid Build Coastguard Worker# when init is executing other binaries. The use of LD_PRELOAD for init spawned
672*e4a36f41SAndroid Build Coastguard Worker# services is generally considered a no-no, as it injects libraries which the
673*e4a36f41SAndroid Build Coastguard Worker# binary was not expecting. This is especially problematic for APEXes. The use
674*e4a36f41SAndroid Build Coastguard Worker# of LD_PRELOAD via APEXes is a layering violation, and inappropriately loads
675*e4a36f41SAndroid Build Coastguard Worker# code into a process which wasn't expecting that code, with potentially
676*e4a36f41SAndroid Build Coastguard Worker# unexpected side effects. (b/140789528)
677*e4a36f41SAndroid Build Coastguard Workerneverallow init *:process noatsecure;
678*e4a36f41SAndroid Build Coastguard Worker
679*e4a36f41SAndroid Build Coastguard Worker# init can never add binder services
680*e4a36f41SAndroid Build Coastguard Workerneverallow init service_manager_type:service_manager { add find };
681*e4a36f41SAndroid Build Coastguard Worker# init can never list binder services
682*e4a36f41SAndroid Build Coastguard Workerneverallow init servicemanager:service_manager list;
683*e4a36f41SAndroid Build Coastguard Worker
684*e4a36f41SAndroid Build Coastguard Worker# Init should not be creating subdirectories in /data/local/tmp
685*e4a36f41SAndroid Build Coastguard Workerneverallow init shell_data_file:dir { write add_name remove_name };
686*e4a36f41SAndroid Build Coastguard Worker
687*e4a36f41SAndroid Build Coastguard Worker# Init should not access sysfs node that are not explicitly labeled.
688*e4a36f41SAndroid Build Coastguard Workerneverallow init sysfs:file { open write };
689*e4a36f41SAndroid Build Coastguard Worker
690*e4a36f41SAndroid Build Coastguard Worker# No domain should be allowed to ptrace init.
691*e4a36f41SAndroid Build Coastguard Workerneverallow * init:process ptrace;
692*e4a36f41SAndroid Build Coastguard Worker
693*e4a36f41SAndroid Build Coastguard Worker# init owns the root of /data
694*e4a36f41SAndroid Build Coastguard Worker# TODO(b/140259336) We want to remove vendor_init
695*e4a36f41SAndroid Build Coastguard Worker# TODO(b/141108496) We want to remove toolbox
696*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -toolbox -vendor_init -vold } system_data_root_file:dir { write add_name remove_name };
697