blob: 5ad30e5b71544c513b0f3f31d79d65b25708ac59 [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 {
Inseob Kime1389972021-07-19 07:48:34 +0000233 console_device
234 devpts
235 dm_device
Inseob Kime1389972021-07-19 07:48:34 +0000236 kmsg_device
237 null_device
238 owntty_device
239 ptmx_device
240 random_device
241 tty_device
242 zero_device
243}:chr_file { read open };
244
245# Any operation that can modify the kernel ring buffer, e.g. clear
246# or a read that consumes the messages that were read.
247allow init kernel:system syslog_mod;
248allow init self:global_capability2_class_set syslog;
249
250# init access to /proc.
251r_dir_file(init, proc_net_type)
252allow init proc_filesystems:file r_file_perms;
253
254allow init {
255 proc # b/67049235 processes /proc/<pid>/* files are mislabeled.
256 proc_bootconfig
257 proc_cmdline
258 proc_diskstats
259 proc_kmsg # Open /proc/kmsg for logd service.
260 proc_meminfo
261 proc_stat # Read /proc/stat for bootchart.
262 proc_uptime
263 proc_version
264}:file r_file_perms;
265
266allow init {
267 proc_abi
268 proc_dirty
269 proc_hostname
270 proc_hung_task
271 proc_extra_free_kbytes
272 proc_net_type
273 proc_max_map_count
274 proc_min_free_order_shift
275 proc_overcommit_memory # /proc/sys/vm/overcommit_memory
276 proc_panic
277 proc_page_cluster
278 proc_perf
279 proc_sched
280 proc_sysrq
281}:file w_file_perms;
282
283allow init {
284 proc_security
285}:file rw_file_perms;
286
287# init chmod/chown access to /proc files.
288allow init {
289 proc_cmdline
290 proc_bootconfig
291 proc_kmsg
292 proc_net
293 proc_pagetypeinfo
294 proc_qtaguid_stat
295 proc_slabinfo
296 proc_sysrq
297 proc_qtaguid_ctrl
298 proc_vmallocinfo
299}:file setattr;
300
301# init access to /sys files.
302allow init {
303 sysfs_android_usb
304 sysfs_dm_verity
305 sysfs_leds
306 sysfs_power
307 sysfs_fs_f2fs
308 sysfs_dm
309}:file w_file_perms;
310
311allow init {
312 sysfs_dt_firmware_android
313 sysfs_fs_ext4_features
314}:file r_file_perms;
315
316allow init {
317 sysfs_zram
318}:file rw_file_perms;
319
320# allow init to create loop devices with /dev/loop-control
321allow init loop_control_device:chr_file rw_file_perms;
322allow init loop_device:blk_file rw_file_perms;
323allowxperm init loop_device:blk_file ioctl {
324 LOOP_SET_FD
325 LOOP_CLR_FD
326 LOOP_CTL_GET_FREE
327 LOOP_SET_BLOCK_SIZE
328 LOOP_SET_DIRECT_IO
329 LOOP_GET_STATUS
330};
331
332# init chmod/chown access to /sys files.
333allow init {
334 sysfs_android_usb
335 sysfs_devices_system_cpu
336 sysfs_ipv4
337 sysfs_leds
338 sysfs_lowmemorykiller
339 sysfs_power
340 sysfs_vibrator
341 sysfs_wake_lock
342 sysfs_zram
343}:file setattr;
344
345allow init self:global_capability_class_set net_admin;
346
347# Reboot.
348allow init self:global_capability_class_set sys_boot;
349
350# Support "adb shell stop"
351allow init self:global_capability_class_set kill;
352allow init domain:process { getpgid sigkill signal };
353
Inseob Kime1389972021-07-19 07:48:34 +0000354# Init creates /data/local/tmp at boot
355allow init shell_data_file:dir { open create read getattr setattr search };
356allow init shell_data_file:file { getattr };
357
358# Set UID, GID, and adjust capability bounding set for services.
359allow init self:global_capability_class_set { setuid setgid setpcap };
360
361# For bootchart to read the /proc/$pid/cmdline file of each process,
362# we need to have following line to allow init to have access
363# to different domains.
364r_dir_file(init, domain)
365
366# Use setexeccon(), setfscreatecon(), and setsockcreatecon().
367# setexec is for services with seclabel options.
368# setfscreate is for labeling directories and socket files.
369# setsockcreate is for labeling local/unix domain sockets.
370allow init self:process { setexec setfscreate setsockcreate };
371
372# Get file context
373allow init file_contexts_file:file r_file_perms;
374
375# sepolicy access
376allow init sepolicy_file:file r_file_perms;
377
378# Perform SELinux access checks on setting properties.
379selinux_check_access(init)
380
381# Ask the kernel for the new context on services to label their sockets.
382allow init kernel:security compute_create;
383
384# Create sockets for the services.
385allow init domain:unix_stream_socket { create bind setopt };
386allow init domain:unix_dgram_socket { create bind setopt };
387
388# Set any property.
389allow init property_type:property_service set;
390
391# Send an SELinux userspace denial to the kernel audit subsystem,
392# so it can be picked up and processed by logd. These denials are
393# generated when an attempt to set a property is denied by policy.
394allow init self:netlink_audit_socket { create_socket_perms_no_ioctl nlmsg_relay };
395allow init self:global_capability_class_set audit_write;
396
397# Run "ifup lo" to bring up the localhost interface
398allow init self:udp_socket { create ioctl };
399# in addition to unpriv ioctls granted to all domains, init also needs:
400allowxperm init self:udp_socket ioctl SIOCSIFFLAGS;
401allow init self:global_capability_class_set net_raw;
402
403# Set scheduling info for psi monitor thread.
404# TODO: delete or revise this line b/131761776
405allow init kernel:process { getsched setsched };
406
407# Create and access /dev files without a specific type,
408# e.g. /dev/.coldboot_done, /dev/.booting
409# TODO: Move these files into their own type unless they are
410# only ever accessed by init.
411allow init device:file create_file_perms;
412
413# Access device mapper for setting up dm-verity
414allow init dm_device:chr_file rw_file_perms;
415allow init dm_device:blk_file rw_file_perms;
416
417# linux keyring configuration
418allow init init:key { write search setattr };
419
420r_dir_file(init, system_file)
421r_dir_file(init, vendor_file_type)
422
423allow init system_data_file:file { getattr read };
424allow init system_data_file:lnk_file r_file_perms;
425
426# Allow init to touch PSI monitors
427allow init proc_pressure_mem:file { rw_file_perms setattr };
428
429# init is using bootstrap bionic
Jiyong Park16c1ae32022-01-23 23:55:41 +0900430use_bootstrap_libs(init)
Inseob Kime1389972021-07-19 07:48:34 +0000431
432# stat the root dir of fuse filesystems (for the mount handler)
433allow init fuse:dir { search getattr };
434
435set_prop(init, property_type)
Inseob Kim4e141f62022-10-12 16:38:20 +0900436
437allow init self:netlink_audit_socket { create_socket_perms_no_ioctl nlmsg_relay };
Jiyong Park02df74a2022-12-20 19:27:49 +0900438
439# PRNG seeder daemon socket is created and listened on by init before forking.
440allow init prng_seeder:unix_stream_socket { create bind listen };