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