blob: 11e398e3b703bfb6aad20e7fc2423364780c8aeb [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
Ryan Savitski4cd09942024-12-13 20:36:44 +000022# Allow opening /proc/kallsyms so that on boot, init can create and retain an
23# fd with the full address visibility (which is evaluated on open and persists
24# for the lifetime of the open file description). This fd can then be shared
25# with other privileged processes.
26allow init proc_kallsyms:file r_file_perms;
27
Inseob Kime1389972021-07-19 07:48:34 +000028# Allow init to restore contexts of vd_device(/dev/block/vd[..]) when labeling
29# /dev/block.
30allow init vd_device:blk_file relabelto;
31
32# chown/chmod on devices.
33allow init {
34 dev_type
35 -hw_random_device
Inseob Kime1389972021-07-19 07:48:34 +000036}:chr_file setattr;
37
38# /dev/__null__ node created by init.
39allow init tmpfs:chr_file { create setattr unlink rw_file_perms };
40
Nate Myren0e15f2d2023-08-15 16:41:17 -070041# /dev/__properties__ and /dev/__properties__/appcompat_override
Inseob Kime1389972021-07-19 07:48:34 +000042allow init properties_device:dir relabelto;
43allow init properties_serial:file { write relabelto };
44allow init property_type:file { append create getattr map open read relabelto rename setattr unlink write };
Nate Myren0e15f2d2023-08-15 16:41:17 -070045# /dev/__properties__/property_info and /dev/__properties__/appcompat_override/property_info
Inseob Kime1389972021-07-19 07:48:34 +000046allow init properties_device:file create_file_perms;
47allow init property_info:file relabelto;
Inseob Kime1389972021-07-19 07:48:34 +000048# /dev/socket
49allow init { device socket_device dm_user_device }:dir relabelto;
Inseob Kim85091cd2022-03-22 21:50:09 +090050# Relabel /dev nodes created in first stage init: /dev/console, /dev/null, /dev/ptmx, /dev/random
51# and /dev/urandom
52allow init { console_device null_device ptmx_device random_device } : chr_file relabelto;
Inseob Kime1389972021-07-19 07:48:34 +000053# /dev/device-mapper, /dev/block(/.*)?
54allow init tmpfs:{ chr_file blk_file } relabelfrom;
55allow init tmpfs:blk_file getattr;
56allow init block_device:{ dir blk_file lnk_file } relabelto;
57allow init dm_device:{ chr_file blk_file } relabelto;
58allow init dm_user_device:chr_file relabelto;
59allow init kernel:fd use;
60# restorecon for early mount device symlinks
61allow init tmpfs:lnk_file { getattr read relabelfrom };
62
63# setrlimit
64allow init self:global_capability_class_set sys_resource;
65
Alan Stokes3105e3e2023-08-23 16:25:50 +010066# Set usermodehelpers.
67allow init { usermodehelper sysfs_usermodehelper }:file rw_file_perms;
68
Inseob Kime1389972021-07-19 07:48:34 +000069# Remove /dev/.booting and load /debug_ramdisk/* files
70allow init tmpfs:file { getattr unlink };
71
72# Access pty created for fsck.
73allow init devpts:chr_file { read write open };
74
75# Access /dev/__null__ node created prior to initial policy load.
76allow init tmpfs:chr_file write;
77
78# Access /dev/console.
79allow init console_device:chr_file rw_file_perms;
80
81# Access /dev/tty0.
82allow init tty_device:chr_file rw_file_perms;
83
84# Call mount(2).
85allow init self:global_capability_class_set sys_admin;
86
87# Call setns(2).
88allow init self:global_capability_class_set sys_chroot;
89
90# Create and mount on directories in /.
91allow init rootfs:dir create_dir_perms;
92allow init {
93 rootfs
94 cgroup
95 linkerconfig_file
96 system_data_file
97 system_data_root_file
98 system_file
99 vendor_file
100}:dir mounton;
101
102# Mount bpf fs on sys/fs/bpf
103allow init fs_bpf:dir mounton;
104
105# Mount on /dev/usb-ffs/adb.
106allow init device:dir mounton;
107
108# Mount tmpfs on /apex
109allow init apex_mnt_dir:dir mounton;
110
111# Create and remove symlinks in /.
112allow init rootfs:lnk_file { create unlink };
113
114# Mount debugfs on /sys/kernel/debug.
115allow init sysfs:dir mounton;
116
117# Create cgroups mount points in tmpfs and mount cgroups on them.
118allow init tmpfs:dir create_dir_perms;
119allow init tmpfs:dir mounton;
120allow init cgroup:dir create_dir_perms;
121allow init cgroup:file rw_file_perms;
Inseob Kime1389972021-07-19 07:48:34 +0000122allow init cgroup_desc_file:file r_file_perms;
Inseob Kime1389972021-07-19 07:48:34 +0000123allow init cgroup_v2:dir { mounton create_dir_perms};
124allow init cgroup_v2:file rw_file_perms;
125
126# Use tmpfs as /data, used for booting when /data is encrypted
127allow init tmpfs:dir relabelfrom;
128
129# Create directories under /dev/cpuctl after chowning it to system.
130allow init self:global_capability_class_set { dac_override dac_read_search };
131
132allow init self:global_capability_class_set { sys_rawio mknod };
133
134# Mounting filesystems from block devices.
135allow init dev_type:blk_file r_file_perms;
136allowxperm init dev_type:blk_file ioctl BLKROSET;
137
138# Mounting filesystems.
139# Only allow relabelto for types used in context= mount options,
140# which should all be assigned the contextmount_type attribute.
141# This can be done in device-specific policy via type or typeattribute
142# declarations.
143allow init {
144 fs_type
145}:filesystem ~relabelto;
146
147# Allow init to mount tracefs in /sys/kernel/tracing
148allow init debugfs_tracing_debug:filesystem mount;
149
150allow init unlabeled:filesystem ~relabelto;
151allow init contextmount_type:filesystem relabelto;
152
153# Allow read-only access to context= mounted filesystems.
154allow init contextmount_type:dir r_dir_perms;
155allow init contextmount_type:notdevfile_class_set r_file_perms;
156
157# restorecon /adb_keys or any other rootfs files and directories to a more
158# specific type.
159allow init rootfs:{ dir file } relabelfrom;
160
161# mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files.
162# chown/chmod require open+read+setattr required for open()+fchown/fchmod().
163# system/core/init.rc requires at least cache_file and data_file_type.
164# init.<board>.rc files often include device-specific types, so
165# we just allow all file types except /system files here.
166allow init self:global_capability_class_set { chown fowner fsetid };
167
168allow init {
169 file_type
170 -exec_type
171 -system_file_type
172 -vendor_file_type
173}:dir { create search getattr open read setattr ioctl };
174
175allow init {
176 file_type
177 -exec_type
Inseob Kime1389972021-07-19 07:48:34 +0000178 -shell_data_file
179 -system_file_type
180 -vendor_file_type
181}:dir { write add_name remove_name rmdir relabelfrom };
182
183allow init {
184 file_type
185 -apex_info_file
186 -exec_type
Inseob Kime1389972021-07-19 07:48:34 +0000187 -shell_data_file
188 -system_file_type
189 -vendor_file_type
190}:file { create getattr open read write setattr relabelfrom unlink map };
191
192allow init tracefs_type:file { create_file_perms relabelfrom };
193
194allow init {
195 file_type
196 -exec_type
Inseob Kime1389972021-07-19 07:48:34 +0000197 -shell_data_file
198 -system_file_type
199 -vendor_file_type
200}:{ sock_file fifo_file } { create getattr open read setattr relabelfrom unlink };
201
202allow init {
203 file_type
204 -apex_mnt_dir
205 -exec_type
Inseob Kime1389972021-07-19 07:48:34 +0000206 -shell_data_file
207 -system_file_type
208 -vendor_file_type
209}:lnk_file { create getattr setattr relabelfrom unlink };
210
211allow init {
212 file_type
213 -system_file_type
214 -vendor_file_type
215 -exec_type
216}:dir_file_class_set relabelto;
217
218allow init { sysfs debugfs_tracing debugfs_tracing_debug }:{ dir file lnk_file } { getattr relabelfrom };
219allow init { sysfs_type tracefs_type }:{ dir file lnk_file } { relabelto getattr };
220allow init dev_type:dir create_dir_perms;
221allow init dev_type:lnk_file create;
222
223# chown/chmod on pseudo files.
224allow init {
225 fs_type
226 -contextmount_type
227 -proc_type
228 -fusefs_type
229 -sysfs_type
230 -rootfs
231}:file { open read setattr };
232allow init { fs_type -contextmount_type -fusefs_type -rootfs }:dir { open read setattr search };
233
234allow init {
Inseob Kime1389972021-07-19 07:48:34 +0000235 console_device
236 devpts
237 dm_device
Inseob Kime1389972021-07-19 07:48:34 +0000238 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
Bart Searsdbca6252024-08-04 23:06:24 +0000296 proc_qtaguid_stat
Inseob Kime1389972021-07-19 07:48:34 +0000297 proc_slabinfo
298 proc_sysrq
Bart Searsdbca6252024-08-04 23:06:24 +0000299 proc_qtaguid_ctrl
Inseob Kime1389972021-07-19 07:48:34 +0000300 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
Kalesh Singhd60a38b2024-05-24 11:37:23 -0700311 sysfs_pgsize_migration
Inseob Kime1389972021-07-19 07:48:34 +0000312}:file w_file_perms;
313
314allow init {
315 sysfs_dt_firmware_android
316 sysfs_fs_ext4_features
317}:file r_file_perms;
318
319allow init {
320 sysfs_zram
321}:file rw_file_perms;
322
323# allow init to create loop devices with /dev/loop-control
324allow init loop_control_device:chr_file rw_file_perms;
325allow init loop_device:blk_file rw_file_perms;
326allowxperm init loop_device:blk_file ioctl {
327 LOOP_SET_FD
328 LOOP_CLR_FD
329 LOOP_CTL_GET_FREE
330 LOOP_SET_BLOCK_SIZE
331 LOOP_SET_DIRECT_IO
332 LOOP_GET_STATUS
333};
334
335# init chmod/chown access to /sys files.
336allow init {
337 sysfs_android_usb
338 sysfs_devices_system_cpu
339 sysfs_ipv4
340 sysfs_leds
341 sysfs_lowmemorykiller
342 sysfs_power
343 sysfs_vibrator
344 sysfs_wake_lock
345 sysfs_zram
346}:file setattr;
347
348allow init self:global_capability_class_set net_admin;
349
350# Reboot.
351allow init self:global_capability_class_set sys_boot;
352
353# Support "adb shell stop"
354allow init self:global_capability_class_set kill;
355allow init domain:process { getpgid sigkill signal };
356
Inseob Kime1389972021-07-19 07:48:34 +0000357# Init creates /data/local/tmp at boot
358allow init shell_data_file:dir { open create read getattr setattr search };
359allow init shell_data_file:file { getattr };
360
361# Set UID, GID, and adjust capability bounding set for services.
362allow init self:global_capability_class_set { setuid setgid setpcap };
363
364# For bootchart to read the /proc/$pid/cmdline file of each process,
365# we need to have following line to allow init to have access
366# to different domains.
367r_dir_file(init, domain)
368
369# Use setexeccon(), setfscreatecon(), and setsockcreatecon().
370# setexec is for services with seclabel options.
371# setfscreate is for labeling directories and socket files.
372# setsockcreate is for labeling local/unix domain sockets.
373allow init self:process { setexec setfscreate setsockcreate };
374
375# Get file context
376allow init file_contexts_file:file r_file_perms;
377
378# sepolicy access
379allow init sepolicy_file:file r_file_perms;
380
381# Perform SELinux access checks on setting properties.
382selinux_check_access(init)
383
384# Ask the kernel for the new context on services to label their sockets.
385allow init kernel:security compute_create;
386
387# Create sockets for the services.
388allow init domain:unix_stream_socket { create bind setopt };
389allow init domain:unix_dgram_socket { create bind setopt };
390
391# Set any property.
392allow init property_type:property_service set;
393
394# Send an SELinux userspace denial to the kernel audit subsystem,
395# so it can be picked up and processed by logd. These denials are
396# generated when an attempt to set a property is denied by policy.
397allow init self:netlink_audit_socket { create_socket_perms_no_ioctl nlmsg_relay };
398allow init self:global_capability_class_set audit_write;
399
400# Run "ifup lo" to bring up the localhost interface
401allow init self:udp_socket { create ioctl };
402# in addition to unpriv ioctls granted to all domains, init also needs:
403allowxperm init self:udp_socket ioctl SIOCSIFFLAGS;
404allow init self:global_capability_class_set net_raw;
405
406# Set scheduling info for psi monitor thread.
407# TODO: delete or revise this line b/131761776
408allow init kernel:process { getsched setsched };
409
410# Create and access /dev files without a specific type,
411# e.g. /dev/.coldboot_done, /dev/.booting
412# TODO: Move these files into their own type unless they are
413# only ever accessed by init.
414allow init device:file create_file_perms;
415
416# Access device mapper for setting up dm-verity
417allow init dm_device:chr_file rw_file_perms;
418allow init dm_device:blk_file rw_file_perms;
419
420# linux keyring configuration
421allow init init:key { write search setattr };
422
423r_dir_file(init, system_file)
424r_dir_file(init, vendor_file_type)
425
426allow init system_data_file:file { getattr read };
427allow init system_data_file:lnk_file r_file_perms;
428
429# Allow init to touch PSI monitors
430allow init proc_pressure_mem:file { rw_file_perms setattr };
431
432# init is using bootstrap bionic
Jiyong Park16c1ae32022-01-23 23:55:41 +0900433use_bootstrap_libs(init)
Inseob Kime1389972021-07-19 07:48:34 +0000434
435# stat the root dir of fuse filesystems (for the mount handler)
436allow init fuse:dir { search getattr };
437
438set_prop(init, property_type)
Inseob Kim4e141f62022-10-12 16:38:20 +0900439
440allow init self:netlink_audit_socket { create_socket_perms_no_ioctl nlmsg_relay };
Jiyong Park02df74a2022-12-20 19:27:49 +0900441
442# PRNG seeder daemon socket is created and listened on by init before forking.
443allow init prng_seeder:unix_stream_socket { create bind listen };
Inseob Kim7bb2d4a2024-01-03 09:33:37 +0900444
445# Allow init to load vendor modules
446r_dir_file(init, vendor_kernel_modules)
447allow init self:capability sys_module;
448allow init vendor_kernel_modules:system module_load;
Inseob Kim9bad60c2024-03-28 15:23:18 +0900449
450allow init tmpfs:chr_file relabelfrom;
451allow init kmsg_device:chr_file { getattr write relabelto };
452allow init kmsg_debug_device:chr_file { open write relabelto };