xref: /aosp_15_r20/system/sepolicy/public/te_macros (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker#####################################
2*e4a36f41SAndroid Build Coastguard Worker# domain_trans(olddomain, type, newdomain)
3*e4a36f41SAndroid Build Coastguard Worker# Allow a transition from olddomain to newdomain
4*e4a36f41SAndroid Build Coastguard Worker# upon executing a file labeled with type.
5*e4a36f41SAndroid Build Coastguard Worker# This only allows the transition; it does not
6*e4a36f41SAndroid Build Coastguard Worker# cause it to occur automatically - use domain_auto_trans
7*e4a36f41SAndroid Build Coastguard Worker# if that is what you want.
8*e4a36f41SAndroid Build Coastguard Worker#
9*e4a36f41SAndroid Build Coastguard Workerdefine(`domain_trans', `
10*e4a36f41SAndroid Build Coastguard Worker# Old domain may exec the file and transition to the new domain.
11*e4a36f41SAndroid Build Coastguard Workerallow $1 $2:file { getattr open read execute map };
12*e4a36f41SAndroid Build Coastguard Workerallow $1 $3:process transition;
13*e4a36f41SAndroid Build Coastguard Worker# New domain is entered by executing the file.
14*e4a36f41SAndroid Build Coastguard Workerallow $3 $2:file { entrypoint open read execute getattr map };
15*e4a36f41SAndroid Build Coastguard Worker# New domain can send SIGCHLD to its caller.
16*e4a36f41SAndroid Build Coastguard Workerifelse($1, `init', `', `allow $3 $1:process sigchld;')
17*e4a36f41SAndroid Build Coastguard Worker# Enable AT_SECURE, i.e. libc secure mode.
18*e4a36f41SAndroid Build Coastguard Workerdontaudit $1 $3:process noatsecure;
19*e4a36f41SAndroid Build Coastguard Worker# XXX dontaudit candidate but requires further study.
20*e4a36f41SAndroid Build Coastguard Workerallow $1 $3:process { siginh rlimitinh };
21*e4a36f41SAndroid Build Coastguard Worker')
22*e4a36f41SAndroid Build Coastguard Worker
23*e4a36f41SAndroid Build Coastguard Worker#####################################
24*e4a36f41SAndroid Build Coastguard Worker# domain_auto_trans(olddomain, type, newdomain)
25*e4a36f41SAndroid Build Coastguard Worker# Automatically transition from olddomain to newdomain
26*e4a36f41SAndroid Build Coastguard Worker# upon executing a file labeled with type.
27*e4a36f41SAndroid Build Coastguard Worker#
28*e4a36f41SAndroid Build Coastguard Workerdefine(`domain_auto_trans', `
29*e4a36f41SAndroid Build Coastguard Worker# Allow the necessary permissions.
30*e4a36f41SAndroid Build Coastguard Workerdomain_trans($1,$2,$3)
31*e4a36f41SAndroid Build Coastguard Worker# Make the transition occur by default.
32*e4a36f41SAndroid Build Coastguard Workertype_transition $1 $2:process $3;
33*e4a36f41SAndroid Build Coastguard Worker')
34*e4a36f41SAndroid Build Coastguard Worker
35*e4a36f41SAndroid Build Coastguard Worker#####################################
36*e4a36f41SAndroid Build Coastguard Worker# file_type_trans(domain, dir_type, file_type)
37*e4a36f41SAndroid Build Coastguard Worker# Allow domain to create a file labeled file_type in a
38*e4a36f41SAndroid Build Coastguard Worker# directory labeled dir_type.
39*e4a36f41SAndroid Build Coastguard Worker# This only allows the transition; it does not
40*e4a36f41SAndroid Build Coastguard Worker# cause it to occur automatically - use file_type_auto_trans
41*e4a36f41SAndroid Build Coastguard Worker# if that is what you want.
42*e4a36f41SAndroid Build Coastguard Worker#
43*e4a36f41SAndroid Build Coastguard Workerdefine(`file_type_trans', `
44*e4a36f41SAndroid Build Coastguard Worker# Allow the domain to add entries to the directory.
45*e4a36f41SAndroid Build Coastguard Workerallow $1 $2:dir ra_dir_perms;
46*e4a36f41SAndroid Build Coastguard Worker# Allow the domain to create the file.
47*e4a36f41SAndroid Build Coastguard Workerallow $1 $3:notdevfile_class_set create_file_perms;
48*e4a36f41SAndroid Build Coastguard Workerallow $1 $3:dir create_dir_perms;
49*e4a36f41SAndroid Build Coastguard Worker')
50*e4a36f41SAndroid Build Coastguard Worker
51*e4a36f41SAndroid Build Coastguard Worker#####################################
52*e4a36f41SAndroid Build Coastguard Worker# file_type_auto_trans(domain, dir_type, file_type)
53*e4a36f41SAndroid Build Coastguard Worker# Automatically label new files with file_type when
54*e4a36f41SAndroid Build Coastguard Worker# they are created by domain in directories labeled dir_type.
55*e4a36f41SAndroid Build Coastguard Worker#
56*e4a36f41SAndroid Build Coastguard Workerdefine(`file_type_auto_trans', `
57*e4a36f41SAndroid Build Coastguard Worker# Allow the necessary permissions.
58*e4a36f41SAndroid Build Coastguard Workerfile_type_trans($1, $2, $3)
59*e4a36f41SAndroid Build Coastguard Worker# Make the transition occur by default.
60*e4a36f41SAndroid Build Coastguard Workertype_transition $1 $2:dir $3;
61*e4a36f41SAndroid Build Coastguard Workertype_transition $1 $2:notdevfile_class_set $3;
62*e4a36f41SAndroid Build Coastguard Worker')
63*e4a36f41SAndroid Build Coastguard Worker
64*e4a36f41SAndroid Build Coastguard Worker#####################################
65*e4a36f41SAndroid Build Coastguard Worker# r_dir_file(domain, type)
66*e4a36f41SAndroid Build Coastguard Worker# Allow the specified domain to read directories, files
67*e4a36f41SAndroid Build Coastguard Worker# and symbolic links of the specified type.
68*e4a36f41SAndroid Build Coastguard Workerdefine(`r_dir_file', `
69*e4a36f41SAndroid Build Coastguard Workerallow $1 $2:dir r_dir_perms;
70*e4a36f41SAndroid Build Coastguard Workerallow $1 $2:{ file lnk_file } r_file_perms;
71*e4a36f41SAndroid Build Coastguard Worker')
72*e4a36f41SAndroid Build Coastguard Worker
73*e4a36f41SAndroid Build Coastguard Worker#####################################
74*e4a36f41SAndroid Build Coastguard Worker# tmpfs_domain(domain)
75*e4a36f41SAndroid Build Coastguard Worker# Allow access to a unique type for this domain when creating tmpfs / ashmem files.
76*e4a36f41SAndroid Build Coastguard Workerdefine(`tmpfs_domain', `
77*e4a36f41SAndroid Build Coastguard Workertype_transition $1 tmpfs:file $1_tmpfs;
78*e4a36f41SAndroid Build Coastguard Workerallow $1 $1_tmpfs:file { read write getattr map };
79*e4a36f41SAndroid Build Coastguard Worker')
80*e4a36f41SAndroid Build Coastguard Worker
81*e4a36f41SAndroid Build Coastguard Worker# pdx macros for IPC. pdx is a high-level name which contains transport-specific
82*e4a36f41SAndroid Build Coastguard Worker# rules from underlying transport (e.g. UDS-based implementation).
83*e4a36f41SAndroid Build Coastguard Worker
84*e4a36f41SAndroid Build Coastguard Worker#####################################
85*e4a36f41SAndroid Build Coastguard Worker# pdx_service_attributes(service)
86*e4a36f41SAndroid Build Coastguard Worker# Defines type attribute used to identify various service-related types.
87*e4a36f41SAndroid Build Coastguard Workerdefine(`pdx_service_attributes', `
88*e4a36f41SAndroid Build Coastguard Workerattribute pdx_$1_endpoint_dir_type;
89*e4a36f41SAndroid Build Coastguard Workerattribute pdx_$1_endpoint_socket_type;
90*e4a36f41SAndroid Build Coastguard Workerattribute pdx_$1_channel_socket_type;
91*e4a36f41SAndroid Build Coastguard Workerattribute pdx_$1_server_type;
92*e4a36f41SAndroid Build Coastguard Worker')
93*e4a36f41SAndroid Build Coastguard Worker
94*e4a36f41SAndroid Build Coastguard Worker#####################################
95*e4a36f41SAndroid Build Coastguard Worker# pdx_service_socket_types(service, endpoint_dir_t)
96*e4a36f41SAndroid Build Coastguard Worker# Define types for endpoint and channel sockets.
97*e4a36f41SAndroid Build Coastguard Workerdefine(`pdx_service_socket_types', `
98*e4a36f41SAndroid Build Coastguard Workertypeattribute $2 pdx_$1_endpoint_dir_type;
99*e4a36f41SAndroid Build Coastguard Workertype pdx_$1_endpoint_socket, pdx_$1_endpoint_socket_type, pdx_endpoint_socket_type, file_type, coredomain_socket, mlstrustedobject, mlstrustedsubject;
100*e4a36f41SAndroid Build Coastguard Workertype pdx_$1_channel_socket, pdx_$1_channel_socket_type, pdx_channel_socket_type, coredomain_socket;
101*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
102*e4a36f41SAndroid Build Coastguard Workerdontaudit su pdx_$1_endpoint_socket:unix_stream_socket *;
103*e4a36f41SAndroid Build Coastguard Workerdontaudit su pdx_$1_channel_socket:unix_stream_socket *;
104*e4a36f41SAndroid Build Coastguard Worker')
105*e4a36f41SAndroid Build Coastguard Worker')
106*e4a36f41SAndroid Build Coastguard Worker
107*e4a36f41SAndroid Build Coastguard Worker#####################################
108*e4a36f41SAndroid Build Coastguard Worker# pdx_server(server_domain, service)
109*e4a36f41SAndroid Build Coastguard Workerdefine(`pdx_server', `
110*e4a36f41SAndroid Build Coastguard Worker# Mark the server domain as a PDX server.
111*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 pdx_$2_server_type;
112*e4a36f41SAndroid Build Coastguard Worker# Allow the init process to create the initial endpoint socket.
113*e4a36f41SAndroid Build Coastguard Workerallow init pdx_$2_endpoint_socket_type:unix_stream_socket { create bind };
114*e4a36f41SAndroid Build Coastguard Worker# Allow the server domain to use the endpoint socket and accept connections on it.
115*e4a36f41SAndroid Build Coastguard Worker# Not using macro like "rw_socket_perms_no_ioctl" because it provides more rights
116*e4a36f41SAndroid Build Coastguard Worker# than we need (e.g. we don"t need "bind" or "connect").
117*e4a36f41SAndroid Build Coastguard Workerallow $1 pdx_$2_endpoint_socket_type:unix_stream_socket { read getattr write setattr lock append getopt setopt shutdown listen accept };
118*e4a36f41SAndroid Build Coastguard Worker# Allow the server domain to apply security context label to the channel socket pair (allow process to use setsockcreatecon_raw()).
119*e4a36f41SAndroid Build Coastguard Workerallow $1 self:process setsockcreate;
120*e4a36f41SAndroid Build Coastguard Worker# Allow the server domain to create a client channel socket.
121*e4a36f41SAndroid Build Coastguard Workerallow $1 pdx_$2_channel_socket_type:unix_stream_socket create_stream_socket_perms;
122*e4a36f41SAndroid Build Coastguard Worker# Prevent other processes from claiming to be a server for the same service.
123*e4a36f41SAndroid Build Coastguard Workerneverallow {domain -$1} pdx_$2_endpoint_socket_type:unix_stream_socket { listen accept };
124*e4a36f41SAndroid Build Coastguard Worker')
125*e4a36f41SAndroid Build Coastguard Worker
126*e4a36f41SAndroid Build Coastguard Worker#####################################
127*e4a36f41SAndroid Build Coastguard Worker# pdx_connect(client, service)
128*e4a36f41SAndroid Build Coastguard Workerdefine(`pdx_connect', `
129*e4a36f41SAndroid Build Coastguard Worker# Allow client to open the service endpoint file.
130*e4a36f41SAndroid Build Coastguard Workerallow $1 pdx_$2_endpoint_dir_type:dir r_dir_perms;
131*e4a36f41SAndroid Build Coastguard Workerallow $1 pdx_$2_endpoint_socket_type:sock_file rw_file_perms;
132*e4a36f41SAndroid Build Coastguard Worker# Allow the client to connect to endpoint socket.
133*e4a36f41SAndroid Build Coastguard Workerallow $1 pdx_$2_endpoint_socket_type:unix_stream_socket { connectto read write shutdown };
134*e4a36f41SAndroid Build Coastguard Worker')
135*e4a36f41SAndroid Build Coastguard Worker
136*e4a36f41SAndroid Build Coastguard Worker#####################################
137*e4a36f41SAndroid Build Coastguard Worker# pdx_use(client, service)
138*e4a36f41SAndroid Build Coastguard Workerdefine(`pdx_use', `
139*e4a36f41SAndroid Build Coastguard Worker# Allow the client to use the PDX channel socket.
140*e4a36f41SAndroid Build Coastguard Worker# Not using macro like "rw_socket_perms_no_ioctl" because it provides more rights
141*e4a36f41SAndroid Build Coastguard Worker# than we need (e.g. we don"t need "bind" or "connect").
142*e4a36f41SAndroid Build Coastguard Workerallow $1 pdx_$2_channel_socket_type:unix_stream_socket { read getattr write setattr lock append getopt setopt shutdown };
143*e4a36f41SAndroid Build Coastguard Worker# Client needs to use an channel event fd from the server.
144*e4a36f41SAndroid Build Coastguard Workerallow $1 pdx_$2_server_type:fd use;
145*e4a36f41SAndroid Build Coastguard Worker# Servers may receive sync fences, gralloc buffers, etc, from clients.
146*e4a36f41SAndroid Build Coastguard Worker# This could be tightened on a per-server basis, but keeping track of service
147*e4a36f41SAndroid Build Coastguard Worker# clients is error prone.
148*e4a36f41SAndroid Build Coastguard Workerallow pdx_$2_server_type $1:fd use;
149*e4a36f41SAndroid Build Coastguard Worker')
150*e4a36f41SAndroid Build Coastguard Worker
151*e4a36f41SAndroid Build Coastguard Worker#####################################
152*e4a36f41SAndroid Build Coastguard Worker# pdx_client(client, service)
153*e4a36f41SAndroid Build Coastguard Workerdefine(`pdx_client', `
154*e4a36f41SAndroid Build Coastguard Workerpdx_connect($1, $2)
155*e4a36f41SAndroid Build Coastguard Workerpdx_use($1, $2)
156*e4a36f41SAndroid Build Coastguard Worker')
157*e4a36f41SAndroid Build Coastguard Worker
158*e4a36f41SAndroid Build Coastguard Worker#####################################
159*e4a36f41SAndroid Build Coastguard Worker# init_daemon_domain(domain)
160*e4a36f41SAndroid Build Coastguard Worker# Set up a transition from init to the daemon domain
161*e4a36f41SAndroid Build Coastguard Worker# upon executing its binary.
162*e4a36f41SAndroid Build Coastguard Workerdefine(`init_daemon_domain', `
163*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(init, $1_exec, $1)
164*e4a36f41SAndroid Build Coastguard Worker')
165*e4a36f41SAndroid Build Coastguard Worker
166*e4a36f41SAndroid Build Coastguard Worker####################################
167*e4a36f41SAndroid Build Coastguard Worker# userfaultfd_use(domain)
168*e4a36f41SAndroid Build Coastguard Worker# Allow domain to create/use userfaultfd.
169*e4a36f41SAndroid Build Coastguard Workerdefine(`userfaultfd_use', `
170*e4a36f41SAndroid Build Coastguard Worker# Set up a type_transition to "userfaultfd" named anonymous inode object.
171*e4a36f41SAndroid Build Coastguard Workertype $1_userfaultfd;
172*e4a36f41SAndroid Build Coastguard Workertype_transition $1 $1:anon_inode $1_userfaultfd "[userfaultfd]";
173*e4a36f41SAndroid Build Coastguard Worker# Allow domain to create/use userfaultfd anon_inode.
174*e4a36f41SAndroid Build Coastguard Workerallow $1 $1_userfaultfd:anon_inode { create ioctl read };
175*e4a36f41SAndroid Build Coastguard Worker# Suppress errors generate during bugreport
176*e4a36f41SAndroid Build Coastguard Workerdontaudit su $1_userfaultfd:anon_inode *;
177*e4a36f41SAndroid Build Coastguard Worker# Other domains may not use userfaultfd anon_inodes created by this domain.
178*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -$1 } $1_userfaultfd:anon_inode *;
179*e4a36f41SAndroid Build Coastguard Worker')
180*e4a36f41SAndroid Build Coastguard Worker
181*e4a36f41SAndroid Build Coastguard Worker####################################
182*e4a36f41SAndroid Build Coastguard Worker# virtualizationservice_use(domain)
183*e4a36f41SAndroid Build Coastguard Worker# Allow domain to create and communicate with a virtual machine using
184*e4a36f41SAndroid Build Coastguard Worker# virtualizationservice and virtualizationmanager.
185*e4a36f41SAndroid Build Coastguard Workerdefine(`virtualizationservice_use', `
186*e4a36f41SAndroid Build Coastguard Worker# Transition to virtualizationmanager when the client executes it.
187*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans($1, virtualizationmanager_exec, virtualizationmanager)
188*e4a36f41SAndroid Build Coastguard Worker# Allow virtualizationmanager to communicate over UDS with the client.
189*e4a36f41SAndroid Build Coastguard Workerallow { virtualizationmanager crosvm } $1:unix_stream_socket { ioctl getattr read write };
190*e4a36f41SAndroid Build Coastguard Worker# Let the client pass file descriptors to virtualizationmanager and on to crosvm.
191*e4a36f41SAndroid Build Coastguard Workerallow { virtualizationmanager crosvm } $1:fd use;
192*e4a36f41SAndroid Build Coastguard Worker# Let the client use file descriptors created by virtualizationmanager.
193*e4a36f41SAndroid Build Coastguard Workerallow $1 virtualizationmanager:fd use;
194*e4a36f41SAndroid Build Coastguard Worker# Allow piping console log to the client
195*e4a36f41SAndroid Build Coastguard Workerallow { virtualizationmanager crosvm } $1:fifo_file { ioctl getattr read write };
196*e4a36f41SAndroid Build Coastguard Worker# Allow client to read/write vsock created by virtualizationmanager to communicate with the VM
197*e4a36f41SAndroid Build Coastguard Worker# that it created. Notice that we do not grant permission to create a vsock;
198*e4a36f41SAndroid Build Coastguard Worker# the client can only connect to VMs that it owns.
199*e4a36f41SAndroid Build Coastguard Workerallow $1 virtualizationmanager:vsock_socket { getattr getopt read write };
200*e4a36f41SAndroid Build Coastguard Worker# Allow client to inspect hypervisor capabilities
201*e4a36f41SAndroid Build Coastguard Workerget_prop($1, hypervisor_prop)
202*e4a36f41SAndroid Build Coastguard Worker# Allow client to read (but not open) the crashdump provided by virtualizationmanager
203*e4a36f41SAndroid Build Coastguard Workerallow $1 virtualizationservice_data_file:file { getattr read };
204*e4a36f41SAndroid Build Coastguard Worker')
205*e4a36f41SAndroid Build Coastguard Worker
206*e4a36f41SAndroid Build Coastguard Worker####################################
207*e4a36f41SAndroid Build Coastguard Worker# early_virtmgr_use(domain)
208*e4a36f41SAndroid Build Coastguard Worker# Allow domain to create and communicate with an early virtual machine using
209*e4a36f41SAndroid Build Coastguard Worker# early_virtmgr.
210*e4a36f41SAndroid Build Coastguard Workerdefine(`early_virtmgr_use', `
211*e4a36f41SAndroid Build Coastguard Worker# Transition to early_virtmgr when the client executes it.
212*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans($1, early_virtmgr_exec, early_virtmgr)
213*e4a36f41SAndroid Build Coastguard Worker# Allow early_virtmgr to communicate over UDS with the client.
214*e4a36f41SAndroid Build Coastguard Workerallow { early_virtmgr crosvm } $1:unix_stream_socket { ioctl getattr read write };
215*e4a36f41SAndroid Build Coastguard Worker# Let the client pass file descriptors to early_virtmgr and on to crosvm.
216*e4a36f41SAndroid Build Coastguard Workerallow { early_virtmgr crosvm } $1:fd use;
217*e4a36f41SAndroid Build Coastguard Workerallow { early_virtmgr crosvm } $1_tmpfs:file rw_file_perms;
218*e4a36f41SAndroid Build Coastguard Worker# Let the client use file descriptors created by early_virtmgr.
219*e4a36f41SAndroid Build Coastguard Workerallow $1 early_virtmgr:fd use;
220*e4a36f41SAndroid Build Coastguard Worker# Allow piping console log to the client
221*e4a36f41SAndroid Build Coastguard Workerallow { early_virtmgr crosvm } $1:fifo_file { ioctl getattr read write };
222*e4a36f41SAndroid Build Coastguard Worker# Allow client to read/write vsock created by early_virtmgr to communicate with the VM
223*e4a36f41SAndroid Build Coastguard Worker# that it created. Notice that we do not grant permission to create a vsock;
224*e4a36f41SAndroid Build Coastguard Worker# the client can only connect to VMs that it owns.
225*e4a36f41SAndroid Build Coastguard Workerallow $1 early_virtmgr:vsock_socket { getattr getopt read write };
226*e4a36f41SAndroid Build Coastguard Worker# Allow client to inspect hypervisor capabilities
227*e4a36f41SAndroid Build Coastguard Workerget_prop($1, hypervisor_prop)
228*e4a36f41SAndroid Build Coastguard Worker# Allow early_virtmgr to read the path of the client using /proc/{PID}/exe
229*e4a36f41SAndroid Build Coastguard Workerallow early_virtmgr $1:dir search;
230*e4a36f41SAndroid Build Coastguard Workerallow early_virtmgr $1:file read;
231*e4a36f41SAndroid Build Coastguard Workerallow early_virtmgr $1:lnk_file read;
232*e4a36f41SAndroid Build Coastguard Worker')
233*e4a36f41SAndroid Build Coastguard Worker
234*e4a36f41SAndroid Build Coastguard Worker#####################################
235*e4a36f41SAndroid Build Coastguard Worker# app_domain(domain)
236*e4a36f41SAndroid Build Coastguard Worker# Allow a base set of permissions required for all apps.
237*e4a36f41SAndroid Build Coastguard Workerdefine(`app_domain', `
238*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 appdomain;
239*e4a36f41SAndroid Build Coastguard Worker# Label tmpfs objects for all apps.
240*e4a36f41SAndroid Build Coastguard Workertype_transition $1 tmpfs:file appdomain_tmpfs;
241*e4a36f41SAndroid Build Coastguard Workeruserfaultfd_use($1)
242*e4a36f41SAndroid Build Coastguard Workerallow $1 appdomain_tmpfs:file { execute getattr map read write };
243*e4a36f41SAndroid Build Coastguard Workerneverallow { $1 -runas_app -shell -simpleperf } { domain -$1 }:file no_rw_file_perms;
244*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -runas_app -shell -simpleperf -$1 } $1:file no_rw_file_perms;
245*e4a36f41SAndroid Build Coastguard Worker# The Android security model guarantees the confidentiality and integrity
246*e4a36f41SAndroid Build Coastguard Worker# of application data and execution state. Ptrace bypasses those
247*e4a36f41SAndroid Build Coastguard Worker# confidentiality guarantees. Disallow ptrace access from system components to
248*e4a36f41SAndroid Build Coastguard Worker# apps. crash_dump is excluded, as it needs ptrace access to produce stack
249*e4a36f41SAndroid Build Coastguard Worker# traces. runas_app is excluded, as it operates only on debuggable apps.
250*e4a36f41SAndroid Build Coastguard Worker# simpleperf is excluded, as it operates only on debuggable or profileable
251*e4a36f41SAndroid Build Coastguard Worker# apps. llkd is excluded, as it needs ptrace access to inspect stack traces for
252*e4a36f41SAndroid Build Coastguard Worker# live lock conditions.
253*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -$1 -crash_dump userdebug_or_eng(`-llkd') -runas_app -simpleperf } $1:process ptrace;
254*e4a36f41SAndroid Build Coastguard Worker')
255*e4a36f41SAndroid Build Coastguard Worker
256*e4a36f41SAndroid Build Coastguard Worker#####################################
257*e4a36f41SAndroid Build Coastguard Worker# untrusted_app_domain(domain)
258*e4a36f41SAndroid Build Coastguard Worker# Allow a base set of permissions required for all untrusted apps.
259*e4a36f41SAndroid Build Coastguard Workerdefine(`untrusted_app_domain', `
260*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 untrusted_app_all;
261*e4a36f41SAndroid Build Coastguard Worker')
262*e4a36f41SAndroid Build Coastguard Worker
263*e4a36f41SAndroid Build Coastguard Worker#####################################
264*e4a36f41SAndroid Build Coastguard Worker# isolated_app_domain(domain)
265*e4a36f41SAndroid Build Coastguard Worker# Allow a base set of permissions required for all isolated apps.
266*e4a36f41SAndroid Build Coastguard Workerdefine(`isolated_app_domain', `
267*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 isolated_app_all;
268*e4a36f41SAndroid Build Coastguard Worker')
269*e4a36f41SAndroid Build Coastguard Worker
270*e4a36f41SAndroid Build Coastguard Worker#####################################
271*e4a36f41SAndroid Build Coastguard Worker# net_domain(domain)
272*e4a36f41SAndroid Build Coastguard Worker# Allow a base set of permissions required for network access.
273*e4a36f41SAndroid Build Coastguard Workerdefine(`net_domain', `
274*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 netdomain;
275*e4a36f41SAndroid Build Coastguard Worker')
276*e4a36f41SAndroid Build Coastguard Worker
277*e4a36f41SAndroid Build Coastguard Worker#####################################
278*e4a36f41SAndroid Build Coastguard Worker# bluetooth_domain(domain)
279*e4a36f41SAndroid Build Coastguard Worker# Allow a base set of permissions required for bluetooth access.
280*e4a36f41SAndroid Build Coastguard Workerdefine(`bluetooth_domain', `
281*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 bluetoothdomain;
282*e4a36f41SAndroid Build Coastguard Worker')
283*e4a36f41SAndroid Build Coastguard Worker
284*e4a36f41SAndroid Build Coastguard Worker#####################################
285*e4a36f41SAndroid Build Coastguard Worker# hal_attribute(hal_name)
286*e4a36f41SAndroid Build Coastguard Worker# Add an attribute for hal implementations along with necessary
287*e4a36f41SAndroid Build Coastguard Worker# restrictions.
288*e4a36f41SAndroid Build Coastguard Workerdefine(`hal_attribute', `
289*e4a36f41SAndroid Build Coastguard Workerattribute hal_$1;
290*e4a36f41SAndroid Build Coastguard Workerexpandattribute hal_$1 true;
291*e4a36f41SAndroid Build Coastguard Workerattribute hal_$1_client;
292*e4a36f41SAndroid Build Coastguard Workerexpandattribute hal_$1_client true;
293*e4a36f41SAndroid Build Coastguard Workerattribute hal_$1_server;
294*e4a36f41SAndroid Build Coastguard Workerexpandattribute hal_$1_server false;
295*e4a36f41SAndroid Build Coastguard Worker
296*e4a36f41SAndroid Build Coastguard Workerneverallow { hal_$1_server -halserverdomain } domain:process fork;
297*e4a36f41SAndroid Build Coastguard Worker# hal_*_client and halclientdomain attributes are always expanded for
298*e4a36f41SAndroid Build Coastguard Worker# performance reasons. Neverallow rules targeting expanded attributes can not be
299*e4a36f41SAndroid Build Coastguard Worker# verified by CTS since these attributes are already expanded by that time.
300*e4a36f41SAndroid Build Coastguard Workerbuild_test_only(`
301*e4a36f41SAndroid Build Coastguard Workerneverallow { hal_$1_server -hal_$1 } domain:process fork;
302*e4a36f41SAndroid Build Coastguard Workerneverallow { hal_$1_client -halclientdomain } domain:process fork;
303*e4a36f41SAndroid Build Coastguard Worker')
304*e4a36f41SAndroid Build Coastguard Worker')
305*e4a36f41SAndroid Build Coastguard Worker
306*e4a36f41SAndroid Build Coastguard Worker#####################################
307*e4a36f41SAndroid Build Coastguard Worker# hal_server_domain(domain, hal_type)
308*e4a36f41SAndroid Build Coastguard Worker# Allow a base set of permissions required for a domain to offer a
309*e4a36f41SAndroid Build Coastguard Worker# HAL implementation of the specified type over HwBinder.
310*e4a36f41SAndroid Build Coastguard Worker#
311*e4a36f41SAndroid Build Coastguard Worker# For example, default implementation of Foo HAL:
312*e4a36f41SAndroid Build Coastguard Worker#   type hal_foo_default, domain;
313*e4a36f41SAndroid Build Coastguard Worker#   hal_server_domain(hal_foo_default, hal_foo)
314*e4a36f41SAndroid Build Coastguard Worker#
315*e4a36f41SAndroid Build Coastguard Workerdefine(`hal_server_domain', `
316*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 halserverdomain;
317*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 $2_server;
318*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 $2;
319*e4a36f41SAndroid Build Coastguard Worker')
320*e4a36f41SAndroid Build Coastguard Worker
321*e4a36f41SAndroid Build Coastguard Worker#####################################
322*e4a36f41SAndroid Build Coastguard Worker# hal_client_domain(domain, hal_type)
323*e4a36f41SAndroid Build Coastguard Worker# Allow a base set of permissions required for a domain to be a
324*e4a36f41SAndroid Build Coastguard Worker# client of a HAL of the specified type.
325*e4a36f41SAndroid Build Coastguard Worker#
326*e4a36f41SAndroid Build Coastguard Worker# For example, make some_domain a client of Foo HAL:
327*e4a36f41SAndroid Build Coastguard Worker#   hal_client_domain(some_domain, hal_foo)
328*e4a36f41SAndroid Build Coastguard Worker#
329*e4a36f41SAndroid Build Coastguard Workerdefine(`hal_client_domain', `
330*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 halclientdomain;
331*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 $2_client;
332*e4a36f41SAndroid Build Coastguard Worker
333*e4a36f41SAndroid Build Coastguard Worker# TODO(b/34170079): Make the inclusion of the rules below conditional also on
334*e4a36f41SAndroid Build Coastguard Worker# non-Treble devices. For now, on non-Treble device, always grant clients of a
335*e4a36f41SAndroid Build Coastguard Worker# HAL sufficient access to run the HAL in passthrough mode (i.e., in-process).
336*e4a36f41SAndroid Build Coastguard Workernot_full_treble(`
337*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 $2;
338*e4a36f41SAndroid Build Coastguard Worker# Find passthrough HAL implementations
339*e4a36f41SAndroid Build Coastguard Workerallow $2 system_file:dir r_dir_perms;
340*e4a36f41SAndroid Build Coastguard Workerallow $2 vendor_file:dir r_dir_perms;
341*e4a36f41SAndroid Build Coastguard Workerallow $2 vendor_file:file { read open getattr execute map };
342*e4a36f41SAndroid Build Coastguard Worker')
343*e4a36f41SAndroid Build Coastguard Worker')
344*e4a36f41SAndroid Build Coastguard Worker
345*e4a36f41SAndroid Build Coastguard Worker#####################################
346*e4a36f41SAndroid Build Coastguard Worker# passthrough_hal_client_domain(domain, hal_type)
347*e4a36f41SAndroid Build Coastguard Worker# Allow a base set of permissions required for a domain to be a
348*e4a36f41SAndroid Build Coastguard Worker# client of a passthrough HAL of the specified type.
349*e4a36f41SAndroid Build Coastguard Worker#
350*e4a36f41SAndroid Build Coastguard Worker# For example, make some_domain a client of passthrough Foo HAL:
351*e4a36f41SAndroid Build Coastguard Worker#   passthrough_hal_client_domain(some_domain, hal_foo)
352*e4a36f41SAndroid Build Coastguard Worker#
353*e4a36f41SAndroid Build Coastguard Workerdefine(`passthrough_hal_client_domain', `
354*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 halclientdomain;
355*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 $2_client;
356*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 $2;
357*e4a36f41SAndroid Build Coastguard Worker# Find passthrough HAL implementations
358*e4a36f41SAndroid Build Coastguard Workerallow $2 system_file:dir r_dir_perms;
359*e4a36f41SAndroid Build Coastguard Workerallow $2 vendor_file:dir r_dir_perms;
360*e4a36f41SAndroid Build Coastguard Workerallow $2 vendor_file:file { read open getattr execute map };
361*e4a36f41SAndroid Build Coastguard Worker')
362*e4a36f41SAndroid Build Coastguard Worker
363*e4a36f41SAndroid Build Coastguard Worker#####################################
364*e4a36f41SAndroid Build Coastguard Worker# unix_socket_connect(clientdomain, socket, serverdomain)
365*e4a36f41SAndroid Build Coastguard Worker# Allow a local socket connection from clientdomain via
366*e4a36f41SAndroid Build Coastguard Worker# socket to serverdomain.
367*e4a36f41SAndroid Build Coastguard Worker#
368*e4a36f41SAndroid Build Coastguard Worker# Note: If you see denial records that distill to the
369*e4a36f41SAndroid Build Coastguard Worker# following allow rules:
370*e4a36f41SAndroid Build Coastguard Worker# allow clientdomain property_socket:sock_file write;
371*e4a36f41SAndroid Build Coastguard Worker# allow clientdomain init:unix_stream_socket connectto;
372*e4a36f41SAndroid Build Coastguard Worker# allow clientdomain something_prop:property_service set;
373*e4a36f41SAndroid Build Coastguard Worker#
374*e4a36f41SAndroid Build Coastguard Worker# This sequence is indicative of attempting to set a property.
375*e4a36f41SAndroid Build Coastguard Worker# use set_prop(sourcedomain, targetproperty)
376*e4a36f41SAndroid Build Coastguard Worker#
377*e4a36f41SAndroid Build Coastguard Workerdefine(`unix_socket_connect', `
378*e4a36f41SAndroid Build Coastguard Workerallow $1 $2_socket:sock_file write;
379*e4a36f41SAndroid Build Coastguard Workerallow $1 $3:unix_stream_socket connectto;
380*e4a36f41SAndroid Build Coastguard Worker')
381*e4a36f41SAndroid Build Coastguard Worker
382*e4a36f41SAndroid Build Coastguard Worker#####################################
383*e4a36f41SAndroid Build Coastguard Worker# set_prop(sourcedomain, targetproperty)
384*e4a36f41SAndroid Build Coastguard Worker# Allows source domain to set the
385*e4a36f41SAndroid Build Coastguard Worker# targetproperty.
386*e4a36f41SAndroid Build Coastguard Worker#
387*e4a36f41SAndroid Build Coastguard Workerdefine(`set_prop', `
388*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect($1, property, init)
389*e4a36f41SAndroid Build Coastguard Workerallow $1 $2:property_service set;
390*e4a36f41SAndroid Build Coastguard Workerget_prop($1, $2)
391*e4a36f41SAndroid Build Coastguard Worker')
392*e4a36f41SAndroid Build Coastguard Worker
393*e4a36f41SAndroid Build Coastguard Worker#####################################
394*e4a36f41SAndroid Build Coastguard Worker# get_prop(sourcedomain, targetproperty)
395*e4a36f41SAndroid Build Coastguard Worker# Allows source domain to read the
396*e4a36f41SAndroid Build Coastguard Worker# targetproperty.
397*e4a36f41SAndroid Build Coastguard Worker#
398*e4a36f41SAndroid Build Coastguard Workerdefine(`get_prop', `
399*e4a36f41SAndroid Build Coastguard Workerallow $1 $2:file { getattr open read map };
400*e4a36f41SAndroid Build Coastguard Worker')
401*e4a36f41SAndroid Build Coastguard Worker
402*e4a36f41SAndroid Build Coastguard Worker#####################################
403*e4a36f41SAndroid Build Coastguard Worker# unix_socket_send(clientdomain, socket, serverdomain)
404*e4a36f41SAndroid Build Coastguard Worker# Allow a local socket send from clientdomain via
405*e4a36f41SAndroid Build Coastguard Worker# socket to serverdomain.
406*e4a36f41SAndroid Build Coastguard Workerdefine(`unix_socket_send', `
407*e4a36f41SAndroid Build Coastguard Workerallow $1 $2_socket:sock_file write;
408*e4a36f41SAndroid Build Coastguard Workerallow $1 $3:unix_dgram_socket sendto;
409*e4a36f41SAndroid Build Coastguard Worker')
410*e4a36f41SAndroid Build Coastguard Worker
411*e4a36f41SAndroid Build Coastguard Worker#####################################
412*e4a36f41SAndroid Build Coastguard Worker# binder_use(domain)
413*e4a36f41SAndroid Build Coastguard Worker# Allow domain to use Binder IPC.
414*e4a36f41SAndroid Build Coastguard Workerdefine(`binder_use', `
415*e4a36f41SAndroid Build Coastguard Worker# Call the servicemanager and transfer references to it.
416*e4a36f41SAndroid Build Coastguard Workerallow $1 servicemanager:binder { call transfer };
417*e4a36f41SAndroid Build Coastguard Worker# Allow servicemanager to send out callbacks
418*e4a36f41SAndroid Build Coastguard Workerallow servicemanager $1:binder { call transfer };
419*e4a36f41SAndroid Build Coastguard Worker# servicemanager performs getpidcon on clients.
420*e4a36f41SAndroid Build Coastguard Workerallow servicemanager $1:dir search;
421*e4a36f41SAndroid Build Coastguard Workerallow servicemanager $1:file { read open };
422*e4a36f41SAndroid Build Coastguard Workerallow servicemanager $1:process getattr;
423*e4a36f41SAndroid Build Coastguard Worker# rw access to /dev/binder and /dev/ashmem is presently granted to
424*e4a36f41SAndroid Build Coastguard Worker# all domains in domain.te.
425*e4a36f41SAndroid Build Coastguard Worker')
426*e4a36f41SAndroid Build Coastguard Worker
427*e4a36f41SAndroid Build Coastguard Worker#####################################
428*e4a36f41SAndroid Build Coastguard Worker# hwbinder_use(domain)
429*e4a36f41SAndroid Build Coastguard Worker# Allow domain to use HwBinder IPC.
430*e4a36f41SAndroid Build Coastguard Workerdefine(`hwbinder_use', `
431*e4a36f41SAndroid Build Coastguard Worker# Call the hwservicemanager and transfer references to it.
432*e4a36f41SAndroid Build Coastguard Workerallow $1 hwservicemanager:binder { call transfer };
433*e4a36f41SAndroid Build Coastguard Worker# Allow hwservicemanager to send out callbacks
434*e4a36f41SAndroid Build Coastguard Workerallow hwservicemanager $1:binder { call transfer };
435*e4a36f41SAndroid Build Coastguard Worker# hwservicemanager performs getpidcon on clients.
436*e4a36f41SAndroid Build Coastguard Workerallow hwservicemanager $1:dir search;
437*e4a36f41SAndroid Build Coastguard Workerallow hwservicemanager $1:file { read open map };
438*e4a36f41SAndroid Build Coastguard Workerallow hwservicemanager $1:process getattr;
439*e4a36f41SAndroid Build Coastguard Worker# rw access to /dev/hwbinder and /dev/ashmem is presently granted to
440*e4a36f41SAndroid Build Coastguard Worker# all domains in domain.te.
441*e4a36f41SAndroid Build Coastguard Worker')
442*e4a36f41SAndroid Build Coastguard Worker
443*e4a36f41SAndroid Build Coastguard Worker#####################################
444*e4a36f41SAndroid Build Coastguard Worker# vndbinder_use(domain)
445*e4a36f41SAndroid Build Coastguard Worker# Allow domain to use Binder IPC.
446*e4a36f41SAndroid Build Coastguard Workerdefine(`vndbinder_use', `
447*e4a36f41SAndroid Build Coastguard Worker# Talk to the vndbinder device node
448*e4a36f41SAndroid Build Coastguard Workerallow $1 vndbinder_device:chr_file rw_file_perms;
449*e4a36f41SAndroid Build Coastguard Worker# Call the vndservicemanager and transfer references to it.
450*e4a36f41SAndroid Build Coastguard Workerallow $1 vndservicemanager:binder { call transfer };
451*e4a36f41SAndroid Build Coastguard Worker# vndservicemanager performs getpidcon on clients.
452*e4a36f41SAndroid Build Coastguard Workerallow vndservicemanager $1:dir search;
453*e4a36f41SAndroid Build Coastguard Workerallow vndservicemanager $1:file { read open map };
454*e4a36f41SAndroid Build Coastguard Workerallow vndservicemanager $1:process getattr;
455*e4a36f41SAndroid Build Coastguard Worker')
456*e4a36f41SAndroid Build Coastguard Worker
457*e4a36f41SAndroid Build Coastguard Worker#####################################
458*e4a36f41SAndroid Build Coastguard Worker# binder_call(clientdomain, serverdomain)
459*e4a36f41SAndroid Build Coastguard Worker# Allow clientdomain to perform binder IPC to serverdomain.
460*e4a36f41SAndroid Build Coastguard Workerdefine(`binder_call', `
461*e4a36f41SAndroid Build Coastguard Worker# Call the server domain and optionally transfer references to it.
462*e4a36f41SAndroid Build Coastguard Workerallow $1 $2:binder { call transfer };
463*e4a36f41SAndroid Build Coastguard Worker# Allow the serverdomain to transfer references to the client on the reply.
464*e4a36f41SAndroid Build Coastguard Workerallow $2 $1:binder transfer;
465*e4a36f41SAndroid Build Coastguard Worker# Receive and use open files from the server.
466*e4a36f41SAndroid Build Coastguard Workerallow $1 $2:fd use;
467*e4a36f41SAndroid Build Coastguard Worker')
468*e4a36f41SAndroid Build Coastguard Worker
469*e4a36f41SAndroid Build Coastguard Worker#####################################
470*e4a36f41SAndroid Build Coastguard Worker# binder_service(domain)
471*e4a36f41SAndroid Build Coastguard Worker# Deprecated. Consider granting the exact permissions required by your service.
472*e4a36f41SAndroid Build Coastguard Workerdefine(`binder_service', `
473*e4a36f41SAndroid Build Coastguard Workertypeattribute $1 binderservicedomain;
474*e4a36f41SAndroid Build Coastguard Worker')
475*e4a36f41SAndroid Build Coastguard Worker
476*e4a36f41SAndroid Build Coastguard Worker#####################################
477*e4a36f41SAndroid Build Coastguard Worker# wakelock_use(domain)
478*e4a36f41SAndroid Build Coastguard Worker# Allow domain to manage wake locks
479*e4a36f41SAndroid Build Coastguard Workerdefine(`wakelock_use', `
480*e4a36f41SAndroid Build Coastguard Worker# TODO(b/115946999): Remove /sys/power/* permissions once CONFIG_PM_WAKELOCKS is
481*e4a36f41SAndroid Build Coastguard Worker# deprecated.
482*e4a36f41SAndroid Build Coastguard Worker# Access /sys/power/wake_lock and /sys/power/wake_unlock
483*e4a36f41SAndroid Build Coastguard Workerallow $1 sysfs_wake_lock:file rw_file_perms;
484*e4a36f41SAndroid Build Coastguard Worker# Accessing these files requires CAP_BLOCK_SUSPEND
485*e4a36f41SAndroid Build Coastguard Workerallow $1 self:global_capability2_class_set block_suspend;
486*e4a36f41SAndroid Build Coastguard Worker# system_suspend permissions
487*e4a36f41SAndroid Build Coastguard Workerbinder_call($1, system_suspend_server)
488*e4a36f41SAndroid Build Coastguard Workerallow $1 system_suspend_hwservice:hwservice_manager find;
489*e4a36f41SAndroid Build Coastguard Worker# halclientdomain permissions
490*e4a36f41SAndroid Build Coastguard Workerhwbinder_use($1)
491*e4a36f41SAndroid Build Coastguard Workerget_prop($1, hwservicemanager_prop)
492*e4a36f41SAndroid Build Coastguard Workerallow $1 hidl_manager_hwservice:hwservice_manager find;
493*e4a36f41SAndroid Build Coastguard Worker# AIDL suspend hal permissions
494*e4a36f41SAndroid Build Coastguard Workerallow $1 hal_system_suspend_service:service_manager find;
495*e4a36f41SAndroid Build Coastguard Workerbinder_use($1)
496*e4a36f41SAndroid Build Coastguard Worker')
497*e4a36f41SAndroid Build Coastguard Worker
498*e4a36f41SAndroid Build Coastguard Worker#####################################
499*e4a36f41SAndroid Build Coastguard Worker# selinux_check_access(domain)
500*e4a36f41SAndroid Build Coastguard Worker# Allow domain to check SELinux permissions via selinuxfs.
501*e4a36f41SAndroid Build Coastguard Workerdefine(`selinux_check_access', `
502*e4a36f41SAndroid Build Coastguard Workerr_dir_file($1, selinuxfs)
503*e4a36f41SAndroid Build Coastguard Workerallow $1 selinuxfs:file w_file_perms;
504*e4a36f41SAndroid Build Coastguard Workerallow $1 kernel:security compute_av;
505*e4a36f41SAndroid Build Coastguard Workerallow $1 self:netlink_selinux_socket { read write create getattr setattr lock relabelfrom relabelto append bind connect listen accept getopt setopt shutdown recvfrom sendto name_bind };
506*e4a36f41SAndroid Build Coastguard Worker')
507*e4a36f41SAndroid Build Coastguard Worker
508*e4a36f41SAndroid Build Coastguard Worker#####################################
509*e4a36f41SAndroid Build Coastguard Worker# selinux_check_context(domain)
510*e4a36f41SAndroid Build Coastguard Worker# Allow domain to check SELinux contexts via selinuxfs.
511*e4a36f41SAndroid Build Coastguard Workerdefine(`selinux_check_context', `
512*e4a36f41SAndroid Build Coastguard Workerr_dir_file($1, selinuxfs)
513*e4a36f41SAndroid Build Coastguard Workerallow $1 selinuxfs:file w_file_perms;
514*e4a36f41SAndroid Build Coastguard Workerallow $1 kernel:security check_context;
515*e4a36f41SAndroid Build Coastguard Worker')
516*e4a36f41SAndroid Build Coastguard Worker
517*e4a36f41SAndroid Build Coastguard Worker#####################################
518*e4a36f41SAndroid Build Coastguard Worker# create_pty(domain)
519*e4a36f41SAndroid Build Coastguard Worker# Allow domain to create and use a pty, isolated from any other domain ptys.
520*e4a36f41SAndroid Build Coastguard Workerdefine(`create_pty', `
521*e4a36f41SAndroid Build Coastguard Worker# Each domain gets a unique devpts type.
522*e4a36f41SAndroid Build Coastguard Workertype $1_devpts, fs_type;
523*e4a36f41SAndroid Build Coastguard Worker# Label the pty with the unique type when created.
524*e4a36f41SAndroid Build Coastguard Workertype_transition $1 devpts:chr_file $1_devpts;
525*e4a36f41SAndroid Build Coastguard Worker# Allow use of the pty after creation.
526*e4a36f41SAndroid Build Coastguard Workerallow $1 $1_devpts:chr_file { open getattr read write ioctl };
527*e4a36f41SAndroid Build Coastguard Workerallowxperm $1 $1_devpts:chr_file ioctl unpriv_tty_ioctls;
528*e4a36f41SAndroid Build Coastguard Worker# TIOCSTI is only ever used for exploits. Block it.
529*e4a36f41SAndroid Build Coastguard Worker# b/33073072, b/7530569
530*e4a36f41SAndroid Build Coastguard Worker# http://www.openwall.com/lists/oss-security/2016/09/26/14
531*e4a36f41SAndroid Build Coastguard Workerneverallowxperm * $1_devpts:chr_file ioctl TIOCSTI;
532*e4a36f41SAndroid Build Coastguard Worker# Note: devpts:dir search and ptmx_device:chr_file rw_file_perms
533*e4a36f41SAndroid Build Coastguard Worker# allowed to everyone via domain.te.
534*e4a36f41SAndroid Build Coastguard Worker')
535*e4a36f41SAndroid Build Coastguard Worker
536*e4a36f41SAndroid Build Coastguard Worker#####################################
537*e4a36f41SAndroid Build Coastguard Worker# Non system_app application set
538*e4a36f41SAndroid Build Coastguard Worker#
539*e4a36f41SAndroid Build Coastguard Workerdefine(`non_system_app_set', `{ appdomain -system_app }')
540*e4a36f41SAndroid Build Coastguard Worker
541*e4a36f41SAndroid Build Coastguard Worker#####################################
542*e4a36f41SAndroid Build Coastguard Worker# Recovery only
543*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply only to recovery mode
544*e4a36f41SAndroid Build Coastguard Worker#
545*e4a36f41SAndroid Build Coastguard Workerdefine(`recovery_only', ifelse(target_recovery, `true', $1, ))
546*e4a36f41SAndroid Build Coastguard Worker
547*e4a36f41SAndroid Build Coastguard Worker#####################################
548*e4a36f41SAndroid Build Coastguard Worker# Not recovery
549*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply only to non-recovery (normal) mode
550*e4a36f41SAndroid Build Coastguard Worker#
551*e4a36f41SAndroid Build Coastguard Workerdefine(`not_recovery', ifelse(target_recovery, `true', , $1))
552*e4a36f41SAndroid Build Coastguard Worker
553*e4a36f41SAndroid Build Coastguard Worker#####################################
554*e4a36f41SAndroid Build Coastguard Worker# Full TREBLE only
555*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply only to full TREBLE devices
556*e4a36f41SAndroid Build Coastguard Worker#
557*e4a36f41SAndroid Build Coastguard Workerdefine(`full_treble_only', ifelse(target_full_treble, `true', $1,
558*e4a36f41SAndroid Build Coastguard Workerifelse(target_full_treble, `cts',
559*e4a36f41SAndroid Build Coastguard Worker# BEGIN_TREBLE_ONLY -- this marker is used by CTS -- do not modify
560*e4a36f41SAndroid Build Coastguard Worker$1
561*e4a36f41SAndroid Build Coastguard Worker# END_TREBLE_ONLY -- this marker is used by CTS -- do not modify
562*e4a36f41SAndroid Build Coastguard Worker, )))
563*e4a36f41SAndroid Build Coastguard Worker
564*e4a36f41SAndroid Build Coastguard Worker#####################################
565*e4a36f41SAndroid Build Coastguard Worker# Not full TREBLE
566*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply only to devices which are not full TREBLE devices
567*e4a36f41SAndroid Build Coastguard Worker#
568*e4a36f41SAndroid Build Coastguard Workerdefine(`not_full_treble', ifelse(target_full_treble, `true', , $1))
569*e4a36f41SAndroid Build Coastguard Worker
570*e4a36f41SAndroid Build Coastguard Worker#####################################
571*e4a36f41SAndroid Build Coastguard Worker# enforce_debugfs_restriction
572*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply to devices that enable debugfs restrictions.
573*e4a36f41SAndroid Build Coastguard Worker# The keyword "cts" is used to insert markers to only CTS test the neverallows
574*e4a36f41SAndroid Build Coastguard Worker# added by the macro for S-launch devices and newer.
575*e4a36f41SAndroid Build Coastguard Workerdefine(`enforce_debugfs_restriction', ifelse(target_enforce_debugfs_restriction, `true', $1,
576*e4a36f41SAndroid Build Coastguard Workerifelse(target_enforce_debugfs_restriction, `cts',
577*e4a36f41SAndroid Build Coastguard Worker# BEGIN_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify
578*e4a36f41SAndroid Build Coastguard Worker$1
579*e4a36f41SAndroid Build Coastguard Worker# END_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify
580*e4a36f41SAndroid Build Coastguard Worker, )))
581*e4a36f41SAndroid Build Coastguard Worker
582*e4a36f41SAndroid Build Coastguard Worker#####################################
583*e4a36f41SAndroid Build Coastguard Worker# no_debugfs_restriction
584*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply to devices that do not have debugfs restrictions in non-user builds.
585*e4a36f41SAndroid Build Coastguard Workerdefine(`no_debugfs_restriction', ifelse(target_enforce_debugfs_restriction, `true', , $1))
586*e4a36f41SAndroid Build Coastguard Worker
587*e4a36f41SAndroid Build Coastguard Worker#####################################
588*e4a36f41SAndroid Build Coastguard Worker# Compatible property only
589*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply only to devices with compatible property
590*e4a36f41SAndroid Build Coastguard Worker#
591*e4a36f41SAndroid Build Coastguard Workerdefine(`compatible_property_only', ifelse(target_compatible_property, `true', $1,
592*e4a36f41SAndroid Build Coastguard Workerifelse(target_compatible_property, `cts',
593*e4a36f41SAndroid Build Coastguard Worker# BEGIN_COMPATIBLE_PROPERTY_ONLY -- this marker is used by CTS -- do not modify
594*e4a36f41SAndroid Build Coastguard Worker$1
595*e4a36f41SAndroid Build Coastguard Worker# END_COMPATIBLE_PROPERTY_ONLY -- this marker is used by CTS -- do not modify
596*e4a36f41SAndroid Build Coastguard Worker, )))
597*e4a36f41SAndroid Build Coastguard Worker
598*e4a36f41SAndroid Build Coastguard Worker#####################################
599*e4a36f41SAndroid Build Coastguard Worker# Not compatible property
600*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply only to devices without compatible property
601*e4a36f41SAndroid Build Coastguard Worker#
602*e4a36f41SAndroid Build Coastguard Workerdefine(`not_compatible_property', ifelse(target_compatible_property, `true', , $1))
603*e4a36f41SAndroid Build Coastguard Worker
604*e4a36f41SAndroid Build Coastguard Worker#####################################
605*e4a36f41SAndroid Build Coastguard Worker# Userdebug or eng builds
606*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply only to userdebug or eng builds
607*e4a36f41SAndroid Build Coastguard Worker#
608*e4a36f41SAndroid Build Coastguard Workerdefine(`userdebug_or_eng', ifelse(target_build_variant, `eng', $1, ifelse(target_build_variant, `userdebug', $1)))
609*e4a36f41SAndroid Build Coastguard Worker
610*e4a36f41SAndroid Build Coastguard Worker#####################################
611*e4a36f41SAndroid Build Coastguard Worker# asan builds
612*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply only to asan builds
613*e4a36f41SAndroid Build Coastguard Worker#
614*e4a36f41SAndroid Build Coastguard Workerdefine(`with_asan', ifelse(target_with_asan, `true', userdebug_or_eng(`$1'), ))
615*e4a36f41SAndroid Build Coastguard Worker
616*e4a36f41SAndroid Build Coastguard Worker#####################################
617*e4a36f41SAndroid Build Coastguard Worker# native coverage builds
618*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply only to builds with native coverage
619*e4a36f41SAndroid Build Coastguard Worker#
620*e4a36f41SAndroid Build Coastguard Workerdefine(`with_native_coverage', ifelse(target_with_native_coverage, `true', userdebug_or_eng(`$1'), ))
621*e4a36f41SAndroid Build Coastguard Worker
622*e4a36f41SAndroid Build Coastguard Worker#####################################
623*e4a36f41SAndroid Build Coastguard Worker# Build-time-only test
624*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which are verified during build, but not as part of *TS testing.
625*e4a36f41SAndroid Build Coastguard Worker#
626*e4a36f41SAndroid Build Coastguard Workerdefine(`build_test_only', ifelse(target_exclude_build_test, `true', , $1))
627*e4a36f41SAndroid Build Coastguard Worker
628*e4a36f41SAndroid Build Coastguard Worker####################################
629*e4a36f41SAndroid Build Coastguard Worker# Fallback crash handling for processes that can't exec crash_dump (e.g. because of seccomp).
630*e4a36f41SAndroid Build Coastguard Worker#
631*e4a36f41SAndroid Build Coastguard Workerdefine(`crash_dump_fallback', `
632*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
633*e4a36f41SAndroid Build Coastguard Worker  allow $1 su:fifo_file append;
634*e4a36f41SAndroid Build Coastguard Worker')
635*e4a36f41SAndroid Build Coastguard Workerallow $1 anr_data_file:file append;
636*e4a36f41SAndroid Build Coastguard Workerallow $1 dumpstate:fd use;
637*e4a36f41SAndroid Build Coastguard Workerallow $1 incidentd:fd use;
638*e4a36f41SAndroid Build Coastguard Worker# TODO: Figure out why write is needed.
639*e4a36f41SAndroid Build Coastguard Workerallow $1 dumpstate:fifo_file { append write };
640*e4a36f41SAndroid Build Coastguard Workerallow $1 incidentd:fifo_file { append write };
641*e4a36f41SAndroid Build Coastguard Workerallow $1 system_server:fifo_file { append write };
642*e4a36f41SAndroid Build Coastguard Workerallow $1 tombstoned:unix_stream_socket connectto;
643*e4a36f41SAndroid Build Coastguard Workerallow $1 tombstoned:fd use;
644*e4a36f41SAndroid Build Coastguard Workerallow $1 tombstoned_crash_socket:sock_file write;
645*e4a36f41SAndroid Build Coastguard Workerallow $1 tombstone_data_file:file append;
646*e4a36f41SAndroid Build Coastguard Worker')
647*e4a36f41SAndroid Build Coastguard Worker
648*e4a36f41SAndroid Build Coastguard Worker#####################################
649*e4a36f41SAndroid Build Coastguard Worker# WITH_DEXPREOPT builds
650*e4a36f41SAndroid Build Coastguard Worker# SELinux rules which apply only when pre-opting.
651*e4a36f41SAndroid Build Coastguard Worker#
652*e4a36f41SAndroid Build Coastguard Workerdefine(`with_dexpreopt', ifelse(target_with_dexpreopt, `true', $1))
653*e4a36f41SAndroid Build Coastguard Worker
654*e4a36f41SAndroid Build Coastguard Worker#####################################
655*e4a36f41SAndroid Build Coastguard Worker# write_logd(domain)
656*e4a36f41SAndroid Build Coastguard Worker# Ability to write to android log
657*e4a36f41SAndroid Build Coastguard Worker# daemon via sockets
658*e4a36f41SAndroid Build Coastguard Workerdefine(`write_logd', `
659*e4a36f41SAndroid Build Coastguard Workerunix_socket_send($1, logdw, logd)
660*e4a36f41SAndroid Build Coastguard Workerallow $1 pmsg_device:chr_file w_file_perms;
661*e4a36f41SAndroid Build Coastguard Worker')
662*e4a36f41SAndroid Build Coastguard Worker
663*e4a36f41SAndroid Build Coastguard Worker#####################################
664*e4a36f41SAndroid Build Coastguard Worker# read_logd(domain)
665*e4a36f41SAndroid Build Coastguard Worker# Ability to run logcat and read from android
666*e4a36f41SAndroid Build Coastguard Worker# log daemon via sockets
667*e4a36f41SAndroid Build Coastguard Workerdefine(`read_logd', `
668*e4a36f41SAndroid Build Coastguard Workerallow $1 logcat_exec:file rx_file_perms;
669*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect($1, logdr, logd)
670*e4a36f41SAndroid Build Coastguard Worker')
671*e4a36f41SAndroid Build Coastguard Worker
672*e4a36f41SAndroid Build Coastguard Worker#####################################
673*e4a36f41SAndroid Build Coastguard Worker# read_runtime_log_tags(domain)
674*e4a36f41SAndroid Build Coastguard Worker# ability to directly map the runtime event log tags
675*e4a36f41SAndroid Build Coastguard Workerdefine(`read_runtime_log_tags', `
676*e4a36f41SAndroid Build Coastguard Workerallow $1 runtime_event_log_tags_file:file r_file_perms;
677*e4a36f41SAndroid Build Coastguard Worker')
678*e4a36f41SAndroid Build Coastguard Worker
679*e4a36f41SAndroid Build Coastguard Worker#####################################
680*e4a36f41SAndroid Build Coastguard Worker# control_logd(domain)
681*e4a36f41SAndroid Build Coastguard Worker# Ability to control
682*e4a36f41SAndroid Build Coastguard Worker# android log daemon via sockets
683*e4a36f41SAndroid Build Coastguard Workerdefine(`control_logd', `
684*e4a36f41SAndroid Build Coastguard Worker# Group AID_LOG checked by filesystem & logd
685*e4a36f41SAndroid Build Coastguard Worker# to permit control commands
686*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect($1, logd, logd)
687*e4a36f41SAndroid Build Coastguard Worker')
688*e4a36f41SAndroid Build Coastguard Worker
689*e4a36f41SAndroid Build Coastguard Worker#####################################
690*e4a36f41SAndroid Build Coastguard Worker# use_keystore(domain)
691*e4a36f41SAndroid Build Coastguard Worker# Ability to use keystore.
692*e4a36f41SAndroid Build Coastguard Worker# Keystore is requires the following permissions
693*e4a36f41SAndroid Build Coastguard Worker# to call getpidcon.
694*e4a36f41SAndroid Build Coastguard Workerdefine(`use_keystore', `
695*e4a36f41SAndroid Build Coastguard Worker  allow keystore $1:dir search;
696*e4a36f41SAndroid Build Coastguard Worker  allow keystore $1:file { read open };
697*e4a36f41SAndroid Build Coastguard Worker  allow keystore $1:process getattr;
698*e4a36f41SAndroid Build Coastguard Worker  allow $1 apc_service:service_manager find;
699*e4a36f41SAndroid Build Coastguard Worker  allow $1 keystore_service:service_manager find;
700*e4a36f41SAndroid Build Coastguard Worker  allow $1 legacykeystore_service:service_manager find;
701*e4a36f41SAndroid Build Coastguard Worker  binder_call($1, keystore)
702*e4a36f41SAndroid Build Coastguard Worker  binder_call(keystore, $1)
703*e4a36f41SAndroid Build Coastguard Worker')
704*e4a36f41SAndroid Build Coastguard Worker
705*e4a36f41SAndroid Build Coastguard Worker#####################################
706*e4a36f41SAndroid Build Coastguard Worker# use_credstore(domain)
707*e4a36f41SAndroid Build Coastguard Worker# Ability to use credstore.
708*e4a36f41SAndroid Build Coastguard Workerdefine(`use_credstore', `
709*e4a36f41SAndroid Build Coastguard Worker  allow credstore $1:dir search;
710*e4a36f41SAndroid Build Coastguard Worker  allow credstore $1:file { read open };
711*e4a36f41SAndroid Build Coastguard Worker  allow credstore $1:process getattr;
712*e4a36f41SAndroid Build Coastguard Worker  allow $1 credstore_service:service_manager find;
713*e4a36f41SAndroid Build Coastguard Worker  binder_call($1, credstore)
714*e4a36f41SAndroid Build Coastguard Worker  binder_call(credstore, $1)
715*e4a36f41SAndroid Build Coastguard Worker')
716*e4a36f41SAndroid Build Coastguard Worker
717*e4a36f41SAndroid Build Coastguard Worker###########################################
718*e4a36f41SAndroid Build Coastguard Worker# use_drmservice(domain)
719*e4a36f41SAndroid Build Coastguard Worker# Ability to use DrmService which requires
720*e4a36f41SAndroid Build Coastguard Worker# DrmService to call getpidcon.
721*e4a36f41SAndroid Build Coastguard Workerdefine(`use_drmservice', `
722*e4a36f41SAndroid Build Coastguard Worker  allow drmserver $1:dir search;
723*e4a36f41SAndroid Build Coastguard Worker  allow drmserver $1:file { read open };
724*e4a36f41SAndroid Build Coastguard Worker  allow drmserver $1:process getattr;
725*e4a36f41SAndroid Build Coastguard Worker')
726*e4a36f41SAndroid Build Coastguard Worker
727*e4a36f41SAndroid Build Coastguard Worker###########################################
728*e4a36f41SAndroid Build Coastguard Worker# add_service(domain, service)
729*e4a36f41SAndroid Build Coastguard Worker# Ability for domain to add a service to service_manager
730*e4a36f41SAndroid Build Coastguard Worker# and find it. It also creates a neverallow preventing
731*e4a36f41SAndroid Build Coastguard Worker# others from adding it.
732*e4a36f41SAndroid Build Coastguard Workerdefine(`add_service', `
733*e4a36f41SAndroid Build Coastguard Worker  allow $1 $2:service_manager { add find };
734*e4a36f41SAndroid Build Coastguard Worker  neverallow { domain -$1 } $2:service_manager add;
735*e4a36f41SAndroid Build Coastguard Worker
736*e4a36f41SAndroid Build Coastguard Worker  # On debug builds with root, allow binder services to use binder over TCP.
737*e4a36f41SAndroid Build Coastguard Worker  # Not using rw_socket_perms_no_ioctl to avoid granting too many permissions.
738*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`
739*e4a36f41SAndroid Build Coastguard Worker    allow $1 su:tcp_socket { accept getopt read write };
740*e4a36f41SAndroid Build Coastguard Worker  ')
741*e4a36f41SAndroid Build Coastguard Worker')
742*e4a36f41SAndroid Build Coastguard Worker
743*e4a36f41SAndroid Build Coastguard Worker###########################################
744*e4a36f41SAndroid Build Coastguard Worker# add_hwservice(domain, service)
745*e4a36f41SAndroid Build Coastguard Worker# Ability for domain to add a service to hwservice_manager
746*e4a36f41SAndroid Build Coastguard Worker# and find it. It also creates a neverallow preventing
747*e4a36f41SAndroid Build Coastguard Worker# others from adding it.
748*e4a36f41SAndroid Build Coastguard Workerdefine(`add_hwservice', `
749*e4a36f41SAndroid Build Coastguard Worker  allow $1 $2:hwservice_manager { add find };
750*e4a36f41SAndroid Build Coastguard Worker  allow $1 hidl_base_hwservice:hwservice_manager add;
751*e4a36f41SAndroid Build Coastguard Worker  neverallow { domain -$1 } $2:hwservice_manager add;
752*e4a36f41SAndroid Build Coastguard Worker')
753*e4a36f41SAndroid Build Coastguard Worker
754*e4a36f41SAndroid Build Coastguard Worker###########################################
755*e4a36f41SAndroid Build Coastguard Worker# hal_attribute_hwservice(attribute, service)
756*e4a36f41SAndroid Build Coastguard Worker# Ability for domain to get a service to hwservice_manager
757*e4a36f41SAndroid Build Coastguard Worker# and find it. It also creates a neverallow preventing
758*e4a36f41SAndroid Build Coastguard Worker# others from adding it.
759*e4a36f41SAndroid Build Coastguard Worker#
760*e4a36f41SAndroid Build Coastguard Worker# Used to pair hal_foo_client with hal_foo_hwservice
761*e4a36f41SAndroid Build Coastguard Workerdefine(`hal_attribute_hwservice', `
762*e4a36f41SAndroid Build Coastguard Worker  allow $1_client $2:hwservice_manager find;
763*e4a36f41SAndroid Build Coastguard Worker  add_hwservice($1_server, $2)
764*e4a36f41SAndroid Build Coastguard Worker
765*e4a36f41SAndroid Build Coastguard Worker  build_test_only(`
766*e4a36f41SAndroid Build Coastguard Worker    # if you are hitting this neverallow, try using:
767*e4a36f41SAndroid Build Coastguard Worker    #     hal_client_domain(<your domain>, hal_<foo>)
768*e4a36f41SAndroid Build Coastguard Worker    # instead
769*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -$1_client -$1_server } $2:hwservice_manager find;
770*e4a36f41SAndroid Build Coastguard Worker  ')
771*e4a36f41SAndroid Build Coastguard Worker')
772*e4a36f41SAndroid Build Coastguard Worker
773*e4a36f41SAndroid Build Coastguard Worker###########################################
774*e4a36f41SAndroid Build Coastguard Worker# hal_attribute_service(attribute, service)
775*e4a36f41SAndroid Build Coastguard Worker# Ability for domain to get a service to service_manager
776*e4a36f41SAndroid Build Coastguard Worker# and find it. It also creates a neverallow preventing
777*e4a36f41SAndroid Build Coastguard Worker# others from adding it.
778*e4a36f41SAndroid Build Coastguard Worker#
779*e4a36f41SAndroid Build Coastguard Worker# Used to pair hal_foo_client with hal_foo_service
780*e4a36f41SAndroid Build Coastguard Workerdefine(`hal_attribute_service', `
781*e4a36f41SAndroid Build Coastguard Worker  allow $1_client $2:service_manager find;
782*e4a36f41SAndroid Build Coastguard Worker  add_service($1_server, $2)
783*e4a36f41SAndroid Build Coastguard Worker
784*e4a36f41SAndroid Build Coastguard Worker  build_test_only(`
785*e4a36f41SAndroid Build Coastguard Worker    # if you are hitting this neverallow, try using:
786*e4a36f41SAndroid Build Coastguard Worker    #     hal_client_domain(<your domain>, hal_<foo>)
787*e4a36f41SAndroid Build Coastguard Worker    # instead
788*e4a36f41SAndroid Build Coastguard Worker    neverallow {
789*e4a36f41SAndroid Build Coastguard Worker        domain
790*e4a36f41SAndroid Build Coastguard Worker        -$1_client
791*e4a36f41SAndroid Build Coastguard Worker        -$1_server
792*e4a36f41SAndroid Build Coastguard Worker        # some services are allowed to find all services
793*e4a36f41SAndroid Build Coastguard Worker        -atrace
794*e4a36f41SAndroid Build Coastguard Worker        -shell
795*e4a36f41SAndroid Build Coastguard Worker        -system_app
796*e4a36f41SAndroid Build Coastguard Worker        -traceur_app
797*e4a36f41SAndroid Build Coastguard Worker    } $2:service_manager find;
798*e4a36f41SAndroid Build Coastguard Worker  ')
799*e4a36f41SAndroid Build Coastguard Worker')
800*e4a36f41SAndroid Build Coastguard Worker
801*e4a36f41SAndroid Build Coastguard Worker###################################
802*e4a36f41SAndroid Build Coastguard Worker# can_profile_heap(domain)
803*e4a36f41SAndroid Build Coastguard Worker# Allow processes within the domain to have their heap profiled by central
804*e4a36f41SAndroid Build Coastguard Worker# heapprofd.
805*e4a36f41SAndroid Build Coastguard Workerdefine(`can_profile_heap', `
806*e4a36f41SAndroid Build Coastguard Worker  # Allow central daemon to send signal for client initialization.
807*e4a36f41SAndroid Build Coastguard Worker  allow heapprofd $1:process signal;
808*e4a36f41SAndroid Build Coastguard Worker  # Allow connecting to the daemon.
809*e4a36f41SAndroid Build Coastguard Worker  unix_socket_connect($1, heapprofd, heapprofd)
810*e4a36f41SAndroid Build Coastguard Worker  # Allow daemon to use the passed fds.
811*e4a36f41SAndroid Build Coastguard Worker  allow heapprofd $1:fd use;
812*e4a36f41SAndroid Build Coastguard Worker  # Allow to read and write to heapprofd shmem.
813*e4a36f41SAndroid Build Coastguard Worker  # The client needs to read the read and write pointers in order to write.
814*e4a36f41SAndroid Build Coastguard Worker  allow $1 heapprofd_tmpfs:file { read write getattr map };
815*e4a36f41SAndroid Build Coastguard Worker  # Use shared memory received over the unix socket.
816*e4a36f41SAndroid Build Coastguard Worker  allow $1 heapprofd:fd use;
817*e4a36f41SAndroid Build Coastguard Worker
818*e4a36f41SAndroid Build Coastguard Worker  # To read and write from the received file descriptors.
819*e4a36f41SAndroid Build Coastguard Worker  # /proc/[pid]/maps and /proc/[pid]/mem have the same SELinux label as the
820*e4a36f41SAndroid Build Coastguard Worker  # process they relate to.
821*e4a36f41SAndroid Build Coastguard Worker  # We need to write to /proc/$PID/page_idle to find idle allocations.
822*e4a36f41SAndroid Build Coastguard Worker  # The client only opens /proc/self/page_idle with RDWR, everything else
823*e4a36f41SAndroid Build Coastguard Worker  # with RDONLY.
824*e4a36f41SAndroid Build Coastguard Worker  # heapprofd cannot open /proc/$PID/mem itself, as it does not have
825*e4a36f41SAndroid Build Coastguard Worker  # sys_ptrace.
826*e4a36f41SAndroid Build Coastguard Worker  allow heapprofd $1:file rw_file_perms;
827*e4a36f41SAndroid Build Coastguard Worker  # Allow searching the /proc/[pid] directory for cmdline.
828*e4a36f41SAndroid Build Coastguard Worker  allow heapprofd $1:dir r_dir_perms;
829*e4a36f41SAndroid Build Coastguard Worker')
830*e4a36f41SAndroid Build Coastguard Worker
831*e4a36f41SAndroid Build Coastguard Worker###################################
832*e4a36f41SAndroid Build Coastguard Worker# never_profile_heap(domain)
833*e4a36f41SAndroid Build Coastguard Worker# Opt out of heap profiling by heapprofd.
834*e4a36f41SAndroid Build Coastguard Workerdefine(`never_profile_heap', `
835*e4a36f41SAndroid Build Coastguard Worker  neverallow heapprofd $1:file read;
836*e4a36f41SAndroid Build Coastguard Worker  neverallow heapprofd $1:process signal;
837*e4a36f41SAndroid Build Coastguard Worker')
838*e4a36f41SAndroid Build Coastguard Worker
839*e4a36f41SAndroid Build Coastguard Worker###################################
840*e4a36f41SAndroid Build Coastguard Worker# can_profile_perf(domain)
841*e4a36f41SAndroid Build Coastguard Worker# Allow processes within the domain to be profiled, and have their stacks
842*e4a36f41SAndroid Build Coastguard Worker# sampled, by traced_perf.
843*e4a36f41SAndroid Build Coastguard Workerdefine(`can_profile_perf', `
844*e4a36f41SAndroid Build Coastguard Worker  # Allow directory & file read to traced_perf, as it stat(2)s /proc/[pid], and
845*e4a36f41SAndroid Build Coastguard Worker  # reads /proc/[pid]/cmdline.
846*e4a36f41SAndroid Build Coastguard Worker  allow traced_perf $1:file r_file_perms;
847*e4a36f41SAndroid Build Coastguard Worker  allow traced_perf $1:dir r_dir_perms;
848*e4a36f41SAndroid Build Coastguard Worker
849*e4a36f41SAndroid Build Coastguard Worker  # Allow central daemon to send signal to request /proc/[pid]/maps and
850*e4a36f41SAndroid Build Coastguard Worker  # /proc/[pid]/mem fds from this process.
851*e4a36f41SAndroid Build Coastguard Worker  allow traced_perf $1:process signal;
852*e4a36f41SAndroid Build Coastguard Worker
853*e4a36f41SAndroid Build Coastguard Worker  # Allow connecting to the daemon.
854*e4a36f41SAndroid Build Coastguard Worker  unix_socket_connect($1, traced_perf, traced_perf)
855*e4a36f41SAndroid Build Coastguard Worker  # Allow daemon to use the passed fds.
856*e4a36f41SAndroid Build Coastguard Worker  allow traced_perf $1:fd use;
857*e4a36f41SAndroid Build Coastguard Worker')
858*e4a36f41SAndroid Build Coastguard Worker
859*e4a36f41SAndroid Build Coastguard Worker###################################
860*e4a36f41SAndroid Build Coastguard Worker# never_profile_perf(domain)
861*e4a36f41SAndroid Build Coastguard Worker# Opt out of profiling by traced_perf.
862*e4a36f41SAndroid Build Coastguard Workerdefine(`never_profile_perf', `
863*e4a36f41SAndroid Build Coastguard Worker  neverallow traced_perf $1:file read;
864*e4a36f41SAndroid Build Coastguard Worker  neverallow traced_perf $1:process signal;
865*e4a36f41SAndroid Build Coastguard Worker')
866*e4a36f41SAndroid Build Coastguard Worker
867*e4a36f41SAndroid Build Coastguard Worker###################################
868*e4a36f41SAndroid Build Coastguard Worker# perfetto_producer(domain)
869*e4a36f41SAndroid Build Coastguard Worker# Allow processes within the domain to write data to Perfetto.
870*e4a36f41SAndroid Build Coastguard Worker# When applying this macro, you might need to also allow traced to use the
871*e4a36f41SAndroid Build Coastguard Worker# producer tmpfs domain, if the producer will be the one creating the shared
872*e4a36f41SAndroid Build Coastguard Worker# memory.
873*e4a36f41SAndroid Build Coastguard Workerdefine(`perfetto_producer', `
874*e4a36f41SAndroid Build Coastguard Worker  allow $1 traced:fd use;
875*e4a36f41SAndroid Build Coastguard Worker  allow $1 traced_tmpfs:file { read write getattr map };
876*e4a36f41SAndroid Build Coastguard Worker  unix_socket_connect($1, traced_producer, traced)
877*e4a36f41SAndroid Build Coastguard Worker
878*e4a36f41SAndroid Build Coastguard Worker  # Also allow the service to use the producer file descriptors. This is
879*e4a36f41SAndroid Build Coastguard Worker  # necessary when the producer is creating the shared memory, as it will be
880*e4a36f41SAndroid Build Coastguard Worker  # passed to the service as a file descriptor (obtained from memfd_create).
881*e4a36f41SAndroid Build Coastguard Worker  allow traced $1:fd use;
882*e4a36f41SAndroid Build Coastguard Worker')
883*e4a36f41SAndroid Build Coastguard Worker
884*e4a36f41SAndroid Build Coastguard Worker###########################################
885*e4a36f41SAndroid Build Coastguard Worker# dump_hal(hal_type)
886*e4a36f41SAndroid Build Coastguard Worker# Ability to dump the hal debug info
887*e4a36f41SAndroid Build Coastguard Worker#
888*e4a36f41SAndroid Build Coastguard Workerdefine(`dump_hal', `
889*e4a36f41SAndroid Build Coastguard Worker  hal_client_domain(dumpstate, $1);
890*e4a36f41SAndroid Build Coastguard Worker  allow $1_server dumpstate:fifo_file write;
891*e4a36f41SAndroid Build Coastguard Worker  allow $1_server dumpstate:fd use;
892*e4a36f41SAndroid Build Coastguard Worker')
893*e4a36f41SAndroid Build Coastguard Worker
894*e4a36f41SAndroid Build Coastguard Worker#####################################
895*e4a36f41SAndroid Build Coastguard Worker# treble_sysprop_neverallow(rules)
896*e4a36f41SAndroid Build Coastguard Worker# SELinux neverallow rules which enforces the accessibility of each property
897*e4a36f41SAndroid Build Coastguard Worker# outside the owner.
898*e4a36f41SAndroid Build Coastguard Worker#
899*e4a36f41SAndroid Build Coastguard Worker# For devices launching with R or later, exported properties must be explicitly marked as
900*e4a36f41SAndroid Build Coastguard Worker# "restricted" or "public", depending on the accessibility outside the owner.
901*e4a36f41SAndroid Build Coastguard Worker# For devices launching with Q or eariler, this neverallow rules can be relaxed with defining
902*e4a36f41SAndroid Build Coastguard Worker# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true on BoardConfig.mk.
903*e4a36f41SAndroid Build Coastguard Worker# See {partition}_{accessibility}_prop macros below.
904*e4a36f41SAndroid Build Coastguard Worker#
905*e4a36f41SAndroid Build Coastguard Worker# CTS uses these rules only for devices launching with R or later.
906*e4a36f41SAndroid Build Coastguard Worker#
907*e4a36f41SAndroid Build Coastguard Worker# TODO(b/131162102): deprecate BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW
908*e4a36f41SAndroid Build Coastguard Worker#
909*e4a36f41SAndroid Build Coastguard Workerdefine(`treble_sysprop_neverallow', ifelse(target_treble_sysprop_neverallow, `true', $1,
910*e4a36f41SAndroid Build Coastguard Workerifelse(target_treble_sysprop_neverallow, `cts',
911*e4a36f41SAndroid Build Coastguard Worker# BEGIN_LAUNCHING_WITH_R_ONLY -- this marker is used by CTS -- do not modify
912*e4a36f41SAndroid Build Coastguard Worker$1
913*e4a36f41SAndroid Build Coastguard Worker# END_LAUNCHING_WITH_R_ONLY -- this marker is used by CTS -- do not modify
914*e4a36f41SAndroid Build Coastguard Worker, )))
915*e4a36f41SAndroid Build Coastguard Worker
916*e4a36f41SAndroid Build Coastguard Worker#####################################
917*e4a36f41SAndroid Build Coastguard Worker# enforce_sysprop_owner(rules)
918*e4a36f41SAndroid Build Coastguard Worker# SELinux neverallow rules which enforces the owner of each property.
919*e4a36f41SAndroid Build Coastguard Worker#
920*e4a36f41SAndroid Build Coastguard Worker# For devices launching with S or later, all properties must be explicitly marked as one of:
921*e4a36f41SAndroid Build Coastguard Worker# system_property_type, vendor_property_type, or product_property_type.
922*e4a36f41SAndroid Build Coastguard Worker# For devices launching with R or eariler, this neverallow rules can be relaxed with defining
923*e4a36f41SAndroid Build Coastguard Worker# BUILD_BROKEN_ENFORCE_SYSPROP_OWNER := true on BoardConfig.mk.
924*e4a36f41SAndroid Build Coastguard Worker# See {partition}_{accessibility}_prop macros below.
925*e4a36f41SAndroid Build Coastguard Worker#
926*e4a36f41SAndroid Build Coastguard Worker# CTS uses these ules only for devices launching with S or later.
927*e4a36f41SAndroid Build Coastguard Worker#
928*e4a36f41SAndroid Build Coastguard Workerdefine(`enforce_sysprop_owner', ifelse(target_enforce_sysprop_owner, `true', $1,
929*e4a36f41SAndroid Build Coastguard Workerifelse(target_enforce_sysprop_owner, `cts',
930*e4a36f41SAndroid Build Coastguard Worker# BEGIN_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify
931*e4a36f41SAndroid Build Coastguard Worker$1
932*e4a36f41SAndroid Build Coastguard Worker# END_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify
933*e4a36f41SAndroid Build Coastguard Worker, )))
934*e4a36f41SAndroid Build Coastguard Worker
935*e4a36f41SAndroid Build Coastguard Worker###########################################
936*e4a36f41SAndroid Build Coastguard Worker# define_prop(name, owner, scope)
937*e4a36f41SAndroid Build Coastguard Worker# Define a property with given owner and scope
938*e4a36f41SAndroid Build Coastguard Worker#
939*e4a36f41SAndroid Build Coastguard Workerdefine(`define_prop', `
940*e4a36f41SAndroid Build Coastguard Worker  type $1, property_type, $2_property_type, $2_$3_property_type;
941*e4a36f41SAndroid Build Coastguard Worker')
942*e4a36f41SAndroid Build Coastguard Worker
943*e4a36f41SAndroid Build Coastguard Worker###########################################
944*e4a36f41SAndroid Build Coastguard Worker# system_internal_prop(name)
945*e4a36f41SAndroid Build Coastguard Worker# Define a /system-owned property used only in /system
946*e4a36f41SAndroid Build Coastguard Worker# For devices launching with Q or eariler, this restriction can be relaxed with
947*e4a36f41SAndroid Build Coastguard Worker# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true
948*e4a36f41SAndroid Build Coastguard Worker#
949*e4a36f41SAndroid Build Coastguard Workerdefine(`system_internal_prop', `
950*e4a36f41SAndroid Build Coastguard Worker  define_prop($1, system, internal)
951*e4a36f41SAndroid Build Coastguard Worker  treble_sysprop_neverallow(`
952*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -coredomain } $1:file no_rw_file_perms;
953*e4a36f41SAndroid Build Coastguard Worker  ')
954*e4a36f41SAndroid Build Coastguard Worker')
955*e4a36f41SAndroid Build Coastguard Worker
956*e4a36f41SAndroid Build Coastguard Worker###########################################
957*e4a36f41SAndroid Build Coastguard Worker# system_restricted_prop(name)
958*e4a36f41SAndroid Build Coastguard Worker# Define a /system-owned property which can't be written outside /system
959*e4a36f41SAndroid Build Coastguard Worker# For devices launching with Q or eariler, this restriction can be relaxed with
960*e4a36f41SAndroid Build Coastguard Worker# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true
961*e4a36f41SAndroid Build Coastguard Worker#
962*e4a36f41SAndroid Build Coastguard Workerdefine(`system_restricted_prop', `
963*e4a36f41SAndroid Build Coastguard Worker  define_prop($1, system, restricted)
964*e4a36f41SAndroid Build Coastguard Worker  treble_sysprop_neverallow(`
965*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -coredomain } $1:property_service set;
966*e4a36f41SAndroid Build Coastguard Worker  ')
967*e4a36f41SAndroid Build Coastguard Worker')
968*e4a36f41SAndroid Build Coastguard Worker
969*e4a36f41SAndroid Build Coastguard Worker###########################################
970*e4a36f41SAndroid Build Coastguard Worker# system_public_prop(name)
971*e4a36f41SAndroid Build Coastguard Worker# Define a /system-owned property with no restrictions
972*e4a36f41SAndroid Build Coastguard Worker#
973*e4a36f41SAndroid Build Coastguard Workerdefine(`system_public_prop', `define_prop($1, system, public)')
974*e4a36f41SAndroid Build Coastguard Worker
975*e4a36f41SAndroid Build Coastguard Worker###########################################
976*e4a36f41SAndroid Build Coastguard Worker# system_vendor_config_prop(name)
977*e4a36f41SAndroid Build Coastguard Worker# Define a /system-owned property which can only be written by vendor_init
978*e4a36f41SAndroid Build Coastguard Worker# This is a macro for vendor-specific configuration properties which is meant
979*e4a36f41SAndroid Build Coastguard Worker# to be set once from vendor_init.
980*e4a36f41SAndroid Build Coastguard Worker#
981*e4a36f41SAndroid Build Coastguard Workerdefine(`system_vendor_config_prop', `
982*e4a36f41SAndroid Build Coastguard Worker  system_public_prop($1)
983*e4a36f41SAndroid Build Coastguard Worker  set_prop(vendor_init, $1)
984*e4a36f41SAndroid Build Coastguard Worker  neverallow { domain -init -vendor_init } $1:property_service set;
985*e4a36f41SAndroid Build Coastguard Worker')
986*e4a36f41SAndroid Build Coastguard Worker
987*e4a36f41SAndroid Build Coastguard Worker###########################################
988*e4a36f41SAndroid Build Coastguard Worker# product_internal_prop(name)
989*e4a36f41SAndroid Build Coastguard Worker# Define a /product-owned property used only in /product
990*e4a36f41SAndroid Build Coastguard Worker# For devices launching with Q or eariler, this restriction can be relaxed with
991*e4a36f41SAndroid Build Coastguard Worker# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true
992*e4a36f41SAndroid Build Coastguard Worker#
993*e4a36f41SAndroid Build Coastguard Workerdefine(`product_internal_prop', `
994*e4a36f41SAndroid Build Coastguard Worker  define_prop($1, product, internal)
995*e4a36f41SAndroid Build Coastguard Worker  treble_sysprop_neverallow(`
996*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -coredomain } $1:file no_rw_file_perms;
997*e4a36f41SAndroid Build Coastguard Worker  ')
998*e4a36f41SAndroid Build Coastguard Worker')
999*e4a36f41SAndroid Build Coastguard Worker
1000*e4a36f41SAndroid Build Coastguard Worker###########################################
1001*e4a36f41SAndroid Build Coastguard Worker# product_restricted_prop(name)
1002*e4a36f41SAndroid Build Coastguard Worker# Define a /product-owned property which can't be written outside /product
1003*e4a36f41SAndroid Build Coastguard Worker# For devices launching with Q or eariler, this restriction can be relaxed with
1004*e4a36f41SAndroid Build Coastguard Worker# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true
1005*e4a36f41SAndroid Build Coastguard Worker#
1006*e4a36f41SAndroid Build Coastguard Workerdefine(`product_restricted_prop', `
1007*e4a36f41SAndroid Build Coastguard Worker  define_prop($1, product, restricted)
1008*e4a36f41SAndroid Build Coastguard Worker  treble_sysprop_neverallow(`
1009*e4a36f41SAndroid Build Coastguard Worker    neverallow { domain -coredomain } $1:property_service set;
1010*e4a36f41SAndroid Build Coastguard Worker  ')
1011*e4a36f41SAndroid Build Coastguard Worker')
1012*e4a36f41SAndroid Build Coastguard Worker
1013*e4a36f41SAndroid Build Coastguard Worker###########################################
1014*e4a36f41SAndroid Build Coastguard Worker# product_public_prop(name)
1015*e4a36f41SAndroid Build Coastguard Worker# Define a /product-owned property with no restrictions
1016*e4a36f41SAndroid Build Coastguard Worker#
1017*e4a36f41SAndroid Build Coastguard Workerdefine(`product_public_prop', `define_prop($1, product, public)')
1018*e4a36f41SAndroid Build Coastguard Worker
1019*e4a36f41SAndroid Build Coastguard Worker###########################################
1020*e4a36f41SAndroid Build Coastguard Worker# vendor_internal_prop(name)
1021*e4a36f41SAndroid Build Coastguard Worker# Define a /vendor-owned property used only in /vendor
1022*e4a36f41SAndroid Build Coastguard Worker# For devices launching with Q or eariler, this restriction can be relaxed with
1023*e4a36f41SAndroid Build Coastguard Worker# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true
1024*e4a36f41SAndroid Build Coastguard Worker#
1025*e4a36f41SAndroid Build Coastguard Workerdefine(`vendor_internal_prop', `
1026*e4a36f41SAndroid Build Coastguard Worker  define_prop($1, vendor, internal)
1027*e4a36f41SAndroid Build Coastguard Worker  treble_sysprop_neverallow(`
1028*e4a36f41SAndroid Build Coastguard Worker# init and dumpstate are in coredomain, but should be able to read all props.
1029*e4a36f41SAndroid Build Coastguard Worker    neverallow { coredomain -init -dumpstate } $1:file no_rw_file_perms;
1030*e4a36f41SAndroid Build Coastguard Worker  ')
1031*e4a36f41SAndroid Build Coastguard Worker')
1032*e4a36f41SAndroid Build Coastguard Worker
1033*e4a36f41SAndroid Build Coastguard Worker###########################################
1034*e4a36f41SAndroid Build Coastguard Worker# vendor_restricted_prop(name)
1035*e4a36f41SAndroid Build Coastguard Worker# Define a /vendor-owned property which can't be written outside /vendor
1036*e4a36f41SAndroid Build Coastguard Worker# For devices launching with Q or eariler, this restriction can be relaxed with
1037*e4a36f41SAndroid Build Coastguard Worker# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true
1038*e4a36f41SAndroid Build Coastguard Worker#
1039*e4a36f41SAndroid Build Coastguard Workerdefine(`vendor_restricted_prop', `
1040*e4a36f41SAndroid Build Coastguard Worker  define_prop($1, vendor, restricted)
1041*e4a36f41SAndroid Build Coastguard Worker  treble_sysprop_neverallow(`
1042*e4a36f41SAndroid Build Coastguard Worker# init is in coredomain, but should be able to write all props.
1043*e4a36f41SAndroid Build Coastguard Worker    neverallow { coredomain -init } $1:property_service set;
1044*e4a36f41SAndroid Build Coastguard Worker  ')
1045*e4a36f41SAndroid Build Coastguard Worker')
1046*e4a36f41SAndroid Build Coastguard Worker
1047*e4a36f41SAndroid Build Coastguard Worker###########################################
1048*e4a36f41SAndroid Build Coastguard Worker# vendor_public_prop(name)
1049*e4a36f41SAndroid Build Coastguard Worker# Define a /vendor-owned property with no restrictions
1050*e4a36f41SAndroid Build Coastguard Worker#
1051*e4a36f41SAndroid Build Coastguard Workerdefine(`vendor_public_prop', `define_prop($1, vendor, public)')
1052*e4a36f41SAndroid Build Coastguard Worker
1053*e4a36f41SAndroid Build Coastguard Worker#####################################
1054*e4a36f41SAndroid Build Coastguard Worker# read_fstab(domain)
1055*e4a36f41SAndroid Build Coastguard Worker# Ability to call ReadDefaultFstab() and ReadFstabFromFile().
1056*e4a36f41SAndroid Build Coastguard Worker#
1057*e4a36f41SAndroid Build Coastguard Workerdefine(`read_fstab', `
1058*e4a36f41SAndroid Build Coastguard Worker  allow $1 { metadata_file gsi_metadata_file_type }:dir search;
1059*e4a36f41SAndroid Build Coastguard Worker  allow $1 gsi_public_metadata_file:file r_file_perms;
1060*e4a36f41SAndroid Build Coastguard Worker  allow $1 { proc_bootconfig proc_cmdline }:file r_file_perms;
1061*e4a36f41SAndroid Build Coastguard Worker')
1062*e4a36f41SAndroid Build Coastguard Worker
1063*e4a36f41SAndroid Build Coastguard Worker######################################
1064*e4a36f41SAndroid Build Coastguard Worker# use_bootstrap_libs(domain)
1065*e4a36f41SAndroid Build Coastguard Worker# Allow domain to use bootstrap bionic libraries in system/lib[64]/bootstrap
1066*e4a36f41SAndroid Build Coastguard Workerdefine(`use_bootstrap_libs', `
1067*e4a36f41SAndroid Build Coastguard Worker  allow $1 system_bootstrap_lib_file:dir r_dir_perms;
1068*e4a36f41SAndroid Build Coastguard Worker  allow $1 system_bootstrap_lib_file:file { execute read open getattr map };
1069*e4a36f41SAndroid Build Coastguard Worker')
1070*e4a36f41SAndroid Build Coastguard Worker
1071*e4a36f41SAndroid Build Coastguard Worker######################################
1072*e4a36f41SAndroid Build Coastguard Worker# use_apex_info(domain)
1073*e4a36f41SAndroid Build Coastguard Worker# Allow access to apex information
1074*e4a36f41SAndroid Build Coastguard Workerdefine(`use_apex_info', `
1075*e4a36f41SAndroid Build Coastguard Worker  allow $1 apex_mnt_dir:dir r_dir_perms;
1076*e4a36f41SAndroid Build Coastguard Worker  allow $1 apex_info_file:file r_file_perms;
1077*e4a36f41SAndroid Build Coastguard Worker  r_dir_file($1, vendor_apex_metadata_file)
1078*e4a36f41SAndroid Build Coastguard Worker')
1079*e4a36f41SAndroid Build Coastguard Worker
1080*e4a36f41SAndroid Build Coastguard Worker####################################
1081*e4a36f41SAndroid Build Coastguard Worker# io_uring_use(domain)
1082*e4a36f41SAndroid Build Coastguard Worker# Allow domain to create/use io_uring.
1083*e4a36f41SAndroid Build Coastguard Workerdefine(`io_uring_use', `
1084*e4a36f41SAndroid Build Coastguard Worker# Set up a type_transition to "io_uring" named anonymous inode object.
1085*e4a36f41SAndroid Build Coastguard Workertype $1_iouring;
1086*e4a36f41SAndroid Build Coastguard Workertype_transition $1 $1:anon_inode $1_iouring "[io_uring]";
1087*e4a36f41SAndroid Build Coastguard Worker# Allow domain to create/use io_uring anon_inode.
1088*e4a36f41SAndroid Build Coastguard Workerallow $1 $1_iouring:anon_inode { create map read write };
1089*e4a36f41SAndroid Build Coastguard Workerallow $1 self:io_uring sqpoll;
1090*e4a36f41SAndroid Build Coastguard Worker# Other domains may not use iouring anon_inodes created by this domain.
1091*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -$1 } $1_iouring:anon_inode *;
1092*e4a36f41SAndroid Build Coastguard Worker# io_uring checks for CAP_IPC_LOCK to determine whether or not to track
1093*e4a36f41SAndroid Build Coastguard Worker# memory usage per uid against RLIMIT_MEMLOCK. This can lead folks to
1094*e4a36f41SAndroid Build Coastguard Worker# grant CAP_IPC_LOCK to silence avc denials, which is undesireable.
1095*e4a36f41SAndroid Build Coastguard Workerdontaudit $1 self:global_capability_class_set ipc_lock;
1096*e4a36f41SAndroid Build Coastguard Worker')
1097