1###
2### Untrusted apps.
3###
4### This file defines the rules for untrusted apps.
5### Apps are labeled based on mac_permissions.xml (maps signer and
6### optionally package name to seinfo value) and seapp_contexts (maps UID
7### and optionally seinfo value to domain for process and type for data
8### directory).  The untrusted_app domain is the default assignment in
9### seapp_contexts for any app with UID between APP_AID (10000)
10### and AID_ISOLATED_START (99000) if the app has no specific seinfo
11### value as determined from mac_permissions.xml.  In current AOSP, this
12### domain is assigned to all non-system apps as well as to any system apps
13### that are not signed by the platform key.  To move
14### a system app into a specific domain, add a signer entry for it to
15### mac_permissions.xml and assign it one of the pre-existing seinfo values
16### or define and use a new seinfo value in both mac_permissions.xml and
17### seapp_contexts.
18###
19### untrusted_app includes all the appdomain rules, plus the
20### additional following rules:
21###
22
23type untrusted_app, domain;
24app_domain(untrusted_app)
25net_domain(untrusted_app)
26bluetooth_domain(untrusted_app)
27
28# Some apps ship with shared libraries and binaries that they write out
29# to their sandbox directory and then execute.
30allow untrusted_app app_data_file:file { rx_file_perms execmod };
31
32allow untrusted_app tun_device:chr_file rw_file_perms;
33
34# ASEC
35allow untrusted_app asec_apk_file:file r_file_perms;
36# Execute libs in asec containers.
37allow untrusted_app asec_public_file:file { execute execmod };
38
39# Allow the allocation and use of ptys
40# Used by: https://play.google.com/store/apps/details?id=jackpal.androidterm
41create_pty(untrusted_app)
42
43# Used by Finsky / Android "Verify Apps" functionality when
44# running "adb install foo.apk".
45# TODO: Long term, we don't want apps probing into shell data files.
46# Figure out a way to remove these rules.
47allow untrusted_app shell_data_file:file r_file_perms;
48allow untrusted_app shell_data_file:dir r_dir_perms;
49
50# b/18504118: Allow reads from /data/anr/traces.txt
51# TODO: We shouldn't be allowing all untrusted_apps to read
52# this file. This is only needed for the GMS feedback agent.
53# See also b/18340553. GMS runs as untrusted_app, and
54# it's too late to change the domain it runs in.
55# This line needs to be deleted.
56allow untrusted_app anr_data_file:file r_file_perms;
57
58# Read and write system app data files passed over Binder.
59# Motivating case was /data/data/com.android.settings/cache/*.jpg for
60# cropping or taking user photos.
61allow untrusted_app system_app_data_file:file { read write getattr };
62
63#
64# Rules migrated from old app domains coalesced into untrusted_app.
65# This includes what used to be media_app, shared_app, and release_app.
66#
67
68# Access /dev/mtp_usb.
69allow untrusted_app mtp_device:chr_file rw_file_perms;
70
71# Access to /data/media.
72allow untrusted_app media_rw_data_file:dir create_dir_perms;
73allow untrusted_app media_rw_data_file:file create_file_perms;
74
75# Traverse into /mnt/media_rw for bypassing FUSE daemon
76# TODO: narrow this to just MediaProvider
77allow untrusted_app mnt_media_rw_file:dir search;
78
79# Write to /cache.
80allow untrusted_app cache_file:dir create_dir_perms;
81allow untrusted_app cache_file:file create_file_perms;
82
83allow untrusted_app drmserver_service:service_manager find;
84allow untrusted_app mediaserver_service:service_manager find;
85allow untrusted_app nfc_service:service_manager find;
86allow untrusted_app radio_service:service_manager find;
87allow untrusted_app surfaceflinger_service:service_manager find;
88allow untrusted_app app_api_service:service_manager find;
89
90# TODO: remove this once priv-apps are no longer running in untrusted_app
91allow untrusted_app system_api_service:service_manager find;
92
93# TODO: remove and replace with specific package that accesses this
94allow untrusted_app persistent_data_block_service:service_manager find;
95
96# Allow verifier to access staged apks.
97allow untrusted_app { apk_tmp_file apk_private_tmp_file }:dir r_dir_perms;
98allow untrusted_app { apk_tmp_file apk_private_tmp_file }:file r_file_perms;
99
100# only allow unprivileged socket ioctl commands
101allow untrusted_app self:{ rawip_socket tcp_socket udp_socket } unpriv_sock_ioctls;
102
103# Allow GMS core to access perfprofd output, which is stored
104# in /data/misc/perfprofd/. GMS core will need to list all
105# data stored in that directory to process them one by one.
106userdebug_or_eng(`
107  allow untrusted_app perfprofd_data_file:file r_file_perms;
108  allow untrusted_app perfprofd_data_file:dir r_dir_perms;
109')
110
111# Programs routinely attempt to scan through /system, looking
112# for files. Suppress the denials when they occur.
113dontaudit untrusted_app exec_type:file getattr;
114
115###
116### neverallow rules
117###
118
119# Receive or send uevent messages.
120neverallow untrusted_app domain:netlink_kobject_uevent_socket *;
121
122# Receive or send generic netlink messages
123neverallow untrusted_app domain:netlink_socket *;
124
125# Too much leaky information in debugfs. It's a security
126# best practice to ensure these files aren't readable.
127neverallow untrusted_app debugfs:file read;
128
129# Do not allow untrusted apps to register services.
130# Only trusted components of Android should be registering
131# services.
132neverallow untrusted_app service_manager_type:service_manager add;
133
134# Do not allow untrusted_apps to connect to the property service
135# or set properties. b/10243159
136neverallow untrusted_app property_socket:sock_file write;
137neverallow untrusted_app init:unix_stream_socket connectto;
138neverallow untrusted_app property_type:property_service set;
139
140# Do not allow untrusted_app to be assigned mlstrustedsubject.
141# This would undermine the per-user isolation model being
142# enforced via levelFrom=user in seapp_contexts and the mls
143# constraints.  As there is no direct way to specify a neverallow
144# on attribute assignment, this relies on the fact that fork
145# permission only makes sense within a domain (hence should
146# never be granted to any other domain within mlstrustedsubject)
147# and untrusted_app is allowed fork permission to itself.
148neverallow untrusted_app mlstrustedsubject:process fork;
149
150# Do not allow untrusted_app to hard link to any files.
151# In particular, if untrusted_app links to other app data
152# files, installd will not be able to guarantee the deletion
153# of the linked to file. Hard links also contribute to security
154# bugs, so we want to ensure untrusted_app never has this
155# capability.
156neverallow untrusted_app file_type:file link;
157