xref: /aosp_15_r20/system/sepolicy/prebuilts/api/34.0/public/domain.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# Rules for all domains.
2*e4a36f41SAndroid Build Coastguard Worker
3*e4a36f41SAndroid Build Coastguard Worker# Allow reaping by init.
4*e4a36f41SAndroid Build Coastguard Workerallow domain init:process sigchld;
5*e4a36f41SAndroid Build Coastguard Worker
6*e4a36f41SAndroid Build Coastguard Worker# Intra-domain accesses.
7*e4a36f41SAndroid Build Coastguard Workerallow domain self:process {
8*e4a36f41SAndroid Build Coastguard Worker    fork
9*e4a36f41SAndroid Build Coastguard Worker    sigchld
10*e4a36f41SAndroid Build Coastguard Worker    sigkill
11*e4a36f41SAndroid Build Coastguard Worker    sigstop
12*e4a36f41SAndroid Build Coastguard Worker    signull
13*e4a36f41SAndroid Build Coastguard Worker    signal
14*e4a36f41SAndroid Build Coastguard Worker    getsched
15*e4a36f41SAndroid Build Coastguard Worker    setsched
16*e4a36f41SAndroid Build Coastguard Worker    getsession
17*e4a36f41SAndroid Build Coastguard Worker    getpgid
18*e4a36f41SAndroid Build Coastguard Worker    setpgid
19*e4a36f41SAndroid Build Coastguard Worker    getcap
20*e4a36f41SAndroid Build Coastguard Worker    setcap
21*e4a36f41SAndroid Build Coastguard Worker    getattr
22*e4a36f41SAndroid Build Coastguard Worker    setrlimit
23*e4a36f41SAndroid Build Coastguard Worker};
24*e4a36f41SAndroid Build Coastguard Workerallow domain self:fd use;
25*e4a36f41SAndroid Build Coastguard Workerallow domain proc:dir r_dir_perms;
26*e4a36f41SAndroid Build Coastguard Workerallow domain proc_net_type:dir search;
27*e4a36f41SAndroid Build Coastguard Workerr_dir_file(domain, self)
28*e4a36f41SAndroid Build Coastguard Workerallow domain self:{ fifo_file file } rw_file_perms;
29*e4a36f41SAndroid Build Coastguard Workerallow domain self:unix_dgram_socket { create_socket_perms sendto };
30*e4a36f41SAndroid Build Coastguard Workerallow domain self:unix_stream_socket { create_stream_socket_perms connectto };
31*e4a36f41SAndroid Build Coastguard Worker
32*e4a36f41SAndroid Build Coastguard Worker# Inherit or receive open files from others.
33*e4a36f41SAndroid Build Coastguard Workerallow domain init:fd use;
34*e4a36f41SAndroid Build Coastguard Worker
35*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
36*e4a36f41SAndroid Build Coastguard Worker  allow domain su:fd use;
37*e4a36f41SAndroid Build Coastguard Worker  allow domain su:unix_stream_socket { connectto getattr getopt read write shutdown };
38*e4a36f41SAndroid Build Coastguard Worker  allow domain su:unix_dgram_socket sendto;
39*e4a36f41SAndroid Build Coastguard Worker
40*e4a36f41SAndroid Build Coastguard Worker  allow { domain -init } su:binder { call transfer };
41*e4a36f41SAndroid Build Coastguard Worker
42*e4a36f41SAndroid Build Coastguard Worker  # Running something like "pm dump com.android.bluetooth" requires
43*e4a36f41SAndroid Build Coastguard Worker  # fifo writes
44*e4a36f41SAndroid Build Coastguard Worker  allow domain su:fifo_file { write getattr };
45*e4a36f41SAndroid Build Coastguard Worker
46*e4a36f41SAndroid Build Coastguard Worker  # allow "gdbserver --attach" to work for su.
47*e4a36f41SAndroid Build Coastguard Worker  allow domain su:process sigchld;
48*e4a36f41SAndroid Build Coastguard Worker
49*e4a36f41SAndroid Build Coastguard Worker  # Allow writing coredumps to /cores/*
50*e4a36f41SAndroid Build Coastguard Worker  allow domain coredump_file:file create_file_perms;
51*e4a36f41SAndroid Build Coastguard Worker  allow domain coredump_file:dir ra_dir_perms;
52*e4a36f41SAndroid Build Coastguard Worker')
53*e4a36f41SAndroid Build Coastguard Worker
54*e4a36f41SAndroid Build Coastguard Workerwith_native_coverage(`
55*e4a36f41SAndroid Build Coastguard Worker  # Allow writing coverage information to /data/misc/trace
56*e4a36f41SAndroid Build Coastguard Worker  allow domain method_trace_data_file:dir create_dir_perms;
57*e4a36f41SAndroid Build Coastguard Worker  allow domain method_trace_data_file:file create_file_perms;
58*e4a36f41SAndroid Build Coastguard Worker')
59*e4a36f41SAndroid Build Coastguard Worker
60*e4a36f41SAndroid Build Coastguard Worker# Root fs.
61*e4a36f41SAndroid Build Coastguard Workerallow domain tmpfs:dir { getattr search };
62*e4a36f41SAndroid Build Coastguard Workerallow domain rootfs:dir search;
63*e4a36f41SAndroid Build Coastguard Workerallow domain rootfs:lnk_file { read getattr };
64*e4a36f41SAndroid Build Coastguard Worker
65*e4a36f41SAndroid Build Coastguard Worker# Device accesses.
66*e4a36f41SAndroid Build Coastguard Workerallow domain device:dir search;
67*e4a36f41SAndroid Build Coastguard Workerallow domain dev_type:lnk_file r_file_perms;
68*e4a36f41SAndroid Build Coastguard Workerallow domain devpts:dir search;
69*e4a36f41SAndroid Build Coastguard Workerallow domain dmabuf_heap_device:dir r_dir_perms;
70*e4a36f41SAndroid Build Coastguard Workerallow domain socket_device:dir r_dir_perms;
71*e4a36f41SAndroid Build Coastguard Workerallow domain owntty_device:chr_file rw_file_perms;
72*e4a36f41SAndroid Build Coastguard Workerallow domain null_device:chr_file rw_file_perms;
73*e4a36f41SAndroid Build Coastguard Workerallow domain zero_device:chr_file rw_file_perms;
74*e4a36f41SAndroid Build Coastguard Worker
75*e4a36f41SAndroid Build Coastguard Worker# /dev/ashmem is being deprecated by means of constraining and eventually
76*e4a36f41SAndroid Build Coastguard Worker# removing all "open" permissions. We preserve the other permissions.
77*e4a36f41SAndroid Build Coastguard Workerallow domain ashmem_device:chr_file { getattr read ioctl lock map append write };
78*e4a36f41SAndroid Build Coastguard Worker# This device is used by libcutils, which is accessible to everyone.
79*e4a36f41SAndroid Build Coastguard Workerallow domain ashmem_libcutils_device:chr_file rw_file_perms;
80*e4a36f41SAndroid Build Coastguard Worker
81*e4a36f41SAndroid Build Coastguard Worker# /dev/binder can be accessed by ... everyone! :)
82*e4a36f41SAndroid Build Coastguard Workerallow { domain -hwservicemanager -vndservicemanager } binder_device:chr_file rw_file_perms;
83*e4a36f41SAndroid Build Coastguard Workerget_prop({domain -hwservicemanager -vndservicemanager }, servicemanager_prop)
84*e4a36f41SAndroid Build Coastguard Worker
85*e4a36f41SAndroid Build Coastguard Worker# Restrict binder ioctls to an allowlist. Additional ioctl commands may be
86*e4a36f41SAndroid Build Coastguard Worker# added to individual domains, but this sets safe defaults for all processes.
87*e4a36f41SAndroid Build Coastguard Workerallowxperm domain binder_device:chr_file ioctl { unpriv_binder_ioctls };
88*e4a36f41SAndroid Build Coastguard Worker
89*e4a36f41SAndroid Build Coastguard Worker# /dev/binderfs needs to be accessed by everyone too!
90*e4a36f41SAndroid Build Coastguard Workerallow domain binderfs:dir { getattr search };
91*e4a36f41SAndroid Build Coastguard Workerallow domain binderfs_logs_proc:dir search;
92*e4a36f41SAndroid Build Coastguard Workerallow domain binderfs_features:dir search;
93*e4a36f41SAndroid Build Coastguard Workerallow domain binderfs_features:file r_file_perms;
94*e4a36f41SAndroid Build Coastguard Worker
95*e4a36f41SAndroid Build Coastguard Workerallow { domain -servicemanager -vndservicemanager -isolated_app } hwbinder_device:chr_file rw_file_perms;
96*e4a36f41SAndroid Build Coastguard Workerallow domain ptmx_device:chr_file rw_file_perms;
97*e4a36f41SAndroid Build Coastguard Workerallow domain random_device:chr_file rw_file_perms;
98*e4a36f41SAndroid Build Coastguard Workerallow domain proc_random:dir r_dir_perms;
99*e4a36f41SAndroid Build Coastguard Workerallow domain proc_random:file r_file_perms;
100*e4a36f41SAndroid Build Coastguard Workerallow domain properties_device:dir { search getattr };
101*e4a36f41SAndroid Build Coastguard Workerallow domain properties_serial:file r_file_perms;
102*e4a36f41SAndroid Build Coastguard Workerallow domain property_info:file r_file_perms;
103*e4a36f41SAndroid Build Coastguard Worker
104*e4a36f41SAndroid Build Coastguard Worker# Let everyone read log properties, so that liblog can avoid sending unloggable
105*e4a36f41SAndroid Build Coastguard Worker# messages to logd.
106*e4a36f41SAndroid Build Coastguard Workerget_prop(domain, log_property_type)
107*e4a36f41SAndroid Build Coastguard Workerdontaudit domain property_type:file audit_access;
108*e4a36f41SAndroid Build Coastguard Workerallow domain property_contexts_file:file r_file_perms;
109*e4a36f41SAndroid Build Coastguard Worker
110*e4a36f41SAndroid Build Coastguard Workerallow domain init:key search;
111*e4a36f41SAndroid Build Coastguard Workerallow domain vold:key search;
112*e4a36f41SAndroid Build Coastguard Worker
113*e4a36f41SAndroid Build Coastguard Worker# logd access
114*e4a36f41SAndroid Build Coastguard Workerwrite_logd(domain)
115*e4a36f41SAndroid Build Coastguard Worker
116*e4a36f41SAndroid Build Coastguard Worker# Directory/link file access for path resolution.
117*e4a36f41SAndroid Build Coastguard Workerallow domain {
118*e4a36f41SAndroid Build Coastguard Worker    system_file
119*e4a36f41SAndroid Build Coastguard Worker    system_lib_file
120*e4a36f41SAndroid Build Coastguard Worker    system_seccomp_policy_file
121*e4a36f41SAndroid Build Coastguard Worker    system_security_cacerts_file
122*e4a36f41SAndroid Build Coastguard Worker}:dir r_dir_perms;
123*e4a36f41SAndroid Build Coastguard Workerallow domain system_file:lnk_file { getattr read };
124*e4a36f41SAndroid Build Coastguard Worker
125*e4a36f41SAndroid Build Coastguard Worker# Global access to /system/etc/security/cacerts/*, /system/etc/seccomp_policy/*, /system/lib[64]/*,
126*e4a36f41SAndroid Build Coastguard Worker# /(system|product|system_ext)/etc/(group|passwd), linker and its config.
127*e4a36f41SAndroid Build Coastguard Workerallow domain system_seccomp_policy_file:file r_file_perms;
128*e4a36f41SAndroid Build Coastguard Worker# cacerts are accessible from public Java API.
129*e4a36f41SAndroid Build Coastguard Workerallow domain system_security_cacerts_file:file r_file_perms;
130*e4a36f41SAndroid Build Coastguard Workerallow domain system_group_file:file r_file_perms;
131*e4a36f41SAndroid Build Coastguard Workerallow domain system_passwd_file:file r_file_perms;
132*e4a36f41SAndroid Build Coastguard Workerallow domain system_linker_exec:file { execute read open getattr map };
133*e4a36f41SAndroid Build Coastguard Workerallow domain system_linker_config_file:file r_file_perms;
134*e4a36f41SAndroid Build Coastguard Workerallow domain system_lib_file:file { execute read open getattr map };
135*e4a36f41SAndroid Build Coastguard Worker# To allow following symlinks at /system/bin/linker, /system/lib/libc.so, etc.
136*e4a36f41SAndroid Build Coastguard Workerallow domain system_linker_exec:lnk_file { read open getattr };
137*e4a36f41SAndroid Build Coastguard Workerallow domain system_lib_file:lnk_file { read open getattr };
138*e4a36f41SAndroid Build Coastguard Worker
139*e4a36f41SAndroid Build Coastguard Workerallow domain system_event_log_tags_file:file r_file_perms;
140*e4a36f41SAndroid Build Coastguard Worker
141*e4a36f41SAndroid Build Coastguard Workerallow { appdomain coredomain } system_file:file { execute read open getattr map };
142*e4a36f41SAndroid Build Coastguard Worker
143*e4a36f41SAndroid Build Coastguard Worker# Make sure system/vendor split doesn not affect non-treble
144*e4a36f41SAndroid Build Coastguard Worker# devices
145*e4a36f41SAndroid Build Coastguard Workernot_full_treble(`
146*e4a36f41SAndroid Build Coastguard Worker    allow domain system_file:file { execute read open getattr map };
147*e4a36f41SAndroid Build Coastguard Worker    allow domain vendor_file_type:dir { search getattr };
148*e4a36f41SAndroid Build Coastguard Worker    allow domain vendor_file_type:file { execute read open getattr map };
149*e4a36f41SAndroid Build Coastguard Worker    allow domain vendor_file_type:lnk_file { getattr read };
150*e4a36f41SAndroid Build Coastguard Worker')
151*e4a36f41SAndroid Build Coastguard Worker
152*e4a36f41SAndroid Build Coastguard Worker# All domains are allowed to open and read directories
153*e4a36f41SAndroid Build Coastguard Worker# that contain HAL implementations (e.g. passthrough
154*e4a36f41SAndroid Build Coastguard Worker# HALs require clients to have these permissions)
155*e4a36f41SAndroid Build Coastguard Workerallow domain vendor_hal_file:dir r_dir_perms;
156*e4a36f41SAndroid Build Coastguard Worker
157*e4a36f41SAndroid Build Coastguard Worker# Everyone can read and execute all same process HALs
158*e4a36f41SAndroid Build Coastguard Workerallow domain same_process_hal_file:dir r_dir_perms;
159*e4a36f41SAndroid Build Coastguard Workerallow {
160*e4a36f41SAndroid Build Coastguard Worker    domain
161*e4a36f41SAndroid Build Coastguard Worker    -coredomain # access is explicitly granted to individual coredomains
162*e4a36f41SAndroid Build Coastguard Worker} same_process_hal_file:file { execute read open getattr map };
163*e4a36f41SAndroid Build Coastguard Worker
164*e4a36f41SAndroid Build Coastguard Worker# Any process can load vndk-sp libraries, which are system libraries
165*e4a36f41SAndroid Build Coastguard Worker# used by same process HALs
166*e4a36f41SAndroid Build Coastguard Workerallow domain vndk_sp_file:dir r_dir_perms;
167*e4a36f41SAndroid Build Coastguard Workerallow domain vndk_sp_file:file { execute read open getattr map };
168*e4a36f41SAndroid Build Coastguard Worker
169*e4a36f41SAndroid Build Coastguard Worker# All domains get access to /vendor/etc
170*e4a36f41SAndroid Build Coastguard Workerallow domain vendor_configs_file:dir r_dir_perms;
171*e4a36f41SAndroid Build Coastguard Workerallow domain vendor_configs_file:file { read open getattr map };
172*e4a36f41SAndroid Build Coastguard Worker
173*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
174*e4a36f41SAndroid Build Coastguard Worker    # Allow all domains to be able to follow /system/vendor and/or
175*e4a36f41SAndroid Build Coastguard Worker    # /vendor/odm symlinks.
176*e4a36f41SAndroid Build Coastguard Worker    allow domain vendor_file_type:lnk_file { getattr open read };
177*e4a36f41SAndroid Build Coastguard Worker
178*e4a36f41SAndroid Build Coastguard Worker    # This is required to be able to search & read /vendor/lib64
179*e4a36f41SAndroid Build Coastguard Worker    # in order to lookup vendor libraries. The execute permission
180*e4a36f41SAndroid Build Coastguard Worker    # for coredomains is granted *only* for same process HALs
181*e4a36f41SAndroid Build Coastguard Worker    allow domain vendor_file:dir { getattr search };
182*e4a36f41SAndroid Build Coastguard Worker
183*e4a36f41SAndroid Build Coastguard Worker    # Allow reading and executing out of /vendor to all vendor domains
184*e4a36f41SAndroid Build Coastguard Worker    allow { domain -coredomain } vendor_file_type:dir r_dir_perms;
185*e4a36f41SAndroid Build Coastguard Worker    allow { domain -coredomain } vendor_file_type:file { read open getattr execute map };
186*e4a36f41SAndroid Build Coastguard Worker    allow { domain -coredomain } vendor_file_type:lnk_file { getattr read };
187*e4a36f41SAndroid Build Coastguard Worker')
188*e4a36f41SAndroid Build Coastguard Worker
189*e4a36f41SAndroid Build Coastguard Worker# read and stat any sysfs symlinks
190*e4a36f41SAndroid Build Coastguard Workerallow domain sysfs:lnk_file { getattr read };
191*e4a36f41SAndroid Build Coastguard Worker
192*e4a36f41SAndroid Build Coastguard Worker# libc references /system/usr/share/zoneinfo for timezone related information.
193*e4a36f41SAndroid Build Coastguard Worker# This directory is considered to be a VNDK-stable
194*e4a36f41SAndroid Build Coastguard Workerallow domain { system_zoneinfo_file }:file r_file_perms;
195*e4a36f41SAndroid Build Coastguard Workerallow domain { system_zoneinfo_file }:dir r_dir_perms;
196*e4a36f41SAndroid Build Coastguard Worker
197*e4a36f41SAndroid Build Coastguard Worker# Lots of processes access current CPU information
198*e4a36f41SAndroid Build Coastguard Workerr_dir_file(domain, sysfs_devices_system_cpu)
199*e4a36f41SAndroid Build Coastguard Worker
200*e4a36f41SAndroid Build Coastguard Workerr_dir_file(domain, sysfs_usb);
201*e4a36f41SAndroid Build Coastguard Worker
202*e4a36f41SAndroid Build Coastguard Worker# If kernel CONFIG_TRANSPARENT_HUGEPAGE is enabled, libjemalloc5 (statically
203*e4a36f41SAndroid Build Coastguard Worker# included by libc) reads /sys/kernel/mm/transparent_hugepage/enabled.
204*e4a36f41SAndroid Build Coastguard Workerallow domain sysfs_transparent_hugepage:dir search;
205*e4a36f41SAndroid Build Coastguard Workerallow domain sysfs_transparent_hugepage:file r_file_perms;
206*e4a36f41SAndroid Build Coastguard Worker
207*e4a36f41SAndroid Build Coastguard Worker# Allow search access, and sometimes getattr access, to various directories
208*e4a36f41SAndroid Build Coastguard Worker# under /data.  We are fairly lenient in allowing search access to top-level
209*e4a36f41SAndroid Build Coastguard Worker# dirs that commonly need to be traversed to get access to the "real" files, as
210*e4a36f41SAndroid Build Coastguard Worker# this greatly simplifies the policy and doesn't open up much attack surface.
211*e4a36f41SAndroid Build Coastguard Workernot_full_treble(`
212*e4a36f41SAndroid Build Coastguard Worker  allow domain system_data_file:dir getattr;
213*e4a36f41SAndroid Build Coastguard Worker')
214*e4a36f41SAndroid Build Coastguard Workerallow { coredomain appdomain } system_data_file:dir getattr;
215*e4a36f41SAndroid Build Coastguard Worker# Anything that accesses anything in /data needs search access to /data itself.
216*e4a36f41SAndroid Build Coastguard Worker# This includes vendor components, as they need to access /data/vendor.
217*e4a36f41SAndroid Build Coastguard Workerallow domain system_data_root_file:dir { search getattr } ;
218*e4a36f41SAndroid Build Coastguard Worker# system_data_file is the default type for directories in /data.  Anything
219*e4a36f41SAndroid Build Coastguard Worker# accessing data files with a more specific type often has to traverse a
220*e4a36f41SAndroid Build Coastguard Worker# system_data_file directory such as /data/misc to get there.
221*e4a36f41SAndroid Build Coastguard Workerallow domain system_data_file:dir search;
222*e4a36f41SAndroid Build Coastguard Worker# Anything that accesses files in /data/user (and /data/user_de, etc.) needs
223*e4a36f41SAndroid Build Coastguard Worker# search access to these directories themselves.  getattr access is sometimes
224*e4a36f41SAndroid Build Coastguard Worker# needed too.
225*e4a36f41SAndroid Build Coastguard Workerallow { coredomain appdomain } system_userdir_file:dir { search getattr };
226*e4a36f41SAndroid Build Coastguard Worker# Anything that accesses files in /data/media needs search access to /data/media
227*e4a36f41SAndroid Build Coastguard Worker# itself.
228*e4a36f41SAndroid Build Coastguard Workerallow { coredomain appdomain } media_userdir_file:dir search;
229*e4a36f41SAndroid Build Coastguard Worker# TODO restrict this to non-coredomain
230*e4a36f41SAndroid Build Coastguard Workerallow domain vendor_userdir_file:dir { getattr search };
231*e4a36f41SAndroid Build Coastguard Workerallow domain vendor_data_file:dir { getattr search };
232*e4a36f41SAndroid Build Coastguard Worker
233*e4a36f41SAndroid Build Coastguard Worker# required by the dynamic linker
234*e4a36f41SAndroid Build Coastguard Workerallow domain proc:lnk_file { getattr read };
235*e4a36f41SAndroid Build Coastguard Worker
236*e4a36f41SAndroid Build Coastguard Worker# /proc/cpuinfo
237*e4a36f41SAndroid Build Coastguard Workerallow domain proc_cpuinfo:file r_file_perms;
238*e4a36f41SAndroid Build Coastguard Worker
239*e4a36f41SAndroid Build Coastguard Worker# /dev/cpu_variant:.*
240*e4a36f41SAndroid Build Coastguard Workerallow domain dev_cpu_variant:file r_file_perms;
241*e4a36f41SAndroid Build Coastguard Worker
242*e4a36f41SAndroid Build Coastguard Worker# profiling needs to read /proc/sys/kernel/perf_event_max_sample_rate
243*e4a36f41SAndroid Build Coastguard Workerallow domain proc_perf:file r_file_perms;
244*e4a36f41SAndroid Build Coastguard Worker
245*e4a36f41SAndroid Build Coastguard Worker# toybox loads libselinux which stats /sys/fs/selinux/
246*e4a36f41SAndroid Build Coastguard Workerallow domain selinuxfs:dir search;
247*e4a36f41SAndroid Build Coastguard Workerallow domain selinuxfs:file getattr;
248*e4a36f41SAndroid Build Coastguard Workerallow domain sysfs:dir search;
249*e4a36f41SAndroid Build Coastguard Workerallow domain selinuxfs:filesystem getattr;
250*e4a36f41SAndroid Build Coastguard Worker
251*e4a36f41SAndroid Build Coastguard Worker# Almost all processes log tracing information to
252*e4a36f41SAndroid Build Coastguard Worker# /sys/kernel/debug/tracing/trace_marker
253*e4a36f41SAndroid Build Coastguard Worker# The reason behind this is documented in b/6513400
254*e4a36f41SAndroid Build Coastguard Workerallow domain debugfs:dir search;
255*e4a36f41SAndroid Build Coastguard Workerallow domain debugfs_tracing:dir search;
256*e4a36f41SAndroid Build Coastguard Workerallow domain debugfs_tracing_debug:dir search;
257*e4a36f41SAndroid Build Coastguard Workerallow domain debugfs_trace_marker:file w_file_perms;
258*e4a36f41SAndroid Build Coastguard Worker
259*e4a36f41SAndroid Build Coastguard Worker# Linux lockdown mode offers coarse-grained definitions for access controls.
260*e4a36f41SAndroid Build Coastguard Worker# The "confidentiality" level detects access to tracefs or the perf subsystem.
261*e4a36f41SAndroid Build Coastguard Worker# This overlaps with more precise declarations in Android's policy. The
262*e4a36f41SAndroid Build Coastguard Worker# debugfs_trace_marker above is an example in which all processes should have
263*e4a36f41SAndroid Build Coastguard Worker# some access to tracefs. Therefore, allow all domains to access this level.
264*e4a36f41SAndroid Build Coastguard Worker# The "integrity" level is however enforced.
265*e4a36f41SAndroid Build Coastguard Workerallow domain self:lockdown confidentiality;
266*e4a36f41SAndroid Build Coastguard Worker
267*e4a36f41SAndroid Build Coastguard Worker# Filesystem access.
268*e4a36f41SAndroid Build Coastguard Workerallow domain fs_type:filesystem getattr;
269*e4a36f41SAndroid Build Coastguard Workerallow domain fs_type:dir getattr;
270*e4a36f41SAndroid Build Coastguard Worker
271*e4a36f41SAndroid Build Coastguard Worker# Restrict all domains to an allowlist for common socket types. Additional
272*e4a36f41SAndroid Build Coastguard Worker# ioctl commands may be added to individual domains, but this sets safe
273*e4a36f41SAndroid Build Coastguard Worker# defaults for all processes. Note that granting this allowlist to domain does
274*e4a36f41SAndroid Build Coastguard Worker# not grant the ioctl permission on these socket types. That must be granted
275*e4a36f41SAndroid Build Coastguard Worker# separately.
276*e4a36f41SAndroid Build Coastguard Workerallowxperm domain domain:{ icmp_socket rawip_socket tcp_socket udp_socket }
277*e4a36f41SAndroid Build Coastguard Worker  ioctl { unpriv_sock_ioctls unpriv_tty_ioctls };
278*e4a36f41SAndroid Build Coastguard Worker# default allowlist for unix sockets.
279*e4a36f41SAndroid Build Coastguard Workerallowxperm domain { domain pdx_channel_socket_type }:{ unix_dgram_socket unix_stream_socket }
280*e4a36f41SAndroid Build Coastguard Worker  ioctl unpriv_unix_sock_ioctls;
281*e4a36f41SAndroid Build Coastguard Worker
282*e4a36f41SAndroid Build Coastguard Worker# Restrict PTYs to only allowed ioctls.
283*e4a36f41SAndroid Build Coastguard Worker# Note that granting this allowlist to domain does
284*e4a36f41SAndroid Build Coastguard Worker# not grant the wider ioctl permission. That must be granted
285*e4a36f41SAndroid Build Coastguard Worker# separately.
286*e4a36f41SAndroid Build Coastguard Workerallowxperm domain devpts:chr_file ioctl unpriv_tty_ioctls;
287*e4a36f41SAndroid Build Coastguard Worker
288*e4a36f41SAndroid Build Coastguard Worker# All domains must clearly enumerate what ioctls they use
289*e4a36f41SAndroid Build Coastguard Worker# on filesystem objects (plain files, directories, symbolic links,
290*e4a36f41SAndroid Build Coastguard Worker# named pipes, and named sockets). We start off with a safe set.
291*e4a36f41SAndroid Build Coastguard Workerallowxperm domain { file_type fs_type domain dev_type }:{ dir notdevfile_class_set blk_file } ioctl { FIOCLEX FIONCLEX };
292*e4a36f41SAndroid Build Coastguard Worker
293*e4a36f41SAndroid Build Coastguard Worker# If a domain has ioctl access to tun_device, it must clearly enumerate the
294*e4a36f41SAndroid Build Coastguard Worker# ioctls used. Safe defaults are listed below.
295*e4a36f41SAndroid Build Coastguard Workerallowxperm domain tun_device:chr_file ioctl { FIOCLEX FIONCLEX };
296*e4a36f41SAndroid Build Coastguard Worker
297*e4a36f41SAndroid Build Coastguard Worker# Allow a process to make a determination whether a file descriptor
298*e4a36f41SAndroid Build Coastguard Worker# for a plain file or pipe (fifo_file) is a tty. Note that granting
299*e4a36f41SAndroid Build Coastguard Worker# this allowlist to domain does not grant the ioctl permission to
300*e4a36f41SAndroid Build Coastguard Worker# these files. That must be granted separately.
301*e4a36f41SAndroid Build Coastguard Workerallowxperm domain { file_type fs_type }:file ioctl { TCGETS };
302*e4a36f41SAndroid Build Coastguard Workerallowxperm domain domain:fifo_file ioctl { TCGETS };
303*e4a36f41SAndroid Build Coastguard Worker
304*e4a36f41SAndroid Build Coastguard Worker# If a domain has access to perform an ioctl on a block device, allow these
305*e4a36f41SAndroid Build Coastguard Worker# very common, benign ioctls
306*e4a36f41SAndroid Build Coastguard Workerallowxperm domain dev_type:blk_file ioctl { BLKGETSIZE64 BLKSSZGET };
307*e4a36f41SAndroid Build Coastguard Worker
308*e4a36f41SAndroid Build Coastguard Worker# Support sqlite F2FS specific optimizations
309*e4a36f41SAndroid Build Coastguard Worker# ioctl permission on the specific file type is still required
310*e4a36f41SAndroid Build Coastguard Worker# TODO: consider only compiling these rules if we know the
311*e4a36f41SAndroid Build Coastguard Worker# /data partition is F2FS
312*e4a36f41SAndroid Build Coastguard Workerallowxperm domain { file_type sdcard_type }:file ioctl {
313*e4a36f41SAndroid Build Coastguard Worker  F2FS_IOC_ABORT_VOLATILE_WRITE
314*e4a36f41SAndroid Build Coastguard Worker  F2FS_IOC_COMMIT_ATOMIC_WRITE
315*e4a36f41SAndroid Build Coastguard Worker  F2FS_IOC_GET_FEATURES
316*e4a36f41SAndroid Build Coastguard Worker  F2FS_IOC_GET_PIN_FILE
317*e4a36f41SAndroid Build Coastguard Worker  F2FS_IOC_SET_PIN_FILE
318*e4a36f41SAndroid Build Coastguard Worker  F2FS_IOC_START_ATOMIC_WRITE
319*e4a36f41SAndroid Build Coastguard Worker};
320*e4a36f41SAndroid Build Coastguard Worker
321*e4a36f41SAndroid Build Coastguard Worker# Workaround for policy compiler being too aggressive and removing hwservice_manager_type
322*e4a36f41SAndroid Build Coastguard Worker# when it's not explicitly used in allow rules
323*e4a36f41SAndroid Build Coastguard Workerallow { domain -domain } hwservice_manager_type:hwservice_manager { add find };
324*e4a36f41SAndroid Build Coastguard Worker# Workaround for policy compiler being too aggressive and removing vndservice_manager_type
325*e4a36f41SAndroid Build Coastguard Worker# when it's not explicitly used in allow rules
326*e4a36f41SAndroid Build Coastguard Workerallow { domain -domain } vndservice_manager_type:service_manager { add find };
327*e4a36f41SAndroid Build Coastguard Worker
328*e4a36f41SAndroid Build Coastguard Worker# Under ASAN, processes will try to read /data, as the sanitized libraries are there.
329*e4a36f41SAndroid Build Coastguard Workerwith_asan(`allow domain system_data_file:dir getattr;')
330*e4a36f41SAndroid Build Coastguard Worker# Under ASAN, /system/asan.options needs to be globally accessible.
331*e4a36f41SAndroid Build Coastguard Workerwith_asan(`allow domain system_asan_options_file:file r_file_perms;')
332*e4a36f41SAndroid Build Coastguard Worker
333*e4a36f41SAndroid Build Coastguard Worker# read APEX dir and stat any symlink pointing to APEXs.
334*e4a36f41SAndroid Build Coastguard Workerallow domain apex_mnt_dir:dir { getattr search };
335*e4a36f41SAndroid Build Coastguard Workerallow domain apex_mnt_dir:lnk_file r_file_perms;
336*e4a36f41SAndroid Build Coastguard Worker
337*e4a36f41SAndroid Build Coastguard Worker###
338*e4a36f41SAndroid Build Coastguard Worker### neverallow rules
339*e4a36f41SAndroid Build Coastguard Worker###
340*e4a36f41SAndroid Build Coastguard Worker
341*e4a36f41SAndroid Build Coastguard Worker# All ioctls on file-like objects (except chr_file and blk_file) and
342*e4a36f41SAndroid Build Coastguard Worker# sockets must be restricted to an allowlist.
343*e4a36f41SAndroid Build Coastguard Workerneverallowxperm * *:{ dir notdevfile_class_set socket_class_set blk_file } ioctl { 0 };
344*e4a36f41SAndroid Build Coastguard Worker
345*e4a36f41SAndroid Build Coastguard Worker# b/68014825 and https://android-review.googlesource.com/516535
346*e4a36f41SAndroid Build Coastguard Worker# rfc6093 says that processes should not use the TCP urgent mechanism
347*e4a36f41SAndroid Build Coastguard Workerneverallowxperm domain domain:socket_class_set ioctl { SIOCATMARK };
348*e4a36f41SAndroid Build Coastguard Worker
349*e4a36f41SAndroid Build Coastguard Worker# TIOCSTI is only ever used for exploits. Block it.
350*e4a36f41SAndroid Build Coastguard Worker# b/33073072, b/7530569
351*e4a36f41SAndroid Build Coastguard Worker# http://www.openwall.com/lists/oss-security/2016/09/26/14
352*e4a36f41SAndroid Build Coastguard Workerneverallowxperm * devpts:chr_file ioctl TIOCSTI;
353*e4a36f41SAndroid Build Coastguard Worker
354*e4a36f41SAndroid Build Coastguard Worker# Do not allow any domain other than init to create unlabeled files.
355*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -recovery } unlabeled:dir_file_class_set create;
356*e4a36f41SAndroid Build Coastguard Worker
357*e4a36f41SAndroid Build Coastguard Worker# Limit device node creation to these allowed domains.
358*e4a36f41SAndroid Build Coastguard Workerneverallow {
359*e4a36f41SAndroid Build Coastguard Worker  domain
360*e4a36f41SAndroid Build Coastguard Worker  -kernel
361*e4a36f41SAndroid Build Coastguard Worker  -init
362*e4a36f41SAndroid Build Coastguard Worker  -ueventd
363*e4a36f41SAndroid Build Coastguard Worker  -vold
364*e4a36f41SAndroid Build Coastguard Worker} self:global_capability_class_set mknod;
365*e4a36f41SAndroid Build Coastguard Worker
366*e4a36f41SAndroid Build Coastguard Worker# No process can map low memory (< CONFIG_LSM_MMAP_MIN_ADDR).
367*e4a36f41SAndroid Build Coastguard Workerneverallow * self:memprotect mmap_zero;
368*e4a36f41SAndroid Build Coastguard Worker
369*e4a36f41SAndroid Build Coastguard Worker# No domain needs mac_override as it is unused by SELinux.
370*e4a36f41SAndroid Build Coastguard Workerneverallow * self:global_capability2_class_set mac_override;
371*e4a36f41SAndroid Build Coastguard Worker
372*e4a36f41SAndroid Build Coastguard Worker# Disallow attempts to set contexts not defined in current policy
373*e4a36f41SAndroid Build Coastguard Worker# This helps guarantee that unknown or dangerous contents will not ever
374*e4a36f41SAndroid Build Coastguard Worker# be set.
375*e4a36f41SAndroid Build Coastguard Workerneverallow * self:global_capability2_class_set mac_admin;
376*e4a36f41SAndroid Build Coastguard Worker
377*e4a36f41SAndroid Build Coastguard Worker# Once the policy has been loaded there shall be none to modify the policy.
378*e4a36f41SAndroid Build Coastguard Worker# It is sealed.
379*e4a36f41SAndroid Build Coastguard Workerneverallow * kernel:security load_policy;
380*e4a36f41SAndroid Build Coastguard Worker
381*e4a36f41SAndroid Build Coastguard Worker# Only init prior to switching context should be able to set enforcing mode.
382*e4a36f41SAndroid Build Coastguard Worker# init starts in kernel domain and switches to init domain via setcon in
383*e4a36f41SAndroid Build Coastguard Worker# the init.rc, so the setenforce occurs while still in kernel. After
384*e4a36f41SAndroid Build Coastguard Worker# switching domains, there is never any need to setenforce again by init.
385*e4a36f41SAndroid Build Coastguard Workerneverallow * kernel:security setenforce;
386*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -kernel } kernel:security setcheckreqprot;
387*e4a36f41SAndroid Build Coastguard Worker
388*e4a36f41SAndroid Build Coastguard Worker# No booleans in AOSP policy, so no need to ever set them.
389*e4a36f41SAndroid Build Coastguard Workerneverallow * kernel:security setbool;
390*e4a36f41SAndroid Build Coastguard Worker
391*e4a36f41SAndroid Build Coastguard Worker# Adjusting the AVC cache threshold.
392*e4a36f41SAndroid Build Coastguard Worker# Not presently allowed to anything in policy, but possibly something
393*e4a36f41SAndroid Build Coastguard Worker# that could be set from init.rc.
394*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } kernel:security setsecparam;
395*e4a36f41SAndroid Build Coastguard Worker
396*e4a36f41SAndroid Build Coastguard Worker# Only the kernel hwrng thread should be able to read from the HW RNG.
397*e4a36f41SAndroid Build Coastguard Workerneverallow {
398*e4a36f41SAndroid Build Coastguard Worker  domain
399*e4a36f41SAndroid Build Coastguard Worker  -prng_seeder # PRNG seeder daemon periodically reseeds itself from HW RNG
400*e4a36f41SAndroid Build Coastguard Worker  -shell # For CTS, restricted to just getattr in shell.te
401*e4a36f41SAndroid Build Coastguard Worker  -ueventd # To create the /dev/hw_random file
402*e4a36f41SAndroid Build Coastguard Worker} hw_random_device:chr_file *;
403*e4a36f41SAndroid Build Coastguard Worker# b/78174219 b/64114943
404*e4a36f41SAndroid Build Coastguard Workerneverallow {
405*e4a36f41SAndroid Build Coastguard Worker  domain
406*e4a36f41SAndroid Build Coastguard Worker  -shell # stat of /dev, getattr only
407*e4a36f41SAndroid Build Coastguard Worker  -ueventd
408*e4a36f41SAndroid Build Coastguard Worker} keychord_device:chr_file *;
409*e4a36f41SAndroid Build Coastguard Worker
410*e4a36f41SAndroid Build Coastguard Worker# Ensure that all entrypoint executables are in exec_type or postinstall_file.
411*e4a36f41SAndroid Build Coastguard Workerneverallow * { file_type -exec_type -postinstall_file }:file entrypoint;
412*e4a36f41SAndroid Build Coastguard Worker
413*e4a36f41SAndroid Build Coastguard Worker# The dynamic linker always calls access(2) on the path. Don't generate SElinux
414*e4a36f41SAndroid Build Coastguard Worker# denials since the linker does not actually access the path in case the path
415*e4a36f41SAndroid Build Coastguard Worker# does not exist or isn't accessible for the process.
416*e4a36f41SAndroid Build Coastguard Workerdontaudit domain postinstall_mnt_dir:dir audit_access;
417*e4a36f41SAndroid Build Coastguard Worker
418*e4a36f41SAndroid Build Coastguard Worker#Ensure that nothing in userspace can access /dev/port
419*e4a36f41SAndroid Build Coastguard Workerneverallow {
420*e4a36f41SAndroid Build Coastguard Worker  domain
421*e4a36f41SAndroid Build Coastguard Worker  -shell # Shell user should not have any abilities outside of getattr
422*e4a36f41SAndroid Build Coastguard Worker  -ueventd
423*e4a36f41SAndroid Build Coastguard Worker} port_device:chr_file *;
424*e4a36f41SAndroid Build Coastguard Workerneverallow * port_device:chr_file ~{ create relabelto unlink setattr getattr };
425*e4a36f41SAndroid Build Coastguard Worker# Only init should be able to configure kernel usermodehelpers or
426*e4a36f41SAndroid Build Coastguard Worker# security-sensitive proc settings.
427*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } usermodehelper:file { append write };
428*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -ueventd } sysfs_usermodehelper:file { append write };
429*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -vendor_init } proc_security:file { append open read write };
430*e4a36f41SAndroid Build Coastguard Worker
431*e4a36f41SAndroid Build Coastguard Worker# Init can't do anything with binder calls. If this neverallow rule is being
432*e4a36f41SAndroid Build Coastguard Worker# triggered, it's probably due to a service with no SELinux domain.
433*e4a36f41SAndroid Build Coastguard Workerneverallow * init:binder *;
434*e4a36f41SAndroid Build Coastguard Workerneverallow * vendor_init:binder *;
435*e4a36f41SAndroid Build Coastguard Worker
436*e4a36f41SAndroid Build Coastguard Worker# Don't allow raw read/write/open access to block_device
437*e4a36f41SAndroid Build Coastguard Worker# Rather force a relabel to a more specific type
438*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -kernel -init -recovery } block_device:blk_file { open read write };
439*e4a36f41SAndroid Build Coastguard Worker
440*e4a36f41SAndroid Build Coastguard Worker# Do not allow renaming of block files or character files
441*e4a36f41SAndroid Build Coastguard Worker# Ability to do so can lead to possible use in an exploit chain
442*e4a36f41SAndroid Build Coastguard Worker# e.g. https://googleprojectzero.blogspot.com/2016/12/chrome-os-exploit-one-byte-overflow-and.html
443*e4a36f41SAndroid Build Coastguard Workerneverallow * *:{ blk_file chr_file } rename;
444*e4a36f41SAndroid Build Coastguard Worker
445*e4a36f41SAndroid Build Coastguard Worker# Don't allow raw read/write/open access to generic devices.
446*e4a36f41SAndroid Build Coastguard Worker# Rather force a relabel to a more specific type.
447*e4a36f41SAndroid Build Coastguard Workerneverallow domain device:chr_file { open read write };
448*e4a36f41SAndroid Build Coastguard Worker
449*e4a36f41SAndroid Build Coastguard Worker# Files from cache should never be executed
450*e4a36f41SAndroid Build Coastguard Workerneverallow domain { cache_file cache_backup_file cache_private_backup_file cache_recovery_file }:file execute;
451*e4a36f41SAndroid Build Coastguard Worker
452*e4a36f41SAndroid Build Coastguard Worker# The test files and executables MUST not be accessible to any domain
453*e4a36f41SAndroid Build Coastguard Workerneverallow { domain userdebug_or_eng(`-kernel') } nativetest_data_file:file_class_set no_w_file_perms;
454*e4a36f41SAndroid Build Coastguard Workerneverallow domain nativetest_data_file:dir no_w_dir_perms;
455*e4a36f41SAndroid Build Coastguard Workerneverallow { domain userdebug_or_eng(`-shell') } nativetest_data_file:file no_x_file_perms;
456*e4a36f41SAndroid Build Coastguard Worker
457*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -shell -init -adbd } shell_test_data_file:file_class_set no_w_file_perms;
458*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -shell -init -adbd } shell_test_data_file:dir no_w_dir_perms;
459*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -shell -init -adbd -heapprofd -crash_dump } shell_test_data_file:file *;
460*e4a36f41SAndroid Build Coastguard Workerneverallow heapprofd shell_test_data_file:file { no_w_file_perms no_x_file_perms };
461*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -shell -init -adbd } shell_test_data_file:sock_file *;
462*e4a36f41SAndroid Build Coastguard Worker
463*e4a36f41SAndroid Build Coastguard Worker# Only the init property service should write to /data/property and /dev/__properties__
464*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } property_data_file:dir no_w_dir_perms;
465*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } property_data_file:file { no_w_file_perms no_x_file_perms };
466*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } property_type:file { no_w_file_perms no_x_file_perms };
467*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } properties_device:file { no_w_file_perms no_x_file_perms };
468*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } properties_serial:file { no_w_file_perms no_x_file_perms };
469*e4a36f41SAndroid Build Coastguard Worker
470*e4a36f41SAndroid Build Coastguard Worker# Nobody should be doing writes to /system & /vendor
471*e4a36f41SAndroid Build Coastguard Worker# These partitions are intended to be read-only and must never be
472*e4a36f41SAndroid Build Coastguard Worker# modified. Doing so would violate important Android security guarantees
473*e4a36f41SAndroid Build Coastguard Worker# and invalidate dm-verity signatures.
474*e4a36f41SAndroid Build Coastguard Workerneverallow {
475*e4a36f41SAndroid Build Coastguard Worker    domain
476*e4a36f41SAndroid Build Coastguard Worker    with_asan(`-asan_extract')
477*e4a36f41SAndroid Build Coastguard Worker    recovery_only(`userdebug_or_eng(`-fastbootd')')
478*e4a36f41SAndroid Build Coastguard Worker} {
479*e4a36f41SAndroid Build Coastguard Worker    system_file_type
480*e4a36f41SAndroid Build Coastguard Worker    vendor_file_type
481*e4a36f41SAndroid Build Coastguard Worker    exec_type
482*e4a36f41SAndroid Build Coastguard Worker}:dir_file_class_set { create write setattr relabelfrom append unlink link rename };
483*e4a36f41SAndroid Build Coastguard Worker
484*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -kernel with_asan(`-asan_extract') } { system_file_type vendor_file_type exec_type }:dir_file_class_set relabelto;
485*e4a36f41SAndroid Build Coastguard Worker
486*e4a36f41SAndroid Build Coastguard Worker# Don't allow mounting on top of /system files or directories
487*e4a36f41SAndroid Build Coastguard Workerneverallow * exec_type:dir_file_class_set mounton;
488*e4a36f41SAndroid Build Coastguard Worker
489*e4a36f41SAndroid Build Coastguard Worker# Nothing should be writing to files in the rootfs.
490*e4a36f41SAndroid Build Coastguard Workerneverallow * rootfs:file { create write setattr relabelto append unlink link rename };
491*e4a36f41SAndroid Build Coastguard Worker
492*e4a36f41SAndroid Build Coastguard Worker# Restrict context mounts to specific types marked with
493*e4a36f41SAndroid Build Coastguard Worker# the contextmount_type attribute.
494*e4a36f41SAndroid Build Coastguard Workerneverallow * {fs_type -contextmount_type}:filesystem relabelto;
495*e4a36f41SAndroid Build Coastguard Worker
496*e4a36f41SAndroid Build Coastguard Worker# Ensure that context mount types are not writable, to ensure that
497*e4a36f41SAndroid Build Coastguard Worker# the write to /system restriction above is not bypassed via context=
498*e4a36f41SAndroid Build Coastguard Worker# mount to another type.
499*e4a36f41SAndroid Build Coastguard Workerneverallow * contextmount_type:dir_file_class_set
500*e4a36f41SAndroid Build Coastguard Worker    { create setattr relabelfrom relabelto append link rename };
501*e4a36f41SAndroid Build Coastguard Workerneverallow { domain recovery_only(`userdebug_or_eng(`-fastbootd')') } contextmount_type:dir_file_class_set { write unlink };
502*e4a36f41SAndroid Build Coastguard Worker
503*e4a36f41SAndroid Build Coastguard Worker# Do not allow service_manager add for default service labels.
504*e4a36f41SAndroid Build Coastguard Worker# Instead domains should use a more specific type such as
505*e4a36f41SAndroid Build Coastguard Worker# system_app_service rather than the generic type.
506*e4a36f41SAndroid Build Coastguard Worker# New service_types are defined in {,hw,vnd}service.te and new mappings
507*e4a36f41SAndroid Build Coastguard Worker# from service name to service_type are defined in {,hw,vnd}service_contexts.
508*e4a36f41SAndroid Build Coastguard Workerneverallow * default_android_service:service_manager *;
509*e4a36f41SAndroid Build Coastguard Workerneverallow * default_android_vndservice:service_manager *;
510*e4a36f41SAndroid Build Coastguard Workerneverallow * default_android_hwservice:hwservice_manager *;
511*e4a36f41SAndroid Build Coastguard Worker
512*e4a36f41SAndroid Build Coastguard Worker# Looking up the base class/interface of all HwBinder services is a bad idea.
513*e4a36f41SAndroid Build Coastguard Worker# hwservicemanager currently offer such lookups only to make it so that security
514*e4a36f41SAndroid Build Coastguard Worker# decisions are expressed in SELinux policy. However, it's unclear whether this
515*e4a36f41SAndroid Build Coastguard Worker# lookup has security implications. If it doesn't, hwservicemanager should be
516*e4a36f41SAndroid Build Coastguard Worker# modified to not offer this lookup.
517*e4a36f41SAndroid Build Coastguard Worker# This rule can be removed if hwservicemanager is modified to not permit these
518*e4a36f41SAndroid Build Coastguard Worker# lookups.
519*e4a36f41SAndroid Build Coastguard Workerneverallow * hidl_base_hwservice:hwservice_manager find;
520*e4a36f41SAndroid Build Coastguard Worker
521*e4a36f41SAndroid Build Coastguard Worker# Require that domains explicitly label unknown properties, and do not allow
522*e4a36f41SAndroid Build Coastguard Worker# anyone but init to modify unknown properties.
523*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -vendor_init } mmc_prop:property_service set;
524*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -vendor_init } vndk_prop:property_service set;
525*e4a36f41SAndroid Build Coastguard Worker
526*e4a36f41SAndroid Build Coastguard Workercompatible_property_only(`
527*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -init } mmc_prop:property_service set;
528*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -init -vendor_init } exported_default_prop:property_service set;
529*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -init } exported_secure_prop:property_service set;
530*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -init -vendor_init } vendor_default_prop:property_service set;
531*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -init -vendor_init } storage_config_prop:property_service set;
532*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -init -vendor_init } hw_timeout_multiplier_prop:property_service set;
533*e4a36f41SAndroid Build Coastguard Worker')
534*e4a36f41SAndroid Build Coastguard Worker
535*e4a36f41SAndroid Build Coastguard Workercompatible_property_only(`
536*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -init -system_server -vendor_init } exported_pm_prop:property_service set;
537*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -coredomain -vendor_init } exported_pm_prop:file no_rw_file_perms;
538*e4a36f41SAndroid Build Coastguard Worker')
539*e4a36f41SAndroid Build Coastguard Worker
540*e4a36f41SAndroid Build Coastguard Worker# New "pm.dexopt." sysprops should be explicitly listed as exported_pm_prop.
541*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -dumpstate -vendor_init } future_pm_prop:property_service set;
542*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -dumpstate -vendor_init } future_pm_prop:file no_rw_file_perms;
543*e4a36f41SAndroid Build Coastguard Worker
544*e4a36f41SAndroid Build Coastguard Worker# ART may introduce new sysprops. SELinux denials due to reading new sysprops on
545*e4a36f41SAndroid Build Coastguard Worker# old platforms shouldn't be regarded as a problem.
546*e4a36f41SAndroid Build Coastguard Workerdontaudit domain future_pm_prop:file read;
547*e4a36f41SAndroid Build Coastguard Worker
548*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } aac_drc_prop:property_service set;
549*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } build_prop:property_service set;
550*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } userdebug_or_eng_prop:property_service set;
551*e4a36f41SAndroid Build Coastguard Worker
552*e4a36f41SAndroid Build Coastguard Worker# Do not allow reading device's serial number from system properties except form
553*e4a36f41SAndroid Build Coastguard Worker# a few allowed domains.
554*e4a36f41SAndroid Build Coastguard Workerneverallow {
555*e4a36f41SAndroid Build Coastguard Worker  domain
556*e4a36f41SAndroid Build Coastguard Worker  -adbd
557*e4a36f41SAndroid Build Coastguard Worker  -dumpstate
558*e4a36f41SAndroid Build Coastguard Worker  -fastbootd
559*e4a36f41SAndroid Build Coastguard Worker  -hal_camera_server
560*e4a36f41SAndroid Build Coastguard Worker  -hal_cas_server
561*e4a36f41SAndroid Build Coastguard Worker  -hal_drm_server
562*e4a36f41SAndroid Build Coastguard Worker  -hal_keymint_server
563*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-incidentd')
564*e4a36f41SAndroid Build Coastguard Worker  -init
565*e4a36f41SAndroid Build Coastguard Worker  -mediadrmserver
566*e4a36f41SAndroid Build Coastguard Worker  -mediaserver
567*e4a36f41SAndroid Build Coastguard Worker  -recovery
568*e4a36f41SAndroid Build Coastguard Worker  -shell
569*e4a36f41SAndroid Build Coastguard Worker  -system_server
570*e4a36f41SAndroid Build Coastguard Worker  -vendor_init
571*e4a36f41SAndroid Build Coastguard Worker} serialno_prop:file r_file_perms;
572*e4a36f41SAndroid Build Coastguard Worker
573*e4a36f41SAndroid Build Coastguard Workerneverallow {
574*e4a36f41SAndroid Build Coastguard Worker  domain
575*e4a36f41SAndroid Build Coastguard Worker  -init
576*e4a36f41SAndroid Build Coastguard Worker  -recovery
577*e4a36f41SAndroid Build Coastguard Worker  -system_server
578*e4a36f41SAndroid Build Coastguard Worker  -shell # Shell is further restricted in shell.te
579*e4a36f41SAndroid Build Coastguard Worker  -ueventd # Further restricted in ueventd.te
580*e4a36f41SAndroid Build Coastguard Worker} frp_block_device:blk_file no_rw_file_perms;
581*e4a36f41SAndroid Build Coastguard Worker
582*e4a36f41SAndroid Build Coastguard Worker# The metadata block device is set aside for device encryption and
583*e4a36f41SAndroid Build Coastguard Worker# verified boot metadata. It may be reset at will and should not
584*e4a36f41SAndroid Build Coastguard Worker# be used by other domains.
585*e4a36f41SAndroid Build Coastguard Workerneverallow {
586*e4a36f41SAndroid Build Coastguard Worker  domain
587*e4a36f41SAndroid Build Coastguard Worker  -init
588*e4a36f41SAndroid Build Coastguard Worker  -recovery
589*e4a36f41SAndroid Build Coastguard Worker  -vold
590*e4a36f41SAndroid Build Coastguard Worker  -e2fs
591*e4a36f41SAndroid Build Coastguard Worker  -fsck
592*e4a36f41SAndroid Build Coastguard Worker  -fastbootd
593*e4a36f41SAndroid Build Coastguard Worker  -hal_fastboot_server
594*e4a36f41SAndroid Build Coastguard Worker} metadata_block_device:blk_file { append link rename write open read ioctl lock };
595*e4a36f41SAndroid Build Coastguard Worker
596*e4a36f41SAndroid Build Coastguard Worker# No domain other than recovery, update_engine and fastbootd can write to system partition(s).
597*e4a36f41SAndroid Build Coastguard Workerneverallow {
598*e4a36f41SAndroid Build Coastguard Worker  domain
599*e4a36f41SAndroid Build Coastguard Worker  -fastbootd
600*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-fsck')
601*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-init')
602*e4a36f41SAndroid Build Coastguard Worker  -recovery
603*e4a36f41SAndroid Build Coastguard Worker  -update_engine
604*e4a36f41SAndroid Build Coastguard Worker} system_block_device:blk_file { write append };
605*e4a36f41SAndroid Build Coastguard Worker
606*e4a36f41SAndroid Build Coastguard Worker# Only (hw|vnd|)servicemanager should be able to register with binder as the context manager
607*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -servicemanager -hwservicemanager -vndservicemanager } *:binder set_context_mgr;
608*e4a36f41SAndroid Build Coastguard Worker# The service managers are only allowed to access their own device node
609*e4a36f41SAndroid Build Coastguard Workerneverallow servicemanager hwbinder_device:chr_file no_rw_file_perms;
610*e4a36f41SAndroid Build Coastguard Workerneverallow servicemanager vndbinder_device:chr_file no_rw_file_perms;
611*e4a36f41SAndroid Build Coastguard Workerneverallow hwservicemanager binder_device:chr_file no_rw_file_perms;
612*e4a36f41SAndroid Build Coastguard Workerneverallow hwservicemanager vndbinder_device:chr_file no_rw_file_perms;
613*e4a36f41SAndroid Build Coastguard Workerneverallow vndservicemanager binder_device:chr_file no_rw_file_perms;
614*e4a36f41SAndroid Build Coastguard Workerneverallow vndservicemanager hwbinder_device:chr_file no_rw_file_perms;
615*e4a36f41SAndroid Build Coastguard Worker
616*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
617*e4a36f41SAndroid Build Coastguard Worker  # Vendor apps are permited to use only stable public services. If they were to use arbitrary
618*e4a36f41SAndroid Build Coastguard Worker  # services which can change any time framework/core is updated, breakage is likely.
619*e4a36f41SAndroid Build Coastguard Worker  #
620*e4a36f41SAndroid Build Coastguard Worker  # Note, this same logic applies to untrusted apps, but neverallows for these are separate.
621*e4a36f41SAndroid Build Coastguard Worker  neverallow {
622*e4a36f41SAndroid Build Coastguard Worker    appdomain
623*e4a36f41SAndroid Build Coastguard Worker    -coredomain
624*e4a36f41SAndroid Build Coastguard Worker  } {
625*e4a36f41SAndroid Build Coastguard Worker    service_manager_type
626*e4a36f41SAndroid Build Coastguard Worker
627*e4a36f41SAndroid Build Coastguard Worker    -app_api_service
628*e4a36f41SAndroid Build Coastguard Worker    -ephemeral_app_api_service
629*e4a36f41SAndroid Build Coastguard Worker
630*e4a36f41SAndroid Build Coastguard Worker    -hal_service_type # see app_neverallows.te
631*e4a36f41SAndroid Build Coastguard Worker
632*e4a36f41SAndroid Build Coastguard Worker    -apc_service
633*e4a36f41SAndroid Build Coastguard Worker    -audioserver_service # TODO(b/36783122) remove exemptions below once app_api_service is fixed
634*e4a36f41SAndroid Build Coastguard Worker    -cameraserver_service
635*e4a36f41SAndroid Build Coastguard Worker    -drmserver_service
636*e4a36f41SAndroid Build Coastguard Worker    -credstore_service
637*e4a36f41SAndroid Build Coastguard Worker    -keystore_maintenance_service
638*e4a36f41SAndroid Build Coastguard Worker    -keystore_service
639*e4a36f41SAndroid Build Coastguard Worker    -legacykeystore_service
640*e4a36f41SAndroid Build Coastguard Worker    -mediadrmserver_service
641*e4a36f41SAndroid Build Coastguard Worker    -mediaextractor_service
642*e4a36f41SAndroid Build Coastguard Worker    -mediametrics_service
643*e4a36f41SAndroid Build Coastguard Worker    -mediaserver_service
644*e4a36f41SAndroid Build Coastguard Worker    -nfc_service
645*e4a36f41SAndroid Build Coastguard Worker    -radio_service
646*e4a36f41SAndroid Build Coastguard Worker    -virtual_touchpad_service
647*e4a36f41SAndroid Build Coastguard Worker    -vr_manager_service
648*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-hal_face_service')
649*e4a36f41SAndroid Build Coastguard Worker  }:service_manager find;
650*e4a36f41SAndroid Build Coastguard Worker')
651*e4a36f41SAndroid Build Coastguard Worker
652*e4a36f41SAndroid Build Coastguard Worker# On full TREBLE devices, only vendor components, shell, and su can use VendorBinder.
653*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
654*e4a36f41SAndroid Build Coastguard Worker  neverallow {
655*e4a36f41SAndroid Build Coastguard Worker    coredomain
656*e4a36f41SAndroid Build Coastguard Worker    -shell
657*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-su')
658*e4a36f41SAndroid Build Coastguard Worker    -ueventd # uevent is granted create for this device, but we still neverallow I/O below
659*e4a36f41SAndroid Build Coastguard Worker  } vndbinder_device:chr_file rw_file_perms;
660*e4a36f41SAndroid Build Coastguard Worker')
661*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
662*e4a36f41SAndroid Build Coastguard Worker  neverallow ueventd vndbinder_device:chr_file { read write append ioctl };
663*e4a36f41SAndroid Build Coastguard Worker')
664*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
665*e4a36f41SAndroid Build Coastguard Worker  neverallow {
666*e4a36f41SAndroid Build Coastguard Worker    coredomain
667*e4a36f41SAndroid Build Coastguard Worker    -shell
668*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-su')
669*e4a36f41SAndroid Build Coastguard Worker  } vndservice_manager_type:service_manager *;
670*e4a36f41SAndroid Build Coastguard Worker')
671*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
672*e4a36f41SAndroid Build Coastguard Worker  neverallow {
673*e4a36f41SAndroid Build Coastguard Worker    coredomain
674*e4a36f41SAndroid Build Coastguard Worker    -shell
675*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-su')
676*e4a36f41SAndroid Build Coastguard Worker  } vndservicemanager:binder *;
677*e4a36f41SAndroid Build Coastguard Worker')
678*e4a36f41SAndroid Build Coastguard Worker
679*e4a36f41SAndroid Build Coastguard Worker# On full TREBLE devices, socket communications between core components and vendor components are
680*e4a36f41SAndroid Build Coastguard Worker# not permitted.
681*e4a36f41SAndroid Build Coastguard Worker  # Most general rules first, more specific rules below.
682*e4a36f41SAndroid Build Coastguard Worker
683*e4a36f41SAndroid Build Coastguard Worker  # Core domains are not permitted to initiate communications to vendor domain sockets.
684*e4a36f41SAndroid Build Coastguard Worker  # We are not restricting the use of already established sockets because it is fine for a process
685*e4a36f41SAndroid Build Coastguard Worker  # to obtain an already established socket via some public/official/stable API and then exchange
686*e4a36f41SAndroid Build Coastguard Worker  # data with its peer over that socket. The wire format in this scenario is dicatated by the API
687*e4a36f41SAndroid Build Coastguard Worker  # and thus does not break the core-vendor separation.
688*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
689*e4a36f41SAndroid Build Coastguard Worker  neverallow_establish_socket_comms({
690*e4a36f41SAndroid Build Coastguard Worker    coredomain
691*e4a36f41SAndroid Build Coastguard Worker    -init
692*e4a36f41SAndroid Build Coastguard Worker    -adbd
693*e4a36f41SAndroid Build Coastguard Worker  }, {
694*e4a36f41SAndroid Build Coastguard Worker    domain
695*e4a36f41SAndroid Build Coastguard Worker    -coredomain
696*e4a36f41SAndroid Build Coastguard Worker    -socket_between_core_and_vendor_violators
697*e4a36f41SAndroid Build Coastguard Worker  });
698*e4a36f41SAndroid Build Coastguard Worker')
699*e4a36f41SAndroid Build Coastguard Worker
700*e4a36f41SAndroid Build Coastguard Worker  # Vendor domains are not permitted to initiate create/open sockets owned by core domains
701*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
702*e4a36f41SAndroid Build Coastguard Worker  neverallow {
703*e4a36f41SAndroid Build Coastguard Worker    domain
704*e4a36f41SAndroid Build Coastguard Worker    -coredomain
705*e4a36f41SAndroid Build Coastguard Worker    -appdomain # appdomain restrictions below
706*e4a36f41SAndroid Build Coastguard Worker    -data_between_core_and_vendor_violators # b/70393317
707*e4a36f41SAndroid Build Coastguard Worker    -socket_between_core_and_vendor_violators
708*e4a36f41SAndroid Build Coastguard Worker    -vendor_init
709*e4a36f41SAndroid Build Coastguard Worker  } {
710*e4a36f41SAndroid Build Coastguard Worker    coredomain_socket
711*e4a36f41SAndroid Build Coastguard Worker    core_data_file_type
712*e4a36f41SAndroid Build Coastguard Worker    unlabeled # used only by core domains
713*e4a36f41SAndroid Build Coastguard Worker  }:sock_file ~{ append getattr ioctl read write };
714*e4a36f41SAndroid Build Coastguard Worker')
715*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
716*e4a36f41SAndroid Build Coastguard Worker  neverallow {
717*e4a36f41SAndroid Build Coastguard Worker    appdomain
718*e4a36f41SAndroid Build Coastguard Worker    -coredomain
719*e4a36f41SAndroid Build Coastguard Worker  } {
720*e4a36f41SAndroid Build Coastguard Worker    coredomain_socket
721*e4a36f41SAndroid Build Coastguard Worker    unlabeled # used only by core domains
722*e4a36f41SAndroid Build Coastguard Worker    core_data_file_type
723*e4a36f41SAndroid Build Coastguard Worker    -app_data_file
724*e4a36f41SAndroid Build Coastguard Worker    -privapp_data_file
725*e4a36f41SAndroid Build Coastguard Worker    -pdx_endpoint_socket_type # used by VR layer
726*e4a36f41SAndroid Build Coastguard Worker    -pdx_channel_socket_type # used by VR layer
727*e4a36f41SAndroid Build Coastguard Worker  }:sock_file ~{ append getattr ioctl read write };
728*e4a36f41SAndroid Build Coastguard Worker')
729*e4a36f41SAndroid Build Coastguard Worker
730*e4a36f41SAndroid Build Coastguard Worker  # Core domains are not permitted to create/open sockets owned by vendor domains
731*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
732*e4a36f41SAndroid Build Coastguard Worker  neverallow {
733*e4a36f41SAndroid Build Coastguard Worker    coredomain
734*e4a36f41SAndroid Build Coastguard Worker    -init
735*e4a36f41SAndroid Build Coastguard Worker    -ueventd
736*e4a36f41SAndroid Build Coastguard Worker    -socket_between_core_and_vendor_violators
737*e4a36f41SAndroid Build Coastguard Worker  } {
738*e4a36f41SAndroid Build Coastguard Worker    file_type
739*e4a36f41SAndroid Build Coastguard Worker    dev_type
740*e4a36f41SAndroid Build Coastguard Worker    -coredomain_socket
741*e4a36f41SAndroid Build Coastguard Worker    -core_data_file_type
742*e4a36f41SAndroid Build Coastguard Worker    -app_data_file_type
743*e4a36f41SAndroid Build Coastguard Worker    -unlabeled
744*e4a36f41SAndroid Build Coastguard Worker  }:sock_file ~{ append getattr ioctl read write };
745*e4a36f41SAndroid Build Coastguard Worker')
746*e4a36f41SAndroid Build Coastguard Worker
747*e4a36f41SAndroid Build Coastguard Worker# On TREBLE devices, vendor and system components are only allowed to share
748*e4a36f41SAndroid Build Coastguard Worker# files by passing open FDs over hwbinder. Ban all directory access and all file
749*e4a36f41SAndroid Build Coastguard Worker# accesses other than what can be applied to an open FD such as
750*e4a36f41SAndroid Build Coastguard Worker# ioctl/stat/read/write/append. This is enforced by segregating /data.
751*e4a36f41SAndroid Build Coastguard Worker# Vendor domains may directly access file in /data/vendor by path, but may only
752*e4a36f41SAndroid Build Coastguard Worker# access files outside of /data/vendor via an open FD passed over hwbinder.
753*e4a36f41SAndroid Build Coastguard Worker# Likewise, core domains may only directly access files outside /data/vendor by
754*e4a36f41SAndroid Build Coastguard Worker# path and files in /data/vendor by open FD.
755*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
756*e4a36f41SAndroid Build Coastguard Worker  # only coredomains may only access core_data_file_type, particularly not
757*e4a36f41SAndroid Build Coastguard Worker  # /data/vendor
758*e4a36f41SAndroid Build Coastguard Worker  neverallow {
759*e4a36f41SAndroid Build Coastguard Worker    coredomain
760*e4a36f41SAndroid Build Coastguard Worker    -appdomain # TODO(b/34980020) remove exemption for appdomain
761*e4a36f41SAndroid Build Coastguard Worker    -data_between_core_and_vendor_violators
762*e4a36f41SAndroid Build Coastguard Worker    -init
763*e4a36f41SAndroid Build Coastguard Worker    -vold_prepare_subdirs
764*e4a36f41SAndroid Build Coastguard Worker  } {
765*e4a36f41SAndroid Build Coastguard Worker    data_file_type
766*e4a36f41SAndroid Build Coastguard Worker    -core_data_file_type
767*e4a36f41SAndroid Build Coastguard Worker    -app_data_file_type
768*e4a36f41SAndroid Build Coastguard Worker  }:file_class_set ~{ append getattr ioctl read write map };
769*e4a36f41SAndroid Build Coastguard Worker')
770*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
771*e4a36f41SAndroid Build Coastguard Worker  neverallow {
772*e4a36f41SAndroid Build Coastguard Worker    coredomain
773*e4a36f41SAndroid Build Coastguard Worker    -appdomain # TODO(b/34980020) remove exemption for appdomain
774*e4a36f41SAndroid Build Coastguard Worker    -data_between_core_and_vendor_violators
775*e4a36f41SAndroid Build Coastguard Worker    -init
776*e4a36f41SAndroid Build Coastguard Worker    -vold_prepare_subdirs
777*e4a36f41SAndroid Build Coastguard Worker    } {
778*e4a36f41SAndroid Build Coastguard Worker      data_file_type
779*e4a36f41SAndroid Build Coastguard Worker      -core_data_file_type
780*e4a36f41SAndroid Build Coastguard Worker      -app_data_file_type
781*e4a36f41SAndroid Build Coastguard Worker      # TODO(b/72998741) Remove exemption. Further restricted in a subsequent
782*e4a36f41SAndroid Build Coastguard Worker      # neverallow. Currently only getattr and search are allowed.
783*e4a36f41SAndroid Build Coastguard Worker      -vendor_data_file
784*e4a36f41SAndroid Build Coastguard Worker    }:dir *;
785*e4a36f41SAndroid Build Coastguard Worker
786*e4a36f41SAndroid Build Coastguard Worker')
787*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
788*e4a36f41SAndroid Build Coastguard Worker  # vendor domains may only access files in /data/vendor, never core_data_file_types
789*e4a36f41SAndroid Build Coastguard Worker  neverallow {
790*e4a36f41SAndroid Build Coastguard Worker    domain
791*e4a36f41SAndroid Build Coastguard Worker    -appdomain # TODO(b/34980020) remove exemption for appdomain
792*e4a36f41SAndroid Build Coastguard Worker    -coredomain
793*e4a36f41SAndroid Build Coastguard Worker    -data_between_core_and_vendor_violators # TODO(b/34980020) Remove once all violators have been cleaned up
794*e4a36f41SAndroid Build Coastguard Worker    -vendor_init
795*e4a36f41SAndroid Build Coastguard Worker  } {
796*e4a36f41SAndroid Build Coastguard Worker    core_data_file_type
797*e4a36f41SAndroid Build Coastguard Worker    with_native_coverage(`-method_trace_data_file')
798*e4a36f41SAndroid Build Coastguard Worker  }:file_class_set ~{ append getattr ioctl read write map };
799*e4a36f41SAndroid Build Coastguard Worker  neverallow {
800*e4a36f41SAndroid Build Coastguard Worker    vendor_init
801*e4a36f41SAndroid Build Coastguard Worker    -data_between_core_and_vendor_violators
802*e4a36f41SAndroid Build Coastguard Worker  } {
803*e4a36f41SAndroid Build Coastguard Worker    core_data_file_type
804*e4a36f41SAndroid Build Coastguard Worker    -unencrypted_data_file
805*e4a36f41SAndroid Build Coastguard Worker    with_native_coverage(`-method_trace_data_file')
806*e4a36f41SAndroid Build Coastguard Worker  }:file_class_set ~{ append getattr ioctl read write map };
807*e4a36f41SAndroid Build Coastguard Worker  # vendor init needs to be able to read unencrypted_data_file to create directories with FBE.
808*e4a36f41SAndroid Build Coastguard Worker  # The vendor init binary lives on the system partition so there is not a concern with stability.
809*e4a36f41SAndroid Build Coastguard Worker  neverallow vendor_init unencrypted_data_file:file ~r_file_perms;
810*e4a36f41SAndroid Build Coastguard Worker')
811*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
812*e4a36f41SAndroid Build Coastguard Worker  # vendor domains may only access dirs in /data/vendor, never core_data_file_types
813*e4a36f41SAndroid Build Coastguard Worker  neverallow {
814*e4a36f41SAndroid Build Coastguard Worker    domain
815*e4a36f41SAndroid Build Coastguard Worker    -appdomain # TODO(b/34980020) remove exemption for appdomain
816*e4a36f41SAndroid Build Coastguard Worker    -coredomain
817*e4a36f41SAndroid Build Coastguard Worker    -data_between_core_and_vendor_violators
818*e4a36f41SAndroid Build Coastguard Worker    -vendor_init
819*e4a36f41SAndroid Build Coastguard Worker  } {
820*e4a36f41SAndroid Build Coastguard Worker    core_data_file_type
821*e4a36f41SAndroid Build Coastguard Worker    -system_data_file # default label for files on /data. Covered below...
822*e4a36f41SAndroid Build Coastguard Worker    -system_data_root_file
823*e4a36f41SAndroid Build Coastguard Worker    -vendor_userdir_file
824*e4a36f41SAndroid Build Coastguard Worker    -vendor_data_file
825*e4a36f41SAndroid Build Coastguard Worker    with_native_coverage(`-method_trace_data_file')
826*e4a36f41SAndroid Build Coastguard Worker  }:dir *;
827*e4a36f41SAndroid Build Coastguard Worker  neverallow {
828*e4a36f41SAndroid Build Coastguard Worker    vendor_init
829*e4a36f41SAndroid Build Coastguard Worker    -data_between_core_and_vendor_violators
830*e4a36f41SAndroid Build Coastguard Worker  } {
831*e4a36f41SAndroid Build Coastguard Worker    core_data_file_type
832*e4a36f41SAndroid Build Coastguard Worker    -unencrypted_data_file
833*e4a36f41SAndroid Build Coastguard Worker    -system_data_file
834*e4a36f41SAndroid Build Coastguard Worker    -system_data_root_file
835*e4a36f41SAndroid Build Coastguard Worker    -vendor_userdir_file
836*e4a36f41SAndroid Build Coastguard Worker    -vendor_data_file
837*e4a36f41SAndroid Build Coastguard Worker    with_native_coverage(`-method_trace_data_file')
838*e4a36f41SAndroid Build Coastguard Worker  }:dir *;
839*e4a36f41SAndroid Build Coastguard Worker  # vendor init needs to be able to read unencrypted_data_file to create directories with FBE.
840*e4a36f41SAndroid Build Coastguard Worker  # The vendor init binary lives on the system partition so there is not a concern with stability.
841*e4a36f41SAndroid Build Coastguard Worker  neverallow vendor_init unencrypted_data_file:dir ~search;
842*e4a36f41SAndroid Build Coastguard Worker')
843*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
844*e4a36f41SAndroid Build Coastguard Worker  # vendor domains may only access dirs in /data/vendor, never core_data_file_types
845*e4a36f41SAndroid Build Coastguard Worker  neverallow {
846*e4a36f41SAndroid Build Coastguard Worker    domain
847*e4a36f41SAndroid Build Coastguard Worker    -appdomain # TODO(b/34980020) remove exemption for appdomain
848*e4a36f41SAndroid Build Coastguard Worker    -coredomain
849*e4a36f41SAndroid Build Coastguard Worker    -data_between_core_and_vendor_violators # TODO(b/34980020) Remove once all violators have been cleaned up
850*e4a36f41SAndroid Build Coastguard Worker    } {
851*e4a36f41SAndroid Build Coastguard Worker      system_data_file # default label for files on /data. Covered below
852*e4a36f41SAndroid Build Coastguard Worker    }:dir ~{ getattr search };
853*e4a36f41SAndroid Build Coastguard Worker')
854*e4a36f41SAndroid Build Coastguard Worker
855*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
856*e4a36f41SAndroid Build Coastguard Worker  #  coredomains may not access dirs in /data/vendor.
857*e4a36f41SAndroid Build Coastguard Worker  neverallow {
858*e4a36f41SAndroid Build Coastguard Worker    coredomain
859*e4a36f41SAndroid Build Coastguard Worker    -data_between_core_and_vendor_violators # TODO(b/34980020) Remove once all violators have been cleaned up
860*e4a36f41SAndroid Build Coastguard Worker    -init
861*e4a36f41SAndroid Build Coastguard Worker    -vold # vold creates per-user storage for both system and vendor
862*e4a36f41SAndroid Build Coastguard Worker    -vold_prepare_subdirs
863*e4a36f41SAndroid Build Coastguard Worker    } {
864*e4a36f41SAndroid Build Coastguard Worker      vendor_data_file # default label for files on /data. Covered below
865*e4a36f41SAndroid Build Coastguard Worker    }:dir ~{ getattr search };
866*e4a36f41SAndroid Build Coastguard Worker')
867*e4a36f41SAndroid Build Coastguard Worker
868*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
869*e4a36f41SAndroid Build Coastguard Worker  #  coredomains may not access dirs in /data/vendor.
870*e4a36f41SAndroid Build Coastguard Worker  neverallow {
871*e4a36f41SAndroid Build Coastguard Worker    coredomain
872*e4a36f41SAndroid Build Coastguard Worker    -data_between_core_and_vendor_violators # TODO(b/34980020) Remove once all violators have been cleaned up
873*e4a36f41SAndroid Build Coastguard Worker    -init
874*e4a36f41SAndroid Build Coastguard Worker    } {
875*e4a36f41SAndroid Build Coastguard Worker      vendor_data_file # default label for files on /data/vendor{,_ce,_de}.
876*e4a36f41SAndroid Build Coastguard Worker    }:file_class_set ~{ append getattr ioctl read write map };
877*e4a36f41SAndroid Build Coastguard Worker')
878*e4a36f41SAndroid Build Coastguard Worker
879*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
880*e4a36f41SAndroid Build Coastguard Worker    # Non-vendor domains are not allowed to file execute shell
881*e4a36f41SAndroid Build Coastguard Worker    # from vendor
882*e4a36f41SAndroid Build Coastguard Worker    neverallow {
883*e4a36f41SAndroid Build Coastguard Worker        coredomain
884*e4a36f41SAndroid Build Coastguard Worker        -init
885*e4a36f41SAndroid Build Coastguard Worker        -shell
886*e4a36f41SAndroid Build Coastguard Worker        -ueventd
887*e4a36f41SAndroid Build Coastguard Worker    } vendor_shell_exec:file { execute execute_no_trans };
888*e4a36f41SAndroid Build Coastguard Worker')
889*e4a36f41SAndroid Build Coastguard Worker
890*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
891*e4a36f41SAndroid Build Coastguard Worker    # Do not allow vendor components to execute files from system
892*e4a36f41SAndroid Build Coastguard Worker    # except for the ones allowed here.
893*e4a36f41SAndroid Build Coastguard Worker    neverallow {
894*e4a36f41SAndroid Build Coastguard Worker        domain
895*e4a36f41SAndroid Build Coastguard Worker        -coredomain
896*e4a36f41SAndroid Build Coastguard Worker        -appdomain
897*e4a36f41SAndroid Build Coastguard Worker        -vendor_executes_system_violators
898*e4a36f41SAndroid Build Coastguard Worker        -vendor_init
899*e4a36f41SAndroid Build Coastguard Worker    } {
900*e4a36f41SAndroid Build Coastguard Worker        system_file_type
901*e4a36f41SAndroid Build Coastguard Worker        -system_lib_file
902*e4a36f41SAndroid Build Coastguard Worker        -system_linker_exec
903*e4a36f41SAndroid Build Coastguard Worker        -crash_dump_exec
904*e4a36f41SAndroid Build Coastguard Worker        -netutils_wrapper_exec
905*e4a36f41SAndroid Build Coastguard Worker        userdebug_or_eng(`-tcpdump_exec')
906*e4a36f41SAndroid Build Coastguard Worker        # Vendor components still can invoke shell commands via /system/bin/sh
907*e4a36f41SAndroid Build Coastguard Worker        -shell_exec
908*e4a36f41SAndroid Build Coastguard Worker        -toolbox_exec
909*e4a36f41SAndroid Build Coastguard Worker    }:file { entrypoint execute execute_no_trans };
910*e4a36f41SAndroid Build Coastguard Worker')
911*e4a36f41SAndroid Build Coastguard Worker
912*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
913*e4a36f41SAndroid Build Coastguard Worker    # Do not allow coredomain to access entrypoint for files other
914*e4a36f41SAndroid Build Coastguard Worker    # than system_file_type and postinstall_file
915*e4a36f41SAndroid Build Coastguard Worker    neverallow coredomain {
916*e4a36f41SAndroid Build Coastguard Worker        file_type
917*e4a36f41SAndroid Build Coastguard Worker        -system_file_type
918*e4a36f41SAndroid Build Coastguard Worker        -postinstall_file
919*e4a36f41SAndroid Build Coastguard Worker    }:file entrypoint;
920*e4a36f41SAndroid Build Coastguard Worker    # Do not allow domains other than coredomain to access entrypoint
921*e4a36f41SAndroid Build Coastguard Worker    # for anything but vendor_file_type and init_exec for vendor_init.
922*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -coredomain } {
923*e4a36f41SAndroid Build Coastguard Worker        file_type
924*e4a36f41SAndroid Build Coastguard Worker        -vendor_file_type
925*e4a36f41SAndroid Build Coastguard Worker        -init_exec
926*e4a36f41SAndroid Build Coastguard Worker    }:file entrypoint;
927*e4a36f41SAndroid Build Coastguard Worker')
928*e4a36f41SAndroid Build Coastguard Worker
929*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
930*e4a36f41SAndroid Build Coastguard Worker    # Do not allow system components to execute files from vendor
931*e4a36f41SAndroid Build Coastguard Worker    # except for the ones allowed here.
932*e4a36f41SAndroid Build Coastguard Worker    neverallow {
933*e4a36f41SAndroid Build Coastguard Worker      coredomain
934*e4a36f41SAndroid Build Coastguard Worker      -init
935*e4a36f41SAndroid Build Coastguard Worker      -shell
936*e4a36f41SAndroid Build Coastguard Worker      -system_executes_vendor_violators
937*e4a36f41SAndroid Build Coastguard Worker      -ueventd
938*e4a36f41SAndroid Build Coastguard Worker    } {
939*e4a36f41SAndroid Build Coastguard Worker      vendor_file_type
940*e4a36f41SAndroid Build Coastguard Worker      -same_process_hal_file
941*e4a36f41SAndroid Build Coastguard Worker      -vndk_sp_file
942*e4a36f41SAndroid Build Coastguard Worker      -vendor_app_file
943*e4a36f41SAndroid Build Coastguard Worker      -vendor_public_framework_file
944*e4a36f41SAndroid Build Coastguard Worker      -vendor_public_lib_file
945*e4a36f41SAndroid Build Coastguard Worker    }:file execute;
946*e4a36f41SAndroid Build Coastguard Worker')
947*e4a36f41SAndroid Build Coastguard Worker
948*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
949*e4a36f41SAndroid Build Coastguard Worker    neverallow {
950*e4a36f41SAndroid Build Coastguard Worker      coredomain
951*e4a36f41SAndroid Build Coastguard Worker      -shell
952*e4a36f41SAndroid Build Coastguard Worker      -system_executes_vendor_violators
953*e4a36f41SAndroid Build Coastguard Worker    } {
954*e4a36f41SAndroid Build Coastguard Worker      vendor_file_type
955*e4a36f41SAndroid Build Coastguard Worker      -same_process_hal_file
956*e4a36f41SAndroid Build Coastguard Worker    }:file execute_no_trans;
957*e4a36f41SAndroid Build Coastguard Worker')
958*e4a36f41SAndroid Build Coastguard Worker
959*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
960*e4a36f41SAndroid Build Coastguard Worker  # Do not allow vendor components access to /system files except for the
961*e4a36f41SAndroid Build Coastguard Worker  # ones allowed here.
962*e4a36f41SAndroid Build Coastguard Worker  neverallow {
963*e4a36f41SAndroid Build Coastguard Worker    domain
964*e4a36f41SAndroid Build Coastguard Worker    -appdomain
965*e4a36f41SAndroid Build Coastguard Worker    -coredomain
966*e4a36f41SAndroid Build Coastguard Worker    -vendor_executes_system_violators
967*e4a36f41SAndroid Build Coastguard Worker    # vendor_init needs access to init_exec for domain transition. vendor_init
968*e4a36f41SAndroid Build Coastguard Worker    # neverallows are covered in public/vendor_init.te
969*e4a36f41SAndroid Build Coastguard Worker    -vendor_init
970*e4a36f41SAndroid Build Coastguard Worker  } {
971*e4a36f41SAndroid Build Coastguard Worker    system_file_type
972*e4a36f41SAndroid Build Coastguard Worker    -crash_dump_exec
973*e4a36f41SAndroid Build Coastguard Worker    -file_contexts_file
974*e4a36f41SAndroid Build Coastguard Worker    -netutils_wrapper_exec
975*e4a36f41SAndroid Build Coastguard Worker    -property_contexts_file
976*e4a36f41SAndroid Build Coastguard Worker    -system_event_log_tags_file
977*e4a36f41SAndroid Build Coastguard Worker    -system_group_file
978*e4a36f41SAndroid Build Coastguard Worker    -system_lib_file
979*e4a36f41SAndroid Build Coastguard Worker    with_asan(`-system_asan_options_file')
980*e4a36f41SAndroid Build Coastguard Worker    -system_linker_exec
981*e4a36f41SAndroid Build Coastguard Worker    -system_linker_config_file
982*e4a36f41SAndroid Build Coastguard Worker    -system_passwd_file
983*e4a36f41SAndroid Build Coastguard Worker    -system_seccomp_policy_file
984*e4a36f41SAndroid Build Coastguard Worker    -system_security_cacerts_file
985*e4a36f41SAndroid Build Coastguard Worker    -system_zoneinfo_file
986*e4a36f41SAndroid Build Coastguard Worker    -task_profiles_api_file
987*e4a36f41SAndroid Build Coastguard Worker    -task_profiles_file
988*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-tcpdump_exec')
989*e4a36f41SAndroid Build Coastguard Worker    # Vendor components still can invoke shell commands via /system/bin/sh
990*e4a36f41SAndroid Build Coastguard Worker    -shell_exec
991*e4a36f41SAndroid Build Coastguard Worker    -toolbox_exec
992*e4a36f41SAndroid Build Coastguard Worker  }:file *;
993*e4a36f41SAndroid Build Coastguard Worker')
994*e4a36f41SAndroid Build Coastguard Worker
995*e4a36f41SAndroid Build Coastguard Worker# Only system_server should be able to send commands via the zygote socket
996*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -zygote -system_server } zygote:unix_stream_socket connectto;
997*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server } zygote_socket:sock_file write;
998*e4a36f41SAndroid Build Coastguard Worker
999*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server -webview_zygote -app_zygote } webview_zygote:unix_stream_socket connectto;
1000*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server } webview_zygote:sock_file write;
1001*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server } app_zygote:sock_file write;
1002*e4a36f41SAndroid Build Coastguard Worker
1003*e4a36f41SAndroid Build Coastguard Workerneverallow domain tombstoned_crash_socket:unix_stream_socket connectto;
1004*e4a36f41SAndroid Build Coastguard Worker
1005*e4a36f41SAndroid Build Coastguard Worker# Never allow anyone except dumpstate, incidentd, or the system server to connect or write to
1006*e4a36f41SAndroid Build Coastguard Worker# the tombstoned intercept socket.
1007*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -dumpstate -incidentd -system_server } tombstoned_intercept_socket:sock_file write;
1008*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -dumpstate -incidentd -system_server } tombstoned_intercept_socket:unix_stream_socket connectto;
1009*e4a36f41SAndroid Build Coastguard Worker
1010*e4a36f41SAndroid Build Coastguard Worker# Never allow anyone but system_server to read heapdumps in /data/system/heapdump.
1011*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server } heapdump_data_file:file read;
1012*e4a36f41SAndroid Build Coastguard Worker
1013*e4a36f41SAndroid Build Coastguard Worker# Android does not support System V IPCs.
1014*e4a36f41SAndroid Build Coastguard Worker#
1015*e4a36f41SAndroid Build Coastguard Worker# The reason for this is due to the fact that, by design, they lead to global
1016*e4a36f41SAndroid Build Coastguard Worker# kernel resource leakage.
1017*e4a36f41SAndroid Build Coastguard Worker#
1018*e4a36f41SAndroid Build Coastguard Worker# For example, there is no way to automatically release a SysV semaphore
1019*e4a36f41SAndroid Build Coastguard Worker# allocated in the kernel when:
1020*e4a36f41SAndroid Build Coastguard Worker#
1021*e4a36f41SAndroid Build Coastguard Worker# - a buggy or malicious process exits
1022*e4a36f41SAndroid Build Coastguard Worker# - a non-buggy and non-malicious process crashes or is explicitly killed.
1023*e4a36f41SAndroid Build Coastguard Worker#
1024*e4a36f41SAndroid Build Coastguard Worker# Killing processes automatically to make room for new ones is an
1025*e4a36f41SAndroid Build Coastguard Worker# important part of Android's application lifecycle implementation. This means
1026*e4a36f41SAndroid Build Coastguard Worker# that, even assuming only non-buggy and non-malicious code, it is very likely
1027*e4a36f41SAndroid Build Coastguard Worker# that over time, the kernel global tables used to implement SysV IPCs will fill
1028*e4a36f41SAndroid Build Coastguard Worker# up.
1029*e4a36f41SAndroid Build Coastguard Workerneverallow * *:{ shm sem msg msgq } *;
1030*e4a36f41SAndroid Build Coastguard Worker
1031*e4a36f41SAndroid Build Coastguard Worker# Do not mount on top of symlinks, fifos, or sockets.
1032*e4a36f41SAndroid Build Coastguard Worker# Feature parity with Chromium LSM.
1033*e4a36f41SAndroid Build Coastguard Workerneverallow * { file_type fs_type dev_type }:{ lnk_file fifo_file sock_file } mounton;
1034*e4a36f41SAndroid Build Coastguard Worker
1035*e4a36f41SAndroid Build Coastguard Worker# Nobody should be able to execute su on user builds.
1036*e4a36f41SAndroid Build Coastguard Worker# On userdebug/eng builds, only dumpstate, shell, and
1037*e4a36f41SAndroid Build Coastguard Worker# su itself execute su.
1038*e4a36f41SAndroid Build Coastguard Workerneverallow { domain userdebug_or_eng(`-dumpstate -shell -su') } su_exec:file no_x_file_perms;
1039*e4a36f41SAndroid Build Coastguard Worker
1040*e4a36f41SAndroid Build Coastguard Worker# Do not allow the introduction of new execmod rules. Text relocations
1041*e4a36f41SAndroid Build Coastguard Worker# and modification of executable pages are unsafe.
1042*e4a36f41SAndroid Build Coastguard Worker# The only exceptions are for NDK text relocations associated with
1043*e4a36f41SAndroid Build Coastguard Worker# https://code.google.com/p/android/issues/detail?id=23203
1044*e4a36f41SAndroid Build Coastguard Worker# which, long term, need to go away.
1045*e4a36f41SAndroid Build Coastguard Workerneverallow * {
1046*e4a36f41SAndroid Build Coastguard Worker  file_type
1047*e4a36f41SAndroid Build Coastguard Worker  -apk_data_file
1048*e4a36f41SAndroid Build Coastguard Worker  -app_data_file
1049*e4a36f41SAndroid Build Coastguard Worker  -asec_public_file
1050*e4a36f41SAndroid Build Coastguard Worker}:file execmod;
1051*e4a36f41SAndroid Build Coastguard Worker
1052*e4a36f41SAndroid Build Coastguard Worker# Do not allow making the stack or heap executable.
1053*e4a36f41SAndroid Build Coastguard Worker# We would also like to minimize execmem but it seems to be
1054*e4a36f41SAndroid Build Coastguard Worker# required by some device-specific service domains.
1055*e4a36f41SAndroid Build Coastguard Workerneverallow * self:process { execstack execheap };
1056*e4a36f41SAndroid Build Coastguard Worker
1057*e4a36f41SAndroid Build Coastguard Worker# Do not allow the introduction of new execmod rules. Text relocations
1058*e4a36f41SAndroid Build Coastguard Worker# and modification of executable pages are unsafe.
1059*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -untrusted_app_25 -untrusted_app_27 } file_type:file execmod;
1060*e4a36f41SAndroid Build Coastguard Worker
1061*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } proc:{ file dir } mounton;
1062*e4a36f41SAndroid Build Coastguard Worker
1063*e4a36f41SAndroid Build Coastguard Worker# Ensure that all types assigned to processes are included
1064*e4a36f41SAndroid Build Coastguard Worker# in the domain attribute, so that all allow and neverallow rules
1065*e4a36f41SAndroid Build Coastguard Worker# written on domain are applied to all processes.
1066*e4a36f41SAndroid Build Coastguard Worker# This is achieved by ensuring that it is impossible to transition
1067*e4a36f41SAndroid Build Coastguard Worker# from a domain to a non-domain type and vice versa.
1068*e4a36f41SAndroid Build Coastguard Worker# TODO - rework this: neverallow domain ~domain:process { transition dyntransition };
1069*e4a36f41SAndroid Build Coastguard Workerneverallow ~domain domain:process { transition dyntransition };
1070*e4a36f41SAndroid Build Coastguard Worker
1071*e4a36f41SAndroid Build Coastguard Worker#
1072*e4a36f41SAndroid Build Coastguard Worker# Only system_app and system_server should be creating or writing
1073*e4a36f41SAndroid Build Coastguard Worker# their files. The proper way to share files is to setup
1074*e4a36f41SAndroid Build Coastguard Worker# type transitions to a more specific type or assigning a type
1075*e4a36f41SAndroid Build Coastguard Worker# to its parent directory via a file_contexts entry.
1076*e4a36f41SAndroid Build Coastguard Worker# Example type transition:
1077*e4a36f41SAndroid Build Coastguard Worker#  mydomain.te:file_type_auto_trans(mydomain, system_data_file, new_file_type)
1078*e4a36f41SAndroid Build Coastguard Worker#
1079*e4a36f41SAndroid Build Coastguard Workerneverallow {
1080*e4a36f41SAndroid Build Coastguard Worker  domain
1081*e4a36f41SAndroid Build Coastguard Worker  -system_server
1082*e4a36f41SAndroid Build Coastguard Worker  -system_app
1083*e4a36f41SAndroid Build Coastguard Worker  -init
1084*e4a36f41SAndroid Build Coastguard Worker  -toolbox # TODO(b/141108496) We want to remove toolbox
1085*e4a36f41SAndroid Build Coastguard Worker  -installd # for relabelfrom and unlink, check for this in explicit neverallow
1086*e4a36f41SAndroid Build Coastguard Worker  -vold_prepare_subdirs # For unlink
1087*e4a36f41SAndroid Build Coastguard Worker  with_asan(`-asan_extract')
1088*e4a36f41SAndroid Build Coastguard Worker} system_data_file:file no_w_file_perms;
1089*e4a36f41SAndroid Build Coastguard Worker# do not grant anything greater than r_file_perms and relabelfrom unlink
1090*e4a36f41SAndroid Build Coastguard Worker# to installd
1091*e4a36f41SAndroid Build Coastguard Workerneverallow installd system_data_file:file ~{ r_file_perms relabelfrom unlink };
1092*e4a36f41SAndroid Build Coastguard Worker
1093*e4a36f41SAndroid Build Coastguard Worker#
1094*e4a36f41SAndroid Build Coastguard Worker# Only these domains should transition to shell domain. This domain is
1095*e4a36f41SAndroid Build Coastguard Worker# permissible for the "shell user". If you need a process to exec a shell
1096*e4a36f41SAndroid Build Coastguard Worker# script with differing privilege, define a domain and set up a transition.
1097*e4a36f41SAndroid Build Coastguard Worker#
1098*e4a36f41SAndroid Build Coastguard Workerneverallow {
1099*e4a36f41SAndroid Build Coastguard Worker  domain
1100*e4a36f41SAndroid Build Coastguard Worker  -adbd
1101*e4a36f41SAndroid Build Coastguard Worker  -init
1102*e4a36f41SAndroid Build Coastguard Worker  -runas
1103*e4a36f41SAndroid Build Coastguard Worker  -zygote
1104*e4a36f41SAndroid Build Coastguard Worker} shell:process { transition dyntransition };
1105*e4a36f41SAndroid Build Coastguard Worker
1106*e4a36f41SAndroid Build Coastguard Worker# Only domains spawned from zygote, runas and simpleperf_app_runner may have
1107*e4a36f41SAndroid Build Coastguard Worker# the appdomain attribute. simpleperf is excluded as a domain transitioned to
1108*e4a36f41SAndroid Build Coastguard Worker# when running an app-scoped profiling session.
1109*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -simpleperf_app_runner -runas -app_zygote -webview_zygote -zygote } {
1110*e4a36f41SAndroid Build Coastguard Worker  appdomain -shell -simpleperf userdebug_or_eng(`-su')
1111*e4a36f41SAndroid Build Coastguard Worker}:process { transition dyntransition };
1112*e4a36f41SAndroid Build Coastguard Worker
1113*e4a36f41SAndroid Build Coastguard Worker# Minimize read access to shell- or app-writable symlinks.
1114*e4a36f41SAndroid Build Coastguard Worker# This is to prevent malicious symlink attacks.
1115*e4a36f41SAndroid Build Coastguard Workerneverallow {
1116*e4a36f41SAndroid Build Coastguard Worker  domain
1117*e4a36f41SAndroid Build Coastguard Worker  -appdomain
1118*e4a36f41SAndroid Build Coastguard Worker  -artd
1119*e4a36f41SAndroid Build Coastguard Worker  -installd
1120*e4a36f41SAndroid Build Coastguard Worker} { app_data_file privapp_data_file }:lnk_file read;
1121*e4a36f41SAndroid Build Coastguard Worker
1122*e4a36f41SAndroid Build Coastguard Workerneverallow {
1123*e4a36f41SAndroid Build Coastguard Worker  domain
1124*e4a36f41SAndroid Build Coastguard Worker  -shell
1125*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-uncrypt')
1126*e4a36f41SAndroid Build Coastguard Worker  -installd
1127*e4a36f41SAndroid Build Coastguard Worker} shell_data_file:lnk_file read;
1128*e4a36f41SAndroid Build Coastguard Worker
1129*e4a36f41SAndroid Build Coastguard Worker# servicemanager and vndservicemanager are the only processes which handle the
1130*e4a36f41SAndroid Build Coastguard Worker# service_manager list request
1131*e4a36f41SAndroid Build Coastguard Workerneverallow * ~{
1132*e4a36f41SAndroid Build Coastguard Worker    servicemanager
1133*e4a36f41SAndroid Build Coastguard Worker    vndservicemanager
1134*e4a36f41SAndroid Build Coastguard Worker    }:service_manager list;
1135*e4a36f41SAndroid Build Coastguard Worker
1136*e4a36f41SAndroid Build Coastguard Worker# hwservicemanager is the only process which handles hw list requests
1137*e4a36f41SAndroid Build Coastguard Workerneverallow * ~{
1138*e4a36f41SAndroid Build Coastguard Worker    hwservicemanager
1139*e4a36f41SAndroid Build Coastguard Worker    }:hwservice_manager list;
1140*e4a36f41SAndroid Build Coastguard Worker
1141*e4a36f41SAndroid Build Coastguard Worker# only service_manager_types can be added to service_manager
1142*e4a36f41SAndroid Build Coastguard Worker# TODO - rework this: neverallow * ~service_manager_type:service_manager { add find };
1143*e4a36f41SAndroid Build Coastguard Worker
1144*e4a36f41SAndroid Build Coastguard Worker# Prevent assigning non property types to properties
1145*e4a36f41SAndroid Build Coastguard Worker# TODO - rework this: neverallow * ~property_type:property_service set;
1146*e4a36f41SAndroid Build Coastguard Worker
1147*e4a36f41SAndroid Build Coastguard Worker# Domain types should never be assigned to any files other
1148*e4a36f41SAndroid Build Coastguard Worker# than the /proc/pid files associated with a process. The
1149*e4a36f41SAndroid Build Coastguard Worker# executable file used to enter a domain should be labeled
1150*e4a36f41SAndroid Build Coastguard Worker# with its own _exec type, not with the domain type.
1151*e4a36f41SAndroid Build Coastguard Worker# Conventionally, this looks something like:
1152*e4a36f41SAndroid Build Coastguard Worker# $ cat mydaemon.te
1153*e4a36f41SAndroid Build Coastguard Worker# type mydaemon, domain;
1154*e4a36f41SAndroid Build Coastguard Worker# type mydaemon_exec, exec_type, file_type;
1155*e4a36f41SAndroid Build Coastguard Worker# init_daemon_domain(mydaemon)
1156*e4a36f41SAndroid Build Coastguard Worker# $ grep mydaemon file_contexts
1157*e4a36f41SAndroid Build Coastguard Worker# /system/bin/mydaemon -- u:object_r:mydaemon_exec:s0
1158*e4a36f41SAndroid Build Coastguard Workerneverallow * domain:file { execute execute_no_trans entrypoint };
1159*e4a36f41SAndroid Build Coastguard Worker
1160*e4a36f41SAndroid Build Coastguard Worker# Do not allow access to the generic debugfs label. This is too broad.
1161*e4a36f41SAndroid Build Coastguard Worker# Instead, if access to part of debugfs is desired, it should have a
1162*e4a36f41SAndroid Build Coastguard Worker# more specific label.
1163*e4a36f41SAndroid Build Coastguard Worker# TODO: fix dumpstate
1164*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -vendor_init -dumpstate } debugfs:{ file lnk_file } no_rw_file_perms;
1165*e4a36f41SAndroid Build Coastguard Worker
1166*e4a36f41SAndroid Build Coastguard Worker# Do not allow executable files in debugfs.
1167*e4a36f41SAndroid Build Coastguard Workerneverallow domain debugfs_type:file { execute execute_no_trans };
1168*e4a36f41SAndroid Build Coastguard Worker
1169*e4a36f41SAndroid Build Coastguard Worker# Don't allow access to the FUSE control filesystem, except to vold and init's
1170*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -vold -init -vendor_init } fusectlfs:file no_rw_file_perms;
1171*e4a36f41SAndroid Build Coastguard Worker
1172*e4a36f41SAndroid Build Coastguard Worker# Profiles contain untrusted data and profman parses that. We should only run
1173*e4a36f41SAndroid Build Coastguard Worker# it from installd and artd forked processes.
1174*e4a36f41SAndroid Build Coastguard Workerneverallow {
1175*e4a36f41SAndroid Build Coastguard Worker  domain
1176*e4a36f41SAndroid Build Coastguard Worker  -installd
1177*e4a36f41SAndroid Build Coastguard Worker  -profman
1178*e4a36f41SAndroid Build Coastguard Worker  -artd
1179*e4a36f41SAndroid Build Coastguard Worker} profman_exec:file no_x_file_perms;
1180*e4a36f41SAndroid Build Coastguard Worker
1181*e4a36f41SAndroid Build Coastguard Worker# Enforce restrictions on kernel module origin.
1182*e4a36f41SAndroid Build Coastguard Worker# Do not allow kernel module loading except from system,
1183*e4a36f41SAndroid Build Coastguard Worker# vendor, boot, and system_dlkm partitions.
1184*e4a36f41SAndroid Build Coastguard Worker# TODO(b/218951883): Remove usage of system and rootfs as origin
1185*e4a36f41SAndroid Build Coastguard Workerneverallow * ~{ system_file_type vendor_file_type rootfs system_dlkm_file_type }:system module_load;
1186*e4a36f41SAndroid Build Coastguard Worker
1187*e4a36f41SAndroid Build Coastguard Worker# Only allow filesystem caps to be set at build time. Runtime changes
1188*e4a36f41SAndroid Build Coastguard Worker# to filesystem capabilities are not permitted.
1189*e4a36f41SAndroid Build Coastguard Workerneverallow * self:global_capability_class_set setfcap;
1190*e4a36f41SAndroid Build Coastguard Worker
1191*e4a36f41SAndroid Build Coastguard Worker# Enforce AT_SECURE for executing crash_dump.
1192*e4a36f41SAndroid Build Coastguard Workerneverallow domain crash_dump:process noatsecure;
1193*e4a36f41SAndroid Build Coastguard Worker
1194*e4a36f41SAndroid Build Coastguard Worker# Do not permit non-core domains to register HwBinder services which are
1195*e4a36f41SAndroid Build Coastguard Worker# guaranteed to be provided by core domains only.
1196*e4a36f41SAndroid Build Coastguard Workerneverallow ~coredomain coredomain_hwservice:hwservice_manager add;
1197*e4a36f41SAndroid Build Coastguard Worker
1198*e4a36f41SAndroid Build Coastguard Worker# Do not permit the registeration of HwBinder services which are guaranteed to
1199*e4a36f41SAndroid Build Coastguard Worker# be passthrough only (i.e., run in the process of their clients instead of a
1200*e4a36f41SAndroid Build Coastguard Worker# separate server process).
1201*e4a36f41SAndroid Build Coastguard Workerneverallow * same_process_hwservice:hwservice_manager add;
1202*e4a36f41SAndroid Build Coastguard Worker
1203*e4a36f41SAndroid Build Coastguard Worker# If an already existing file is opened with O_CREAT, the kernel might generate
1204*e4a36f41SAndroid Build Coastguard Worker# a false report of a create denial. Silence these denials and make sure that
1205*e4a36f41SAndroid Build Coastguard Worker# inappropriate permissions are not granted.
1206*e4a36f41SAndroid Build Coastguard Worker
1207*e4a36f41SAndroid Build Coastguard Worker# These filesystems don't allow files or directories to be created, so the permission
1208*e4a36f41SAndroid Build Coastguard Worker# to do so should never be granted.
1209*e4a36f41SAndroid Build Coastguard Workerneverallow domain {
1210*e4a36f41SAndroid Build Coastguard Worker  proc_type
1211*e4a36f41SAndroid Build Coastguard Worker  sysfs_type
1212*e4a36f41SAndroid Build Coastguard Worker}:dir { add_name create link remove_name rename reparent rmdir write };
1213*e4a36f41SAndroid Build Coastguard Worker
1214*e4a36f41SAndroid Build Coastguard Worker# cgroupfs directories can be created, but not files within them.
1215*e4a36f41SAndroid Build Coastguard Workerneverallow domain cgroup:file create;
1216*e4a36f41SAndroid Build Coastguard Workerneverallow domain cgroup_v2:file create;
1217*e4a36f41SAndroid Build Coastguard Worker
1218*e4a36f41SAndroid Build Coastguard Workerdontaudit domain proc_type:dir write;
1219*e4a36f41SAndroid Build Coastguard Workerdontaudit domain sysfs_type:dir write;
1220*e4a36f41SAndroid Build Coastguard Workerdontaudit domain cgroup:file create;
1221*e4a36f41SAndroid Build Coastguard Workerdontaudit domain cgroup_v2:file create;
1222*e4a36f41SAndroid Build Coastguard Worker
1223*e4a36f41SAndroid Build Coastguard Worker# These are only needed in permissive mode - in enforcing mode the
1224*e4a36f41SAndroid Build Coastguard Worker# directory write check fails and so these are never attempted.
1225*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
1226*e4a36f41SAndroid Build Coastguard Worker  dontaudit domain proc_type:dir add_name;
1227*e4a36f41SAndroid Build Coastguard Worker  dontaudit domain sysfs_type:dir add_name;
1228*e4a36f41SAndroid Build Coastguard Worker  dontaudit domain proc_type:file create;
1229*e4a36f41SAndroid Build Coastguard Worker  dontaudit domain sysfs_type:file create;
1230*e4a36f41SAndroid Build Coastguard Worker')
1231*e4a36f41SAndroid Build Coastguard Worker
1232*e4a36f41SAndroid Build Coastguard Worker# Platform must not have access to /mnt/vendor.
1233*e4a36f41SAndroid Build Coastguard Workerneverallow {
1234*e4a36f41SAndroid Build Coastguard Worker  coredomain
1235*e4a36f41SAndroid Build Coastguard Worker  -init
1236*e4a36f41SAndroid Build Coastguard Worker  -ueventd
1237*e4a36f41SAndroid Build Coastguard Worker  -vold
1238*e4a36f41SAndroid Build Coastguard Worker  -system_writes_mnt_vendor_violators
1239*e4a36f41SAndroid Build Coastguard Worker} mnt_vendor_file:dir *;
1240*e4a36f41SAndroid Build Coastguard Worker
1241*e4a36f41SAndroid Build Coastguard Worker# Only apps are allowed access to vendor public libraries.
1242*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
1243*e4a36f41SAndroid Build Coastguard Worker  neverallow {
1244*e4a36f41SAndroid Build Coastguard Worker    coredomain
1245*e4a36f41SAndroid Build Coastguard Worker    -appdomain
1246*e4a36f41SAndroid Build Coastguard Worker  } {vendor_public_framework_file vendor_public_lib_file}:file { execute execute_no_trans };
1247*e4a36f41SAndroid Build Coastguard Worker')
1248*e4a36f41SAndroid Build Coastguard Worker
1249*e4a36f41SAndroid Build Coastguard Worker# Vendor domian must not have access to /mnt/product.
1250*e4a36f41SAndroid Build Coastguard Workerneverallow {
1251*e4a36f41SAndroid Build Coastguard Worker  domain
1252*e4a36f41SAndroid Build Coastguard Worker  -coredomain
1253*e4a36f41SAndroid Build Coastguard Worker} mnt_product_file:dir *;
1254*e4a36f41SAndroid Build Coastguard Worker
1255*e4a36f41SAndroid Build Coastguard Worker# Platform must not have access to sysfs_batteryinfo, but should do it via health HAL
1256*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
1257*e4a36f41SAndroid Build Coastguard Worker  neverallow {
1258*e4a36f41SAndroid Build Coastguard Worker    coredomain
1259*e4a36f41SAndroid Build Coastguard Worker    -shell
1260*e4a36f41SAndroid Build Coastguard Worker    # For access to block device information under /sys/class/block.
1261*e4a36f41SAndroid Build Coastguard Worker    -apexd
1262*e4a36f41SAndroid Build Coastguard Worker    # Read sysfs block device information.
1263*e4a36f41SAndroid Build Coastguard Worker    -init
1264*e4a36f41SAndroid Build Coastguard Worker    # Generate uevents for health info
1265*e4a36f41SAndroid Build Coastguard Worker    -ueventd
1266*e4a36f41SAndroid Build Coastguard Worker    # Recovery uses health HAL passthrough implementation.
1267*e4a36f41SAndroid Build Coastguard Worker    -recovery
1268*e4a36f41SAndroid Build Coastguard Worker    # Charger uses health HAL passthrough implementation.
1269*e4a36f41SAndroid Build Coastguard Worker    -charger
1270*e4a36f41SAndroid Build Coastguard Worker    # TODO(b/110891300): remove this exception
1271*e4a36f41SAndroid Build Coastguard Worker    -incidentd
1272*e4a36f41SAndroid Build Coastguard Worker  } sysfs_batteryinfo:file { open read };
1273*e4a36f41SAndroid Build Coastguard Worker')
1274*e4a36f41SAndroid Build Coastguard Worker
1275*e4a36f41SAndroid Build Coastguard Workerneverallow {
1276*e4a36f41SAndroid Build Coastguard Worker  domain
1277*e4a36f41SAndroid Build Coastguard Worker  -hal_codec2_server
1278*e4a36f41SAndroid Build Coastguard Worker  -hal_omx_server
1279*e4a36f41SAndroid Build Coastguard Worker} hal_codec2_hwservice:hwservice_manager add;
1280*e4a36f41SAndroid Build Coastguard Worker
1281*e4a36f41SAndroid Build Coastguard Worker# Only apps targetting < Q are allowed to open /dev/ashmem directly.
1282*e4a36f41SAndroid Build Coastguard Worker# Apps must use ASharedMemory NDK API. Native code must use libcutils API.
1283*e4a36f41SAndroid Build Coastguard Workerneverallow {
1284*e4a36f41SAndroid Build Coastguard Worker  domain
1285*e4a36f41SAndroid Build Coastguard Worker  -ephemeral_app # We don't distinguish ephemeral apps based on target API.
1286*e4a36f41SAndroid Build Coastguard Worker  -untrusted_app_25
1287*e4a36f41SAndroid Build Coastguard Worker  -untrusted_app_27
1288*e4a36f41SAndroid Build Coastguard Worker} ashmem_device:chr_file open;
1289*e4a36f41SAndroid Build Coastguard Worker
1290*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -traced_probes -init -vendor_init } debugfs_tracing_printk_formats:file *;
1291*e4a36f41SAndroid Build Coastguard Worker
1292*e4a36f41SAndroid Build Coastguard Worker# Linux lockdown "integrity" level is enforced for user builds.
1293*e4a36f41SAndroid Build Coastguard Workerneverallow { domain userdebug_or_eng(`-domain') } self:lockdown integrity;
1294*e4a36f41SAndroid Build Coastguard Worker
1295*e4a36f41SAndroid Build Coastguard Worker# Allow everyone to read media server-configurable flags, so that libstagefright can be
1296*e4a36f41SAndroid Build Coastguard Worker# configured using server-configurable flags
1297*e4a36f41SAndroid Build Coastguard Workerget_prop(domain, device_config_media_native_prop)
1298