blob: da811ed72e01effc844c262790d63f5d9c66ec15 [file] [log] [blame]
Inseob Kim4eb56602021-07-09 15:51:12 +09001# Rules for all domains.
Inseob Kimff43be22021-06-07 16:56:56 +09002
Inseob Kim4eb56602021-07-09 15:51:12 +09003# Allow reaping by init.
4allow domain init:process sigchld;
Inseob Kimff43be22021-06-07 16:56:56 +09005
Inseob Kim4eb56602021-07-09 15:51:12 +09006# Intra-domain accesses.
7allow domain self:process {
8 fork
9 sigchld
10 sigkill
11 sigstop
12 signull
13 signal
14 getsched
15 setsched
16 getsession
17 getpgid
18 setpgid
19 getcap
20 setcap
21 getattr
22 setrlimit
23};
24allow domain self:fd use;
25allow domain proc:dir r_dir_perms;
26allow domain proc_net_type:dir search;
27r_dir_file(domain, self)
28allow domain self:{ fifo_file file } rw_file_perms;
29allow domain self:unix_dgram_socket { create_socket_perms sendto };
30allow domain self:unix_stream_socket { create_stream_socket_perms connectto };
Inseob Kimff43be22021-06-07 16:56:56 +090031
Inseob Kim4eb56602021-07-09 15:51:12 +090032# Inherit or receive open files from others.
33allow domain init:fd use;
Inseob Kimff43be22021-06-07 16:56:56 +090034
Inseob Kim4eb56602021-07-09 15:51:12 +090035# Root fs.
36allow domain tmpfs:dir { getattr search };
37allow domain rootfs:dir search;
38allow domain rootfs:lnk_file { read getattr };
39
40# Device accesses.
41allow domain device:dir search;
42allow domain dev_type:lnk_file r_file_perms;
43allow domain devpts:dir search;
44allow domain socket_device:dir r_dir_perms;
45allow domain owntty_device:chr_file rw_file_perms;
46allow domain null_device:chr_file rw_file_perms;
47allow domain zero_device:chr_file rw_file_perms;
48
49# /dev/binder can be accessed by ... everyone! :)
50allow { domain -hwservicemanager } binder_device:chr_file rw_file_perms;
51
52# Restrict binder ioctls to an allowlist. Additional ioctl commands may be
53# added to individual domains, but this sets safe defaults for all processes.
54allowxperm domain binder_device:chr_file ioctl { unpriv_binder_ioctls };
55
56# /dev/binderfs needs to be accessed by everyone too!
57allow domain binderfs:dir { getattr search };
58allow domain binderfs_logs_proc:dir search;
59
60allow { domain -servicemanager } hwbinder_device:chr_file rw_file_perms;
61allow domain ptmx_device:chr_file rw_file_perms;
62allow domain random_device:chr_file rw_file_perms;
63allow domain proc_random:dir r_dir_perms;
64allow domain proc_random:file r_file_perms;
65allow domain properties_device:dir { search getattr };
66allow domain properties_serial:file r_file_perms;
67allow domain property_info:file r_file_perms;
68
69allow domain property_contexts_file:file r_file_perms;
70
71allow domain init:key search;
72
73# logd access
74unix_socket_send(domain, logdw, logd)
75
76# Directory/link file access for path resolution.
77allow domain {
78 system_file
79 system_lib_file
80 system_seccomp_policy_file
81 system_security_cacerts_file
82}:dir r_dir_perms;
83allow domain system_file:lnk_file { getattr read };
84
85# Global access to /system/etc/security/cacerts/*, /system/etc/seccomp_policy/*, /system/lib[64]/*,
86# /(system|product|system_ext)/etc/(group|passwd), linker and its config.
87allow domain system_seccomp_policy_file:file r_file_perms;
88# cacerts are accessible from public Java API.
89allow domain system_security_cacerts_file:file r_file_perms;
90allow domain system_group_file:file r_file_perms;
91allow domain system_passwd_file:file r_file_perms;
92allow domain system_linker_exec:file { execute read open getattr map };
93allow domain system_linker_config_file:file r_file_perms;
94allow domain system_lib_file:file { execute read open getattr map };
95# To allow following symlinks at /system/bin/linker, /system/lib/libc.so, etc.
96allow domain system_linker_exec:lnk_file { read open getattr };
97allow domain system_lib_file:lnk_file { read open getattr };
98
99allow domain system_event_log_tags_file:file r_file_perms;
100
101allow coredomain system_file:file { execute read open getattr map };
102
103# All domains get access to /vendor/etc
104allow domain vendor_configs_file:dir r_dir_perms;
105allow domain vendor_configs_file:file { read open getattr map };
106
107# Allow all domains to be able to follow /system/vendor and/or
108# /vendor/odm symlinks.
109allow domain vendor_file_type:lnk_file { getattr open read };
110
111# This is required to be able to search & read /vendor/lib64
112# in order to lookup vendor libraries. The execute permission
113# for coredomains is granted *only* for same process HALs
114allow domain vendor_file:dir { getattr search };
115
116# Allow reading and executing out of /vendor to all vendor domains
117allow { domain -coredomain } vendor_file_type:dir r_dir_perms;
118allow { domain -coredomain } vendor_file_type:file { read open getattr execute map };
119allow { domain -coredomain } vendor_file_type:lnk_file { getattr read };
120
121# read and stat any sysfs symlinks
122allow domain sysfs:lnk_file { getattr read };
123
124# Lots of processes access current CPU information
125r_dir_file(domain, sysfs_devices_system_cpu)
126
127# If kernel CONFIG_TRANSPARENT_HUGEPAGE is enabled, libjemalloc5 (statically
128# included by libc) reads /sys/kernel/mm/transparent_hugepage/enabled.
129allow domain sysfs_transparent_hugepage:dir search;
130allow domain sysfs_transparent_hugepage:file r_file_perms;
131
132allow coredomain system_data_file:dir getattr;
133# /data has the label system_data_root_file. Vendor components need the search
134# permission on system_data_root_file for path traversal to /data/vendor.
135allow domain system_data_root_file:dir { search getattr } ;
136allow domain system_data_file:dir search;
137# TODO restrict this to non-coredomain
138allow domain vendor_data_file:dir { getattr search };
139
140# required by the dynamic linker
141allow domain proc:lnk_file { getattr read };
142
143# /proc/cpuinfo
144allow domain proc_cpuinfo:file r_file_perms;
145
146# profiling needs to read /proc/sys/kernel/perf_event_max_sample_rate
147allow domain proc_perf:file r_file_perms;
148
149# toybox loads libselinux which stats /sys/fs/selinux/
150allow domain selinuxfs:dir search;
151allow domain selinuxfs:file getattr;
152allow domain sysfs:dir search;
153allow domain selinuxfs:filesystem getattr;
154
155# Almost all processes log tracing information to
156# /sys/kernel/debug/tracing/trace_marker
157# The reason behind this is documented in b/6513400
158allow domain debugfs:dir search;
159allow domain debugfs_tracing:dir search;
160allow domain debugfs_tracing_debug:dir search;
161allow domain debugfs_trace_marker:file w_file_perms;
162
163# Linux lockdown mode offers coarse-grained definitions for access controls.
164# The "confidentiality" level detects access to tracefs or the perf subsystem.
165# This overlaps with more precise declarations in Android's policy. The
166# debugfs_trace_marker above is an example in which all processes should have
167# some access to tracefs. Therefore, allow all domains to access this level.
168# The "integrity" level is however enforced.
169allow domain self:lockdown confidentiality;
170
171# Filesystem access.
172allow domain fs_type:filesystem getattr;
173allow domain fs_type:dir getattr;
174
175# Restrict all domains to an allowlist for common socket types. Additional
176# ioctl commands may be added to individual domains, but this sets safe
177# defaults for all processes. Note that granting this allowlist to domain does
178# not grant the ioctl permission on these socket types. That must be granted
179# separately.
180allowxperm domain domain:{ icmp_socket rawip_socket tcp_socket udp_socket }
181 ioctl { unpriv_sock_ioctls unpriv_tty_ioctls };
182# default allowlist for unix sockets.
183allowxperm domain { domain pdx_channel_socket_type }:{ unix_dgram_socket unix_stream_socket }
184 ioctl unpriv_unix_sock_ioctls;
185
186# Restrict PTYs to only allowed ioctls.
187# Note that granting this allowlist to domain does
188# not grant the wider ioctl permission. That must be granted
189# separately.
190allowxperm domain devpts:chr_file ioctl unpriv_tty_ioctls;
191
192# All domains must clearly enumerate what ioctls they use
193# on filesystem objects (plain files, directories, symbolic links,
194# named pipes, and named sockets). We start off with a safe set.
195allowxperm domain { file_type fs_type domain dev_type }:{ dir notdevfile_class_set blk_file } ioctl { FIOCLEX FIONCLEX };
196
197# If a domain has ioctl access to tun_device, it must clearly enumerate the
198# ioctls used. Safe defaults are listed below.
199allowxperm domain tun_device:chr_file ioctl { FIOCLEX FIONCLEX };
200
201# Allow a process to make a determination whether a file descriptor
202# for a plain file or pipe (fifo_file) is a tty. Note that granting
203# this allowlist to domain does not grant the ioctl permission to
204# these files. That must be granted separately.
205allowxperm domain { file_type fs_type }:file ioctl { TCGETS };
206allowxperm domain domain:fifo_file ioctl { TCGETS };
207
208# If a domain has access to perform an ioctl on a block device, allow these
209# very common, benign ioctls
210allowxperm domain dev_type:blk_file ioctl { BLKGETSIZE64 BLKSSZGET };
211
212# read APEX dir and stat any symlink pointing to APEXs.
213allow domain apex_mnt_dir:dir { getattr search };
214allow domain apex_mnt_dir:lnk_file r_file_perms;
215
216allow domain self:global_capability_class_set audit_control;
217allow domain self:netlink_audit_socket { create_socket_perms_no_ioctl nlmsg_write };
218
219# workaround for supressing property accesses.
220# TODO: remove these
Andrew Scull6f3e5fe2021-07-02 12:38:21 +0000221set_prop(domain, property_type -vmsecret_keymint_prop)
Inseob Kim4eb56602021-07-09 15:51:12 +0900222# auditallow { domain -init } property_type:property_service set;
223# auditallow { domain -init } property_type:file rw_file_perms;
224
225allow domain linkerconfig_file:dir search;
226allow domain linkerconfig_file:file r_file_perms;
227
228#-----------------------------------------
Inseob Kimff43be22021-06-07 16:56:56 +0900229# Path resolution access in cgroups.
230allow domain cgroup:dir search;
Inseob Kim4eb56602021-07-09 15:51:12 +0900231allow { domain } cgroup:dir w_dir_perms;
232allow { domain } cgroup:file w_file_perms;
Inseob Kimff43be22021-06-07 16:56:56 +0900233
234allow domain cgroup_v2:dir search;
Inseob Kim4eb56602021-07-09 15:51:12 +0900235allow { domain } cgroup_v2:dir w_dir_perms;
236allow { domain } cgroup_v2:file w_file_perms;
Inseob Kimff43be22021-06-07 16:56:56 +0900237
238allow domain cgroup_rc_file:dir search;
239allow domain cgroup_rc_file:file r_file_perms;
240allow domain task_profiles_file:file r_file_perms;
241allow domain task_profiles_api_file:file r_file_perms;
Inseob Kimff43be22021-06-07 16:56:56 +0900242
Inseob Kim4eb56602021-07-09 15:51:12 +0900243#-----------------------------------------
Inseob Kimff43be22021-06-07 16:56:56 +0900244# Allow access to fsverity keyring.
245allow domain kernel:key search;
Inseob Kimff43be22021-06-07 16:56:56 +0900246
Inseob Kim4eb56602021-07-09 15:51:12 +0900247# Transition to crash_dump when /system/bin/crash_dump* is executed.
248# This occurs when the process crashes.
249# We do not apply this to the su domain to avoid interfering with
250# tests (b/114136122)
251domain_auto_trans(domain, crash_dump_exec, crash_dump);
252allow domain crash_dump:process sigchld;