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