blob: 708d537ba3fa65da287bb7ea2e030f9f0bbde952 [file] [log] [blame]
Inseob Kime1389972021-07-19 07:48:34 +00001typeattribute init coredomain;
2
3tmpfs_domain(init)
4
5domain_trans(init, shell_exec, shell)
6domain_trans(init, init_exec, ueventd)
7domain_trans(init, init_exec, vendor_init)
8
9# Allow init to figure out name of dm-device from it's /dev/block/dm-XX path.
10# This is useful in case of remounting ext4 userdata into checkpointing mode,
11# since it potentially requires tearing down dm-devices (e.g. dm-bow, dm-crypto)
12# that userdata is mounted onto.
13allow init sysfs_dm:file read;
14
15# Second-stage init performs a test for whether the kernel has SELinux hooks
16# for the perf_event_open() syscall. This is done by testing for the syscall
17# outcomes corresponding to this policy.
18allow init self:perf_event { open cpu };
19allow init self:global_capability2_class_set perfmon;
20dontaudit init self:perf_event { kernel tracepoint read write };
21
22# Allow init to restore contexts of vd_device(/dev/block/vd[..]) when labeling
23# /dev/block.
24allow init vd_device:blk_file relabelto;
25
26# chown/chmod on devices.
27allow init {
28 dev_type
29 -hw_random_device
30 -kvm_device
31}:chr_file setattr;
32
33# /dev/__null__ node created by init.
34allow init tmpfs:chr_file { create setattr unlink rw_file_perms };
35
36# /dev/__properties__
37allow init properties_device:dir relabelto;
38allow init properties_serial:file { write relabelto };
39allow init property_type:file { append create getattr map open read relabelto rename setattr unlink write };
40# /dev/__properties__/property_info
41allow init properties_device:file create_file_perms;
42allow init property_info:file relabelto;
43# /dev/event-log-tags
44allow init device:file relabelfrom;
45allow init runtime_event_log_tags_file:file { open write setattr relabelto create };
46# /dev/socket
47allow init { device socket_device dm_user_device }:dir relabelto;
Inseob Kim85091cd2022-03-22 21:50:09 +090048# Relabel /dev nodes created in first stage init: /dev/console, /dev/null, /dev/ptmx, /dev/random
49# and /dev/urandom
50allow init { console_device null_device ptmx_device random_device } : chr_file relabelto;
Inseob Kime1389972021-07-19 07:48:34 +000051# /dev/device-mapper, /dev/block(/.*)?
52allow init tmpfs:{ chr_file blk_file } relabelfrom;
53allow init tmpfs:blk_file getattr;
54allow init block_device:{ dir blk_file lnk_file } relabelto;
55allow init dm_device:{ chr_file blk_file } relabelto;
56allow init dm_user_device:chr_file relabelto;
57allow init kernel:fd use;
58# restorecon for early mount device symlinks
59allow init tmpfs:lnk_file { getattr read relabelfrom };
60
61# setrlimit
62allow init self:global_capability_class_set sys_resource;
63
64# Remove /dev/.booting and load /debug_ramdisk/* files
65allow init tmpfs:file { getattr unlink };
66
67# Access pty created for fsck.
68allow init devpts:chr_file { read write open };
69
70# Access /dev/__null__ node created prior to initial policy load.
71allow init tmpfs:chr_file write;
72
73# Access /dev/console.
74allow init console_device:chr_file rw_file_perms;
75
76# Access /dev/tty0.
77allow init tty_device:chr_file rw_file_perms;
78
79# Call mount(2).
80allow init self:global_capability_class_set sys_admin;
81
82# Call setns(2).
83allow init self:global_capability_class_set sys_chroot;
84
85# Create and mount on directories in /.
86allow init rootfs:dir create_dir_perms;
87allow init {
88 rootfs
89 cgroup
90 linkerconfig_file
91 system_data_file
92 system_data_root_file
93 system_file
94 vendor_file
95}:dir mounton;
96
97# Mount bpf fs on sys/fs/bpf
98allow init fs_bpf:dir mounton;
99
100# Mount on /dev/usb-ffs/adb.
101allow init device:dir mounton;
102
103# Mount tmpfs on /apex
104allow init apex_mnt_dir:dir mounton;
105
106# Create and remove symlinks in /.
107allow init rootfs:lnk_file { create unlink };
108
109# Mount debugfs on /sys/kernel/debug.
110allow init sysfs:dir mounton;
111
112# Create cgroups mount points in tmpfs and mount cgroups on them.
113allow init tmpfs:dir create_dir_perms;
114allow init tmpfs:dir mounton;
115allow init cgroup:dir create_dir_perms;
116allow init cgroup:file rw_file_perms;
117allow init cgroup_rc_file:file rw_file_perms;
118allow init cgroup_desc_file:file r_file_perms;
119allow init cgroup_desc_api_file:file r_file_perms;
120allow init cgroup_v2:dir { mounton create_dir_perms};
121allow init cgroup_v2:file rw_file_perms;
122
123# Use tmpfs as /data, used for booting when /data is encrypted
124allow init tmpfs:dir relabelfrom;
125
126# Create directories under /dev/cpuctl after chowning it to system.
127allow init self:global_capability_class_set { dac_override dac_read_search };
128
129allow init self:global_capability_class_set { sys_rawio mknod };
130
131# Mounting filesystems from block devices.
132allow init dev_type:blk_file r_file_perms;
133allowxperm init dev_type:blk_file ioctl BLKROSET;
134
135# Mounting filesystems.
136# Only allow relabelto for types used in context= mount options,
137# which should all be assigned the contextmount_type attribute.
138# This can be done in device-specific policy via type or typeattribute
139# declarations.
140allow init {
141 fs_type
142}:filesystem ~relabelto;
143
144# Allow init to mount tracefs in /sys/kernel/tracing
145allow init debugfs_tracing_debug:filesystem mount;
146
147allow init unlabeled:filesystem ~relabelto;
148allow init contextmount_type:filesystem relabelto;
149
150# Allow read-only access to context= mounted filesystems.
151allow init contextmount_type:dir r_dir_perms;
152allow init contextmount_type:notdevfile_class_set r_file_perms;
153
154# restorecon /adb_keys or any other rootfs files and directories to a more
155# specific type.
156allow init rootfs:{ dir file } relabelfrom;
157
158# mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files.
159# chown/chmod require open+read+setattr required for open()+fchown/fchmod().
160# system/core/init.rc requires at least cache_file and data_file_type.
161# init.<board>.rc files often include device-specific types, so
162# we just allow all file types except /system files here.
163allow init self:global_capability_class_set { chown fowner fsetid };
164
165allow init {
166 file_type
167 -exec_type
168 -system_file_type
169 -vendor_file_type
170}:dir { create search getattr open read setattr ioctl };
171
172allow init {
173 file_type
174 -exec_type
Inseob Kime1389972021-07-19 07:48:34 +0000175 -shell_data_file
176 -system_file_type
177 -vendor_file_type
178}:dir { write add_name remove_name rmdir relabelfrom };
179
180allow init {
181 file_type
182 -apex_info_file
183 -exec_type
Inseob Kime1389972021-07-19 07:48:34 +0000184 -runtime_event_log_tags_file
185 -shell_data_file
186 -system_file_type
187 -vendor_file_type
188}:file { create getattr open read write setattr relabelfrom unlink map };
189
190allow init tracefs_type:file { create_file_perms relabelfrom };
191
192allow init {
193 file_type
194 -exec_type
Inseob Kime1389972021-07-19 07:48:34 +0000195 -shell_data_file
196 -system_file_type
197 -vendor_file_type
198}:{ sock_file fifo_file } { create getattr open read setattr relabelfrom unlink };
199
200allow init {
201 file_type
202 -apex_mnt_dir
203 -exec_type
Inseob Kime1389972021-07-19 07:48:34 +0000204 -shell_data_file
205 -system_file_type
206 -vendor_file_type
207}:lnk_file { create getattr setattr relabelfrom unlink };
208
209allow init {
210 file_type
211 -system_file_type
212 -vendor_file_type
213 -exec_type
214}:dir_file_class_set relabelto;
215
216allow init { sysfs debugfs_tracing debugfs_tracing_debug }:{ dir file lnk_file } { getattr relabelfrom };
217allow init { sysfs_type tracefs_type }:{ dir file lnk_file } { relabelto getattr };
218allow init dev_type:dir create_dir_perms;
219allow init dev_type:lnk_file create;
220
221# chown/chmod on pseudo files.
222allow init {
223 fs_type
224 -contextmount_type
225 -proc_type
226 -fusefs_type
227 -sysfs_type
228 -rootfs
229}:file { open read setattr };
230allow init { fs_type -contextmount_type -fusefs_type -rootfs }:dir { open read setattr search };
231
232allow init {
233 binder_device
234 console_device
235 devpts
236 dm_device
237 hwbinder_device
238 kmsg_device
239 null_device
240 owntty_device
241 ptmx_device
242 random_device
243 tty_device
244 zero_device
245}:chr_file { read open };
246
247# Any operation that can modify the kernel ring buffer, e.g. clear
248# or a read that consumes the messages that were read.
249allow init kernel:system syslog_mod;
250allow init self:global_capability2_class_set syslog;
251
252# init access to /proc.
253r_dir_file(init, proc_net_type)
254allow init proc_filesystems:file r_file_perms;
255
256allow init {
257 proc # b/67049235 processes /proc/<pid>/* files are mislabeled.
258 proc_bootconfig
259 proc_cmdline
260 proc_diskstats
261 proc_kmsg # Open /proc/kmsg for logd service.
262 proc_meminfo
263 proc_stat # Read /proc/stat for bootchart.
264 proc_uptime
265 proc_version
266}:file r_file_perms;
267
268allow init {
269 proc_abi
270 proc_dirty
271 proc_hostname
272 proc_hung_task
273 proc_extra_free_kbytes
274 proc_net_type
275 proc_max_map_count
276 proc_min_free_order_shift
277 proc_overcommit_memory # /proc/sys/vm/overcommit_memory
278 proc_panic
279 proc_page_cluster
280 proc_perf
281 proc_sched
282 proc_sysrq
283}:file w_file_perms;
284
285allow init {
286 proc_security
287}:file rw_file_perms;
288
289# init chmod/chown access to /proc files.
290allow init {
291 proc_cmdline
292 proc_bootconfig
293 proc_kmsg
294 proc_net
295 proc_pagetypeinfo
296 proc_qtaguid_stat
297 proc_slabinfo
298 proc_sysrq
299 proc_qtaguid_ctrl
300 proc_vmallocinfo
301}:file setattr;
302
303# init access to /sys files.
304allow init {
305 sysfs_android_usb
306 sysfs_dm_verity
307 sysfs_leds
308 sysfs_power
309 sysfs_fs_f2fs
310 sysfs_dm
311}:file w_file_perms;
312
313allow init {
314 sysfs_dt_firmware_android
315 sysfs_fs_ext4_features
316}:file r_file_perms;
317
318allow init {
319 sysfs_zram
320}:file rw_file_perms;
321
322# allow init to create loop devices with /dev/loop-control
323allow init loop_control_device:chr_file rw_file_perms;
324allow init loop_device:blk_file rw_file_perms;
325allowxperm init loop_device:blk_file ioctl {
326 LOOP_SET_FD
327 LOOP_CLR_FD
328 LOOP_CTL_GET_FREE
329 LOOP_SET_BLOCK_SIZE
330 LOOP_SET_DIRECT_IO
331 LOOP_GET_STATUS
332};
333
334# init chmod/chown access to /sys files.
335allow init {
336 sysfs_android_usb
337 sysfs_devices_system_cpu
338 sysfs_ipv4
339 sysfs_leds
340 sysfs_lowmemorykiller
341 sysfs_power
342 sysfs_vibrator
343 sysfs_wake_lock
344 sysfs_zram
345}:file setattr;
346
347allow init self:global_capability_class_set net_admin;
348
349# Reboot.
350allow init self:global_capability_class_set sys_boot;
351
352# Support "adb shell stop"
353allow init self:global_capability_class_set kill;
354allow init domain:process { getpgid sigkill signal };
355
Inseob Kime1389972021-07-19 07:48:34 +0000356# Init creates /data/local/tmp at boot
357allow init shell_data_file:dir { open create read getattr setattr search };
358allow init shell_data_file:file { getattr };
359
360# Set UID, GID, and adjust capability bounding set for services.
361allow init self:global_capability_class_set { setuid setgid setpcap };
362
363# For bootchart to read the /proc/$pid/cmdline file of each process,
364# we need to have following line to allow init to have access
365# to different domains.
366r_dir_file(init, domain)
367
368# Use setexeccon(), setfscreatecon(), and setsockcreatecon().
369# setexec is for services with seclabel options.
370# setfscreate is for labeling directories and socket files.
371# setsockcreate is for labeling local/unix domain sockets.
372allow init self:process { setexec setfscreate setsockcreate };
373
374# Get file context
375allow init file_contexts_file:file r_file_perms;
376
377# sepolicy access
378allow init sepolicy_file:file r_file_perms;
379
380# Perform SELinux access checks on setting properties.
381selinux_check_access(init)
382
383# Ask the kernel for the new context on services to label their sockets.
384allow init kernel:security compute_create;
385
386# Create sockets for the services.
387allow init domain:unix_stream_socket { create bind setopt };
388allow init domain:unix_dgram_socket { create bind setopt };
389
390# Set any property.
391allow init property_type:property_service set;
392
393# Send an SELinux userspace denial to the kernel audit subsystem,
394# so it can be picked up and processed by logd. These denials are
395# generated when an attempt to set a property is denied by policy.
396allow init self:netlink_audit_socket { create_socket_perms_no_ioctl nlmsg_relay };
397allow init self:global_capability_class_set audit_write;
398
399# Run "ifup lo" to bring up the localhost interface
400allow init self:udp_socket { create ioctl };
401# in addition to unpriv ioctls granted to all domains, init also needs:
402allowxperm init self:udp_socket ioctl SIOCSIFFLAGS;
403allow init self:global_capability_class_set net_raw;
404
405# Set scheduling info for psi monitor thread.
406# TODO: delete or revise this line b/131761776
407allow init kernel:process { getsched setsched };
408
409# Create and access /dev files without a specific type,
410# e.g. /dev/.coldboot_done, /dev/.booting
411# TODO: Move these files into their own type unless they are
412# only ever accessed by init.
413allow init device:file create_file_perms;
414
415# Access device mapper for setting up dm-verity
416allow init dm_device:chr_file rw_file_perms;
417allow init dm_device:blk_file rw_file_perms;
418
419# linux keyring configuration
420allow init init:key { write search setattr };
421
422r_dir_file(init, system_file)
423r_dir_file(init, vendor_file_type)
424
425allow init system_data_file:file { getattr read };
426allow init system_data_file:lnk_file r_file_perms;
427
428# Allow init to touch PSI monitors
429allow init proc_pressure_mem:file { rw_file_perms setattr };
430
431# init is using bootstrap bionic
Jiyong Park16c1ae32022-01-23 23:55:41 +0900432use_bootstrap_libs(init)
Inseob Kime1389972021-07-19 07:48:34 +0000433
434# stat the root dir of fuse filesystems (for the mount handler)
435allow init fuse:dir { search getattr };
436
437set_prop(init, property_type)