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