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