xref: /aosp_15_r20/system/sepolicy/prebuilts/api/34.0/public/app.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker###
2*e4a36f41SAndroid Build Coastguard Worker### Domain for all zygote spawned apps
3*e4a36f41SAndroid Build Coastguard Worker###
4*e4a36f41SAndroid Build Coastguard Worker### This file is the base policy for all zygote spawned apps.
5*e4a36f41SAndroid Build Coastguard Worker### Other policy files, such as isolated_app.te, untrusted_app.te, etc
6*e4a36f41SAndroid Build Coastguard Worker### extend from this policy. Only policies which should apply to ALL
7*e4a36f41SAndroid Build Coastguard Worker### zygote spawned apps should be added here.
8*e4a36f41SAndroid Build Coastguard Worker###
9*e4a36f41SAndroid Build Coastguard Workertype appdomain_tmpfs, file_type;
10*e4a36f41SAndroid Build Coastguard Worker
11*e4a36f41SAndroid Build Coastguard Worker###
12*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules
13*e4a36f41SAndroid Build Coastguard Worker###
14*e4a36f41SAndroid Build Coastguard Worker### These are things that Android apps should NEVER be able to do
15*e4a36f41SAndroid Build Coastguard Worker###
16*e4a36f41SAndroid Build Coastguard Worker
17*e4a36f41SAndroid Build Coastguard Worker# Superuser capabilities.
18*e4a36f41SAndroid Build Coastguard Worker# bluetooth requires net_admin and wake_alarm. network stack app requires net_admin.
19*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -bluetooth -network_stack } self:capability_class_set *;
20*e4a36f41SAndroid Build Coastguard Worker
21*e4a36f41SAndroid Build Coastguard Worker# Block device access.
22*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain dev_type:blk_file { read write };
23*e4a36f41SAndroid Build Coastguard Worker
24*e4a36f41SAndroid Build Coastguard Worker# Note: Try expanding list of app domains in the future.
25*e4a36f41SAndroid Build Coastguard Workerneverallow { untrusted_app isolated_app shell } graphics_device:chr_file { read write };
26*e4a36f41SAndroid Build Coastguard Worker
27*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -nfc } nfc_device:chr_file
28*e4a36f41SAndroid Build Coastguard Worker    { read write };
29*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -bluetooth } hci_attach_dev:chr_file
30*e4a36f41SAndroid Build Coastguard Worker    { read write };
31*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain tee_device:chr_file { read write };
32*e4a36f41SAndroid Build Coastguard Worker
33*e4a36f41SAndroid Build Coastguard Worker# Privileged netlink socket interfaces.
34*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -network_stack }
35*e4a36f41SAndroid Build Coastguard Worker    domain:{
36*e4a36f41SAndroid Build Coastguard Worker        netlink_tcpdiag_socket
37*e4a36f41SAndroid Build Coastguard Worker        netlink_nflog_socket
38*e4a36f41SAndroid Build Coastguard Worker        netlink_xfrm_socket
39*e4a36f41SAndroid Build Coastguard Worker        netlink_audit_socket
40*e4a36f41SAndroid Build Coastguard Worker        netlink_dnrt_socket
41*e4a36f41SAndroid Build Coastguard Worker    } *;
42*e4a36f41SAndroid Build Coastguard Worker
43*e4a36f41SAndroid Build Coastguard Worker# These messages are broadcast messages from the kernel to userspace.
44*e4a36f41SAndroid Build Coastguard Worker# Do not allow the writing of netlink messages, which has been a source
45*e4a36f41SAndroid Build Coastguard Worker# of rooting vulns in the past.
46*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -network_stack }
47*e4a36f41SAndroid Build Coastguard Worker    domain:netlink_kobject_uevent_socket { write append };
48*e4a36f41SAndroid Build Coastguard Worker
49*e4a36f41SAndroid Build Coastguard Worker# Sockets under /dev/socket that are not specifically typed.
50*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain socket_device:sock_file write;
51*e4a36f41SAndroid Build Coastguard Worker
52*e4a36f41SAndroid Build Coastguard Worker# Unix domain sockets.
53*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain adbd_socket:sock_file write;
54*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -radio } rild_socket:sock_file write;
55*e4a36f41SAndroid Build Coastguard Worker
56*e4a36f41SAndroid Build Coastguard Worker# ptrace access to non-app domains.
57*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain { domain -appdomain }:process ptrace;
58*e4a36f41SAndroid Build Coastguard Worker
59*e4a36f41SAndroid Build Coastguard Worker# The Android security model guarantees the confidentiality and integrity
60*e4a36f41SAndroid Build Coastguard Worker# of application data and execution state. Ptrace bypasses those
61*e4a36f41SAndroid Build Coastguard Worker# confidentiality guarantees. Disallow ptrace access from system components
62*e4a36f41SAndroid Build Coastguard Worker# to apps. Crash_dump is excluded, as it needs ptrace access to
63*e4a36f41SAndroid Build Coastguard Worker# produce stack traces.  llkd is excluded, as it needs ptrace access to
64*e4a36f41SAndroid Build Coastguard Worker# inspect stack traces for live lock conditions.
65*e4a36f41SAndroid Build Coastguard Worker
66*e4a36f41SAndroid Build Coastguard Workerneverallow {
67*e4a36f41SAndroid Build Coastguard Worker  domain
68*e4a36f41SAndroid Build Coastguard Worker  -appdomain
69*e4a36f41SAndroid Build Coastguard Worker  -crash_dump
70*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-llkd')
71*e4a36f41SAndroid Build Coastguard Worker} appdomain:process ptrace;
72*e4a36f41SAndroid Build Coastguard Worker
73*e4a36f41SAndroid Build Coastguard Worker# Read or write access to /proc/pid entries for any non-app domain.
74*e4a36f41SAndroid Build Coastguard Worker# A different form of hidepid=2 like protections
75*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain { domain -appdomain }:file no_w_file_perms;
76*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -shell } { domain -appdomain }:file no_rw_file_perms;
77*e4a36f41SAndroid Build Coastguard Worker
78*e4a36f41SAndroid Build Coastguard Worker# signal access to non-app domains.
79*e4a36f41SAndroid Build Coastguard Worker# sigchld allowed for parent death notification.
80*e4a36f41SAndroid Build Coastguard Worker# signull allowed for kill(pid, 0) existence test.
81*e4a36f41SAndroid Build Coastguard Worker# All others prohibited.
82*e4a36f41SAndroid Build Coastguard Worker# -perfetto is to allow shell (which is an appdomain) to kill perfetto
83*e4a36f41SAndroid Build Coastguard Worker# (see private/shell.te).
84*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain { domain -appdomain -perfetto }:process
85*e4a36f41SAndroid Build Coastguard Worker    { sigkill sigstop signal };
86*e4a36f41SAndroid Build Coastguard Worker
87*e4a36f41SAndroid Build Coastguard Worker# Write to rootfs.
88*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain rootfs:dir_file_class_set
89*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
90*e4a36f41SAndroid Build Coastguard Worker
91*e4a36f41SAndroid Build Coastguard Worker# Write to /system.
92*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain system_file:dir_file_class_set
93*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
94*e4a36f41SAndroid Build Coastguard Worker
95*e4a36f41SAndroid Build Coastguard Worker# Write to entrypoint executables.
96*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain exec_type:file
97*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
98*e4a36f41SAndroid Build Coastguard Worker
99*e4a36f41SAndroid Build Coastguard Worker# Write to system-owned parts of /data.
100*e4a36f41SAndroid Build Coastguard Worker# This is the default type for anything under /data not otherwise
101*e4a36f41SAndroid Build Coastguard Worker# specified in file_contexts.  Define a different type for portions
102*e4a36f41SAndroid Build Coastguard Worker# that should be writable by apps.
103*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain system_data_file:dir_file_class_set
104*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
105*e4a36f41SAndroid Build Coastguard Worker
106*e4a36f41SAndroid Build Coastguard Worker# Write to various other parts of /data.
107*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain drm_data_file:dir_file_class_set
108*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
109*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -platform_app }
110*e4a36f41SAndroid Build Coastguard Worker    apk_data_file:dir_file_class_set
111*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
112*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -platform_app }
113*e4a36f41SAndroid Build Coastguard Worker    apk_tmp_file:dir_file_class_set
114*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
115*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -platform_app }
116*e4a36f41SAndroid Build Coastguard Worker    apk_private_data_file:dir_file_class_set
117*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
118*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -platform_app }
119*e4a36f41SAndroid Build Coastguard Worker    apk_private_tmp_file:dir_file_class_set
120*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
121*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -shell }
122*e4a36f41SAndroid Build Coastguard Worker    shell_data_file:dir_file_class_set
123*e4a36f41SAndroid Build Coastguard Worker    { create setattr relabelfrom relabelto append unlink link rename };
124*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -bluetooth }
125*e4a36f41SAndroid Build Coastguard Worker    bluetooth_data_file:dir_file_class_set
126*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
127*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -credstore -init } credstore_data_file:dir_file_class_set *;
128*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain
129*e4a36f41SAndroid Build Coastguard Worker    keystore_data_file:dir_file_class_set
130*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
131*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain
132*e4a36f41SAndroid Build Coastguard Worker    systemkeys_data_file:dir_file_class_set
133*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
134*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain
135*e4a36f41SAndroid Build Coastguard Worker    wifi_data_file:dir_file_class_set
136*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
137*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain
138*e4a36f41SAndroid Build Coastguard Worker    dhcp_data_file:dir_file_class_set
139*e4a36f41SAndroid Build Coastguard Worker    { create write setattr relabelfrom relabelto append unlink link rename };
140*e4a36f41SAndroid Build Coastguard Worker
141*e4a36f41SAndroid Build Coastguard Worker# access tmp apk files
142*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -untrusted_app_all -platform_app -priv_app }
143*e4a36f41SAndroid Build Coastguard Worker    { apk_tmp_file apk_private_tmp_file }:dir_file_class_set *;
144*e4a36f41SAndroid Build Coastguard Worker
145*e4a36f41SAndroid Build Coastguard Workerneverallow untrusted_app_all { apk_tmp_file apk_private_tmp_file }:{ devfile_class_set dir fifo_file lnk_file sock_file } *;
146*e4a36f41SAndroid Build Coastguard Workerneverallow untrusted_app_all { apk_tmp_file apk_private_tmp_file }:file ~{ getattr read };
147*e4a36f41SAndroid Build Coastguard Worker
148*e4a36f41SAndroid Build Coastguard Worker# Access to factory files.
149*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain efs_file:dir_file_class_set write;
150*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -shell } efs_file:dir_file_class_set read;
151*e4a36f41SAndroid Build Coastguard Worker
152*e4a36f41SAndroid Build Coastguard Worker# Write to various pseudo file systems.
153*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -bluetooth -nfc }
154*e4a36f41SAndroid Build Coastguard Worker    sysfs:dir_file_class_set write;
155*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain
156*e4a36f41SAndroid Build Coastguard Worker    proc:dir_file_class_set write;
157*e4a36f41SAndroid Build Coastguard Worker
158*e4a36f41SAndroid Build Coastguard Worker# Access to syslog(2) or /proc/kmsg.
159*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain kernel:system { syslog_read syslog_mod syslog_console };
160*e4a36f41SAndroid Build Coastguard Worker
161*e4a36f41SAndroid Build Coastguard Worker# SELinux is not an API for apps to use
162*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -shell } *:security { compute_av check_context };
163*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -shell } *:netlink_selinux_socket *;
164*e4a36f41SAndroid Build Coastguard Worker
165*e4a36f41SAndroid Build Coastguard Worker# Ability to perform any filesystem operation other than statfs(2).
166*e4a36f41SAndroid Build Coastguard Worker# i.e. no mount(2), unmount(2), etc.
167*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain fs_type:filesystem ~getattr;
168*e4a36f41SAndroid Build Coastguard Worker
169*e4a36f41SAndroid Build Coastguard Worker# prevent creation/manipulation of globally readable symlinks
170*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain {
171*e4a36f41SAndroid Build Coastguard Worker  apk_data_file
172*e4a36f41SAndroid Build Coastguard Worker  cache_file
173*e4a36f41SAndroid Build Coastguard Worker  cache_recovery_file
174*e4a36f41SAndroid Build Coastguard Worker  dev_type
175*e4a36f41SAndroid Build Coastguard Worker  rootfs
176*e4a36f41SAndroid Build Coastguard Worker  system_file
177*e4a36f41SAndroid Build Coastguard Worker  tmpfs
178*e4a36f41SAndroid Build Coastguard Worker}:lnk_file no_w_file_perms;
179*e4a36f41SAndroid Build Coastguard Worker
180*e4a36f41SAndroid Build Coastguard Worker# Applications should use the activity model for receiving events
181*e4a36f41SAndroid Build Coastguard Workerneverallow {
182*e4a36f41SAndroid Build Coastguard Worker  appdomain
183*e4a36f41SAndroid Build Coastguard Worker  -shell # bugreport
184*e4a36f41SAndroid Build Coastguard Worker} input_device:chr_file ~getattr;
185*e4a36f41SAndroid Build Coastguard Worker
186*e4a36f41SAndroid Build Coastguard Worker# Do not allow access to Bluetooth-related system properties except for a few allowed domains.
187*e4a36f41SAndroid Build Coastguard Worker# neverallow rules for access to Bluetooth-related data files are above.
188*e4a36f41SAndroid Build Coastguard Workerneverallow {
189*e4a36f41SAndroid Build Coastguard Worker  appdomain
190*e4a36f41SAndroid Build Coastguard Worker  -bluetooth
191*e4a36f41SAndroid Build Coastguard Worker  -system_app
192*e4a36f41SAndroid Build Coastguard Worker} { bluetooth_audio_hal_prop bluetooth_a2dp_offload_prop bluetooth_prop exported_bluetooth_prop }:file create_file_perms;
193*e4a36f41SAndroid Build Coastguard Worker
194*e4a36f41SAndroid Build Coastguard Worker# allow system_app to access Nfc-related system properties.
195*e4a36f41SAndroid Build Coastguard Workerset_prop(system_app, nfc_prop)
196*e4a36f41SAndroid Build Coastguard Worker
197*e4a36f41SAndroid Build Coastguard Worker# allow system_app to access radio_config system properties.
198*e4a36f41SAndroid Build Coastguard Workerset_prop(system_app, radio_control_prop)
199*e4a36f41SAndroid Build Coastguard Worker
200*e4a36f41SAndroid Build Coastguard Worker# Apps cannot access proc_uid_time_in_state
201*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain proc_uid_time_in_state:file *;
202*e4a36f41SAndroid Build Coastguard Worker
203*e4a36f41SAndroid Build Coastguard Worker# Apps cannot access proc_uid_concurrent_active_time
204*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain proc_uid_concurrent_active_time:file *;
205*e4a36f41SAndroid Build Coastguard Worker
206*e4a36f41SAndroid Build Coastguard Worker# Apps cannot access proc_uid_concurrent_policy_time
207*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain proc_uid_concurrent_policy_time:file *;
208*e4a36f41SAndroid Build Coastguard Worker
209*e4a36f41SAndroid Build Coastguard Worker# Apps cannot access proc_uid_cpupower
210*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain proc_uid_cpupower:file *;
211*e4a36f41SAndroid Build Coastguard Worker
212*e4a36f41SAndroid Build Coastguard Worker# Apps may not read /proc/net/{tcp,tcp6,udp,udp6}. These files leak information across the
213*e4a36f41SAndroid Build Coastguard Worker# application boundary. VPN apps may use the ConnectivityManager.getConnectionOwnerUid() API to
214*e4a36f41SAndroid Build Coastguard Worker# perform UID lookups.
215*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -shell } proc_net_tcp_udp:file *;
216*e4a36f41SAndroid Build Coastguard Worker
217*e4a36f41SAndroid Build Coastguard Worker# Apps cannot access bootstrap files. The bootstrap files are only for
218*e4a36f41SAndroid Build Coastguard Worker# extremely early processes (like init, etc.) which are started before
219*e4a36f41SAndroid Build Coastguard Worker# the runtime APEX is activated and Bionic libs are provided from there.
220*e4a36f41SAndroid Build Coastguard Worker# If app process accesses (or even load/execute) the bootstrap files,
221*e4a36f41SAndroid Build Coastguard Worker# it might cause problems such as ODR violation, etc.
222*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain system_bootstrap_lib_file:file
223*e4a36f41SAndroid Build Coastguard Worker    { open read write append execute execute_no_trans map };
224*e4a36f41SAndroid Build Coastguard Workerneverallow appdomain system_bootstrap_lib_file:dir
225*e4a36f41SAndroid Build Coastguard Worker    { open read getattr search };
226