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