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