blob: bb5da7c1e068c3f23f7763e806c117caac90c46e [file] [log] [blame]
Alex Klyubin92295ef2017-01-05 15:44:32 -08001###
2### A domain for further sandboxing privileged apps.
3###
4
Alex Klyubinf5446eb2017-03-23 14:27:32 -07005typeattribute priv_app coredomain;
dcashman3e8dbf02016-12-08 11:23:34 -08006app_domain(priv_app)
dcashman2e00e632016-10-12 14:58:09 -07007
Alex Klyubin92295ef2017-01-05 15:44:32 -08008# Access the network.
9net_domain(priv_app)
10# Access bluetooth.
11bluetooth_domain(priv_app)
12
dcashman2e00e632016-10-12 14:58:09 -070013# Allow the allocation and use of ptys
14# Used by: https://play.privileged.com/store/apps/details?id=jackpal.androidterm
15create_pty(priv_app)
Alex Klyubin92295ef2017-01-05 15:44:32 -080016
Nick Kraleviche1ddd742018-10-27 15:20:38 -070017# Allow loading executable code from writable priv-app home
18# directories. This is a W^X violation, however, it needs
19# to be supported for now for the following reasons.
20# * /data/user_*/0/*/code_cache/* POSSIBLE uses (b/117841367)
21# 1) com.android.opengl.shaders_cache
22# 2) com.android.skia.shaders_cache
23# 3) com.android.renderscript.cache
24# * /data/user_de/0/com.google.android.gms/app_chimera
25# TODO: Tighten (b/112357170)
26allow priv_app privapp_data_file:file execute;
Alex Klyubin92295ef2017-01-05 15:44:32 -080027
Elliott Hughes25cb9042021-02-10 10:07:45 -080028# Chrome Crashpad uses the the dynamic linker to load native executables
29# from an APK (b/112050209, crbug.com/928422)
30allow priv_app system_linker_exec:file execute_no_trans;
31
Nick Kralevich87e91232019-01-24 13:05:03 -080032allow priv_app privapp_data_file:lnk_file create_file_perms;
33
Alan Stokes5c378a52019-03-21 23:52:30 +000034# Priv apps can find services that expose both @SystemAPI and normal APIs.
yro31b11d82018-01-09 11:27:36 -080035allow priv_app app_api_service:service_manager find;
Alan Stokes5c378a52019-03-21 23:52:30 +000036allow priv_app system_api_service:service_manager find;
37
Alex Klyubin92295ef2017-01-05 15:44:32 -080038allow priv_app audioserver_service:service_manager find;
39allow priv_app cameraserver_service:service_manager find;
40allow priv_app drmserver_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080041allow priv_app mediadrmserver_service:service_manager find;
42allow priv_app mediaextractor_service:service_manager find;
yro31b11d82018-01-09 11:27:36 -080043allow priv_app mediametrics_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080044allow priv_app mediaserver_service:service_manager find;
Nick Moukhineaffe2392020-09-18 09:47:05 +020045allow priv_app music_recognition_service:service_manager find;
Ricky Waic6352972017-11-13 17:52:05 +000046allow priv_app network_watchlist_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080047allow priv_app nfc_service:service_manager find;
Andrew Scull37174242017-02-17 13:51:32 +000048allow priv_app oem_lock_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080049allow priv_app persistent_data_block_service:service_manager find;
yro31b11d82018-01-09 11:27:36 -080050allow priv_app radio_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080051allow priv_app recovery_service:service_manager find;
yro31b11d82018-01-09 11:27:36 -080052allow priv_app stats_service:service_manager find;
Yiwei Zhang544d6b32019-02-07 15:00:55 -080053
Alex Klyubin92295ef2017-01-05 15:44:32 -080054# Write to /cache.
55allow priv_app { cache_file cache_recovery_file }:dir create_dir_perms;
56allow priv_app { cache_file cache_recovery_file }:file create_file_perms;
Nick Kralevich21cb0452017-01-23 22:19:06 -080057# /cache is a symlink to /data/cache on some devices. Allow reading the link.
58allow priv_app cache_file:lnk_file r_file_perms;
Alex Klyubin92295ef2017-01-05 15:44:32 -080059
Alex Klyubin92295ef2017-01-05 15:44:32 -080060# Access to /data/media.
61allow priv_app media_rw_data_file:dir create_dir_perms;
62allow priv_app media_rw_data_file:file create_file_perms;
63
64# Used by Finsky / Android "Verify Apps" functionality when
65# running "adb install foo.apk".
66allow priv_app shell_data_file:file r_file_perms;
67allow priv_app shell_data_file:dir r_dir_perms;
68
Max Bires715e2ae2018-03-13 09:56:27 -070069# Allow traceur to pass file descriptors through a content provider to betterbug
70allow priv_app trace_data_file:file { getattr read };
71
Yi Kongae9645e2021-03-18 01:45:52 +080072# Allow betterbug to read profile reports generated by profcollect.
73userdebug_or_eng(`
74 allow priv_app profcollectd_data_file:file r_file_perms;
75')
76
Primiano Tucci2f998092021-01-07 17:12:21 +000077# Allow the bug reporting frontend to read the presence and timestamp of the
78# trace attached to the bugreport (but not its contents, which will go in the
79# usual bugreport .zip file). This is used by the bug reporting UI to tell if
80# the bugreport will contain a system trace or not while the bugreport is still
81# in progress.
Nataniel Borges6b624a52021-11-25 14:57:24 +010082allow priv_app wm_trace_data_file:dir r_dir_perms;
83allow priv_app wm_trace_data_file:file getattr;
Primiano Tucci2f998092021-01-07 17:12:21 +000084allow priv_app perfetto_traces_bugreport_data_file:dir r_dir_perms;
85allow priv_app perfetto_traces_bugreport_data_file:file { getattr };
Primiano Tucci2bb85872021-01-18 09:26:57 +000086# Required to traverse the parent dir (/data/misc/perfetto-traces).
87allow priv_app perfetto_traces_data_file:dir { search };
Primiano Tucci2f998092021-01-07 17:12:21 +000088
Lalit Magantib549e2d2021-12-10 21:50:44 +000089# Allow priv apps (e.g. BetterBug) to receive Perfetto traces through
90# the framework (i.e. TracingServiceProxy) and sendfile them into their private
91# directories for reporting when network and battery conditions are
92# appropriate.
93allow priv_app perfetto:fd use;
94allow priv_app perfetto_traces_data_file:file { read getattr };
95
Alex Klyubin92295ef2017-01-05 15:44:32 -080096# Allow verifier to access staged apks.
97allow priv_app { apk_tmp_file apk_private_tmp_file }:dir r_dir_perms;
98allow priv_app { apk_tmp_file apk_private_tmp_file }:file r_file_perms;
Victor Hsieh6543cf92024-04-26 13:04:00 -070099allowxperm priv_app { apk_tmp_file apk_private_tmp_file }:file ioctl FS_IOC_MEASURE_VERITY;
Alex Klyubin92295ef2017-01-05 15:44:32 -0800100
Alex Klyubin92295ef2017-01-05 15:44:32 -0800101# For AppFuse.
102allow priv_app vold:fd use;
103allow priv_app fuse_device:chr_file { read write };
104
Tri Vof92cfb92017-12-08 15:37:01 -0800105# /proc access
106allow priv_app {
107 proc_vmstat
108}:file r_file_perms;
109
110allow priv_app sysfs_type:dir search;
Tri Vof92cfb92017-12-08 15:37:01 -0800111# Read access to /sys/block/zram*/mm_stat
112r_dir_file(priv_app, sysfs_zram)
113
Alex Klyubin92295ef2017-01-05 15:44:32 -0800114r_dir_file(priv_app, rootfs)
115
Ashwini Oruganti60c6d4e2019-12-13 13:30:53 -0800116# Allow com.android.vending to communicate with statsd.
yro31b11d82018-01-09 11:27:36 -0800117binder_call(priv_app, statsd)
118
Alex Klyubin92295ef2017-01-05 15:44:32 -0800119# Allow Phone to read/write cached ringtones (opened by system).
120allow priv_app ringtone_file:file { getattr read write };
121
122# Access to /data/preloads
123allow priv_app preloads_data_file:file r_file_perms;
124allow priv_app preloads_data_file:dir r_dir_perms;
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700125allow priv_app preloads_media_file:file r_file_perms;
126allow priv_app preloads_media_file:dir r_dir_perms;
Alex Klyubin92295ef2017-01-05 15:44:32 -0800127
Mark Salyzynd33a9a12016-11-07 15:11:39 -0800128read_runtime_log_tags(priv_app)
129
Joe Onorato9cc5c092019-03-16 15:45:45 -0700130# Allow priv_apps to request and collect incident reports.
131# (Also requires DUMP and PACKAGE_USAGE_STATS permissions)
132allow priv_app incident_service:service_manager find;
133binder_call(priv_app, incidentd)
134allow priv_app incidentd:fifo_file { read write };
135
Hung-ying Tyan565384d2019-04-26 16:14:52 +0800136# Allow priv_apps to check whether Dynamic System Update is enabled
137get_prop(priv_app, dynamic_system_prop)
138
Jeff Vander Stoep6d8a8762018-01-18 08:55:02 -0800139# suppress denials for non-API accesses.
Dan Cashman91d398d2017-09-26 12:58:29 -0700140dontaudit priv_app exec_type:file getattr;
Jeff Vander Stoep62338482017-10-20 13:35:42 -0700141dontaudit priv_app device:dir read;
Joel Galenson9ec59f62018-04-20 15:27:21 -0700142dontaudit priv_app fs_bpf:dir search;
Jeff Vander Stoep9dc1d532018-04-04 14:36:13 -0700143dontaudit priv_app net_dns_prop:file read;
Tri Vof92cfb92017-12-08 15:37:01 -0800144dontaudit priv_app proc:file read;
Jeff Vander Stoep62338482017-10-20 13:35:42 -0700145dontaudit priv_app proc_interrupts:file read;
146dontaudit priv_app proc_modules:file read;
Tri Voe319c032019-05-09 16:14:04 -0700147dontaudit priv_app proc_net:file read;
Jeff Vander Stoepe88d6492018-01-29 20:50:59 -0800148dontaudit priv_app proc_stat:file read;
Jeff Vander Stoep6d8a8762018-01-18 08:55:02 -0800149dontaudit priv_app proc_version:file read;
Jeff Vander Stoep9dc1d532018-04-04 14:36:13 -0700150dontaudit priv_app sysfs:dir read;
Jeff Vander Stoep4894d9f2018-06-29 11:04:24 -0700151dontaudit priv_app sysfs:file read;
Jeff Vander Stoep9dc1d532018-04-04 14:36:13 -0700152dontaudit priv_app sysfs_android_usb:file read;
Jeff Vander Stoep90bd1de2019-10-25 11:01:40 +0200153dontaudit priv_app sysfs_dm:file r_file_perms;
ThiƩbaud Weksteen51cc7402023-10-16 11:00:24 +1100154dontaudit priv_app { wifi_prop wifi_config_prop wifi_hal_prop }:file read;
Dan Cashman91d398d2017-09-26 12:58:29 -0700155
Nathan Haroldee268642017-12-14 18:20:30 -0800156# allow privileged apps to use UDP sockets provided by the system server but not
157# modify them other than to connect
Nathan Harold252b0152018-03-27 06:34:54 -0700158allow priv_app system_server:udp_socket {
159 connect getattr read recvfrom sendto write getopt setopt };
Nathan Haroldee268642017-12-14 18:20:30 -0800160
Songchun Fan39222532020-02-13 08:38:36 -0800161# allow apps like Phonesky to check the file signature of an apk installed on
Songchun Fanb4c94912021-02-09 14:33:24 -0800162# the Incremental File System, fill missing blocks and get the app status and loading progress
Yurii Zubrytskyi80dfa062021-01-14 21:01:25 -0800163allowxperm priv_app apk_data_file:file ioctl {
164 INCFS_IOCTL_READ_SIGNATURE
165 INCFS_IOCTL_FILL_BLOCKS
166 INCFS_IOCTL_GET_BLOCK_COUNT
Songchun Fanb4c94912021-02-09 14:33:24 -0800167 INCFS_IOCTL_GET_FILLED_BLOCKS
Yurii Zubrytskyi80dfa062021-01-14 21:01:25 -0800168};
Songchun Fan39222532020-02-13 08:38:36 -0800169
Songchun Fan82ea55d2020-02-21 17:41:40 -0800170# allow privileged data loader apps (e.g. com.android.vending) to read logs from Incremental File System
Songchun Fan2679d8e2020-03-17 18:30:34 -0700171allow priv_app incremental_control_file:file { read getattr ioctl };
172
173# allow apps like Phonesky to request permission to fill blocks of an apk file
174# on the Incremental File System.
175allowxperm priv_app incremental_control_file:file ioctl INCFS_IOCTL_PERMIT_FILL;
Songchun Fan82ea55d2020-02-21 17:41:40 -0800176
Alex Buynytskyy0f010762021-02-04 14:41:41 -0800177# allow privileged apps to read the vendor property that indicates if Incremental File System is enabled
178get_prop(priv_app, incremental_prop)
179
Seigo Nonaka5717c082023-09-11 09:53:44 +0900180# allow privileged apps to read the device config flags.
181get_prop(priv_app, device_config_aconfig_flags_prop)
182
Bell YAO7f938f52023-12-06 17:54:42 +0000183# allow privileged apps to read boot reason property
184get_prop(priv_app, system_boot_reason_prop)
185
Nikita Ioffe01d4c992020-04-22 00:04:04 +0100186# Required for Phonesky to be able to read APEX files under /data/apex/active/.
187allow priv_app apex_data_file:dir search;
188allow priv_app staging_data_file:file r_file_perms;
Mohammad Samiul Islama45cdda2020-12-10 21:48:51 +0000189# Required for Phonesky to be able to read staged files under /data/app-staging.
190allow priv_app staging_data_file:dir r_dir_perms;
Nikita Ioffe01d4c992020-04-22 00:04:04 +0100191
Deyao Rendfb31822022-10-03 22:32:09 +0000192# Allow com.android.vending to access files under vendor/apex as well as system apex files.
193# This is required for com.android.vending to handle APEXes for e.g. delta patch optimization.
194allow priv_app vendor_apex_file:dir r_dir_perms;
195allow priv_app vendor_apex_file:file r_file_perms;
196
tianli0709fbc2020-06-17 17:57:25 +0800197# allow priv app to access the system app data files for ContentProvider case.
198allow priv_app system_app_data_file:file { read getattr };
199
Hongguang737b0982021-06-09 09:36:39 -0700200# Allow the renderscript compiler to be run.
201domain_auto_trans(priv_app, rs_exec, rs)
202
203# Allow loading and deleting executable shared libraries
204# within an application home directory. Such shared libraries would be
205# created by things like renderscript or via other mechanisms.
206allow priv_app app_exec_data_file:file { r_file_perms execute unlink };
207
Alan Stokes30608522022-10-24 12:32:34 +0100208# Allow privileged apps to create a VM. Note that access is still
209# guarded with the `android.permission.MANAGE_VIRTUAL_MACHINE`
210# permission.
211virtualizationservice_use(priv_app)
212
Alex Klyubin92295ef2017-01-05 15:44:32 -0800213###
214### neverallow rules
215###
216
217# Receive or send uevent messages.
218neverallow priv_app domain:netlink_kobject_uevent_socket *;
219
220# Receive or send generic netlink messages
221neverallow priv_app domain:netlink_socket *;
222
Alan Stokesa0518b72020-10-27 11:28:00 +0000223# Read or write kernel printk buffer
224neverallow priv_app kmsg_device:chr_file no_rw_file_perms;
225
Alex Klyubin92295ef2017-01-05 15:44:32 -0800226# Too much leaky information in debugfs. It's a security
227# best practice to ensure these files aren't readable.
Steven Morelandb56bf682023-05-22 23:02:24 +0000228neverallow priv_app debugfs_type:file read;
Alex Klyubin92295ef2017-01-05 15:44:32 -0800229
230# Do not allow privileged apps to register services.
231# Only trusted components of Android should be registering
232# services.
233neverallow priv_app service_manager_type:service_manager add;
234
235# Do not allow privileged apps to connect to the property service
236# or set properties. b/10243159
237neverallow priv_app property_socket:sock_file write;
238neverallow priv_app init:unix_stream_socket connectto;
239neverallow priv_app property_type:property_service set;
240
241# Do not allow priv_app to be assigned mlstrustedsubject.
242# This would undermine the per-user isolation model being
243# enforced via levelFrom=user in seapp_contexts and the mls
244# constraints. As there is no direct way to specify a neverallow
245# on attribute assignment, this relies on the fact that fork
246# permission only makes sense within a domain (hence should
247# never be granted to any other domain within mlstrustedsubject)
248# and priv_app is allowed fork permission to itself.
249neverallow priv_app mlstrustedsubject:process fork;
250
251# Do not allow priv_app to hard link to any files.
252# In particular, if priv_app links to other app data
253# files, installd will not be able to guarantee the deletion
254# of the linked to file. Hard links also contribute to security
255# bugs, so we want to ensure priv_app never has this
256# capability.
257neverallow priv_app file_type:file link;
Max Bires715e2ae2018-03-13 09:56:27 -0700258
259# priv apps should not be able to open trace data files, they should depend
260# upon traceur to pass a file descriptor which they can then read
261neverallow priv_app trace_data_file:dir *;
262neverallow priv_app trace_data_file:file { no_w_file_perms open };
Tri Vof55c9892018-10-10 22:48:15 +0000263
264# Do not allow priv_app access to cgroups.
265neverallow priv_app cgroup:file *;
Marco Ballesioaa4ce952021-02-11 15:18:11 -0800266neverallow priv_app cgroup_v2:file *;
Nick Kraleviche1ddd742018-10-27 15:20:38 -0700267
268# Do not allow loading executable code from non-privileged
269# application home directories. Code loading across a security boundary
270# is dangerous and allows a full compromise of a privileged process
271# by an unprivileged process. b/112357170
Steven Morelandf3722d52023-05-22 23:45:40 +0000272neverallow priv_app { app_data_file_type -privapp_data_file }:file no_x_file_perms;
Nick Kralevich87e91232019-01-24 13:05:03 -0800273
Steven Morelandf3722d52023-05-22 23:45:40 +0000274# Do not follow any app provided symlinks
275neverallow priv_app { app_data_file_type -privapp_data_file }:lnk_file { open read getattr };
Jeff Vander Stoep7f23ef42021-09-24 11:52:08 +0200276
277# Do not allow getting permission-protected network information from sysfs.
278neverallow priv_app sysfs_net:file *;
279
280# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
281# ioctl permission, or 3. disallow the socket class.
282neverallowxperm priv_app domain:{ icmp_socket rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
283neverallow priv_app *:{ netlink_route_socket netlink_selinux_socket } ioctl;
284neverallow priv_app *:{
285 socket netlink_socket packet_socket key_socket appletalk_socket
286 netlink_tcpdiag_socket netlink_nflog_socket
287 netlink_xfrm_socket netlink_audit_socket
288 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
289 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
290 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
291 netlink_rdma_socket netlink_crypto_socket sctp_socket
292 ax25_socket ipx_socket netrom_socket atmpvc_socket x25_socket rose_socket decnet_socket
293 atmsvc_socket rds_socket irda_socket pppox_socket llc_socket can_socket tipc_socket
294 bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket
295 alg_socket nfc_socket kcm_socket qipcrtr_socket smc_socket xdp_socket
296} *;