xref: /aosp_15_r20/system/sepolicy/prebuilts/api/29.0/private/zygote.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# zygote
2*e4a36f41SAndroid Build Coastguard Workertypeattribute zygote coredomain;
3*e4a36f41SAndroid Build Coastguard Workertypeattribute zygote mlstrustedsubject;
4*e4a36f41SAndroid Build Coastguard Worker
5*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(zygote)
6*e4a36f41SAndroid Build Coastguard Worker
7*e4a36f41SAndroid Build Coastguard Workerread_runtime_log_tags(zygote)
8*e4a36f41SAndroid Build Coastguard Worker
9*e4a36f41SAndroid Build Coastguard Worker# Override DAC on files and switch uid/gid.
10*e4a36f41SAndroid Build Coastguard Workerallow zygote self:global_capability_class_set { dac_override dac_read_search setgid setuid fowner chown };
11*e4a36f41SAndroid Build Coastguard Worker
12*e4a36f41SAndroid Build Coastguard Worker# Drop capabilities from bounding set.
13*e4a36f41SAndroid Build Coastguard Workerallow zygote self:global_capability_class_set setpcap;
14*e4a36f41SAndroid Build Coastguard Worker
15*e4a36f41SAndroid Build Coastguard Worker# Switch SELinux context to app domains.
16*e4a36f41SAndroid Build Coastguard Workerallow zygote self:process setcurrent;
17*e4a36f41SAndroid Build Coastguard Workerallow zygote system_server_startup:process dyntransition;
18*e4a36f41SAndroid Build Coastguard Workerallow zygote appdomain:process dyntransition;
19*e4a36f41SAndroid Build Coastguard Workerallow zygote webview_zygote:process dyntransition;
20*e4a36f41SAndroid Build Coastguard Workerallow zygote app_zygote:process dyntransition;
21*e4a36f41SAndroid Build Coastguard Worker
22*e4a36f41SAndroid Build Coastguard Worker# Allow zygote to read app /proc/pid dirs (b/10455872).
23*e4a36f41SAndroid Build Coastguard Workerallow zygote appdomain:dir { getattr search };
24*e4a36f41SAndroid Build Coastguard Workerallow zygote appdomain:file { r_file_perms };
25*e4a36f41SAndroid Build Coastguard Worker
26*e4a36f41SAndroid Build Coastguard Worker# Move children into the peer process group.
27*e4a36f41SAndroid Build Coastguard Workerallow zygote system_server:process { getpgid setpgid };
28*e4a36f41SAndroid Build Coastguard Workerallow zygote appdomain:process { getpgid setpgid };
29*e4a36f41SAndroid Build Coastguard Workerallow zygote webview_zygote:process { getpgid setpgid };
30*e4a36f41SAndroid Build Coastguard Workerallow zygote app_zygote:process { getpgid setpgid };
31*e4a36f41SAndroid Build Coastguard Worker
32*e4a36f41SAndroid Build Coastguard Worker# Read system data.
33*e4a36f41SAndroid Build Coastguard Workerallow zygote system_data_file:dir r_dir_perms;
34*e4a36f41SAndroid Build Coastguard Workerallow zygote system_data_file:file r_file_perms;
35*e4a36f41SAndroid Build Coastguard Worker
36*e4a36f41SAndroid Build Coastguard Worker# Write to /data/dalvik-cache.
37*e4a36f41SAndroid Build Coastguard Workerallow zygote dalvikcache_data_file:dir create_dir_perms;
38*e4a36f41SAndroid Build Coastguard Workerallow zygote dalvikcache_data_file:file create_file_perms;
39*e4a36f41SAndroid Build Coastguard Worker
40*e4a36f41SAndroid Build Coastguard Worker# Create symlinks in /data/dalvik-cache.
41*e4a36f41SAndroid Build Coastguard Workerallow zygote dalvikcache_data_file:lnk_file create_file_perms;
42*e4a36f41SAndroid Build Coastguard Worker
43*e4a36f41SAndroid Build Coastguard Worker# Write to /data/resource-cache.
44*e4a36f41SAndroid Build Coastguard Workerallow zygote resourcecache_data_file:dir rw_dir_perms;
45*e4a36f41SAndroid Build Coastguard Workerallow zygote resourcecache_data_file:file create_file_perms;
46*e4a36f41SAndroid Build Coastguard Worker
47*e4a36f41SAndroid Build Coastguard Worker# For updateability, the zygote may fetch the current boot
48*e4a36f41SAndroid Build Coastguard Worker# classpath from the dalvik cache. Integrity of the files
49*e4a36f41SAndroid Build Coastguard Worker# is ensured by fsverity protection (checked in art_apex_boot_integrity).
50*e4a36f41SAndroid Build Coastguard Workerallow zygote dalvikcache_data_file:file execute;
51*e4a36f41SAndroid Build Coastguard Worker
52*e4a36f41SAndroid Build Coastguard Worker# Allow zygote to create JIT memory.
53*e4a36f41SAndroid Build Coastguard Workerallow zygote self:process execmem;
54*e4a36f41SAndroid Build Coastguard Worker
55*e4a36f41SAndroid Build Coastguard Worker# Execute idmap and dex2oat within zygote's own domain.
56*e4a36f41SAndroid Build Coastguard Worker# TODO:  Should either of these be transitioned to the same domain
57*e4a36f41SAndroid Build Coastguard Worker# used by installd or stay in-domain for zygote?
58*e4a36f41SAndroid Build Coastguard Workerallow zygote idmap_exec:file rx_file_perms;
59*e4a36f41SAndroid Build Coastguard Workerallow zygote dex2oat_exec:file rx_file_perms;
60*e4a36f41SAndroid Build Coastguard Worker
61*e4a36f41SAndroid Build Coastguard Worker# Allow apps access to /vendor/overlay
62*e4a36f41SAndroid Build Coastguard Workerr_dir_file(zygote, vendor_overlay_file)
63*e4a36f41SAndroid Build Coastguard Worker
64*e4a36f41SAndroid Build Coastguard Worker# Control cgroups.
65*e4a36f41SAndroid Build Coastguard Workerallow zygote cgroup:dir create_dir_perms;
66*e4a36f41SAndroid Build Coastguard Workerallow zygote cgroup:{ file lnk_file } r_file_perms;
67*e4a36f41SAndroid Build Coastguard Workerallow zygote self:global_capability_class_set sys_admin;
68*e4a36f41SAndroid Build Coastguard Worker
69*e4a36f41SAndroid Build Coastguard Worker# Allow zygote to stat the files that it opens. The zygote must
70*e4a36f41SAndroid Build Coastguard Worker# be able to inspect them so that it can reopen them on fork
71*e4a36f41SAndroid Build Coastguard Worker# if necessary: b/30963384.
72*e4a36f41SAndroid Build Coastguard Workerallow zygote pmsg_device:chr_file getattr;
73*e4a36f41SAndroid Build Coastguard Workerallow zygote debugfs_trace_marker:file getattr;
74*e4a36f41SAndroid Build Coastguard Worker
75*e4a36f41SAndroid Build Coastguard Worker# Get seapp_contexts
76*e4a36f41SAndroid Build Coastguard Workerallow zygote seapp_contexts_file:file r_file_perms;
77*e4a36f41SAndroid Build Coastguard Worker# Check validity of SELinux context before use.
78*e4a36f41SAndroid Build Coastguard Workerselinux_check_context(zygote)
79*e4a36f41SAndroid Build Coastguard Worker# Check SELinux permissions.
80*e4a36f41SAndroid Build Coastguard Workerselinux_check_access(zygote)
81*e4a36f41SAndroid Build Coastguard Worker
82*e4a36f41SAndroid Build Coastguard Worker# Native bridge functionality requires that zygote replaces
83*e4a36f41SAndroid Build Coastguard Worker# /proc/cpuinfo with /system/lib/<ISA>/cpuinfo using a bind mount
84*e4a36f41SAndroid Build Coastguard Workerallow zygote proc_cpuinfo:file mounton;
85*e4a36f41SAndroid Build Coastguard Worker
86*e4a36f41SAndroid Build Coastguard Worker# Allow remounting rootfs as MS_SLAVE.
87*e4a36f41SAndroid Build Coastguard Workerallow zygote rootfs:dir mounton;
88*e4a36f41SAndroid Build Coastguard Workerallow zygote tmpfs:filesystem { mount unmount };
89*e4a36f41SAndroid Build Coastguard Workerallow zygote fuse:filesystem { unmount };
90*e4a36f41SAndroid Build Coastguard Workerallow zygote sdcardfs:filesystem { unmount };
91*e4a36f41SAndroid Build Coastguard Worker
92*e4a36f41SAndroid Build Coastguard Worker# Allow creating user-specific storage source if started before vold.
93*e4a36f41SAndroid Build Coastguard Workerallow zygote mnt_user_file:dir { create_dir_perms mounton };
94*e4a36f41SAndroid Build Coastguard Workerallow zygote mnt_user_file:lnk_file create_file_perms;
95*e4a36f41SAndroid Build Coastguard Workerallow zygote mnt_user_file:file create_file_perms;
96*e4a36f41SAndroid Build Coastguard Worker# Allowed to mount user-specific storage into place
97*e4a36f41SAndroid Build Coastguard Workerallow zygote storage_file:dir { search mounton };
98*e4a36f41SAndroid Build Coastguard Worker
99*e4a36f41SAndroid Build Coastguard Worker# Allow mounting and creating files, dirs on sdcardfs.
100*e4a36f41SAndroid Build Coastguard Worker# TODO: reduce this back to only sdcardfs once b/123533205 is root-caused
101*e4a36f41SAndroid Build Coastguard Worker# (Technically "sdcardfs" and "media_rw_data_file" are equivalent, since
102*e4a36f41SAndroid Build Coastguard Worker# sdcardfs simply wraps files stored under /data/media.)
103*e4a36f41SAndroid Build Coastguard Workerallow zygote { sdcard_type media_rw_data_file }:dir { create_dir_perms mounton };
104*e4a36f41SAndroid Build Coastguard Workerallow zygote { sdcard_type media_rw_data_file }:file { create_file_perms };
105*e4a36f41SAndroid Build Coastguard Worker
106*e4a36f41SAndroid Build Coastguard Worker# Allow zygote to expand app files while preloading libraries
107*e4a36f41SAndroid Build Coastguard Workerallow zygote mnt_expand_file:dir getattr;
108*e4a36f41SAndroid Build Coastguard Worker
109*e4a36f41SAndroid Build Coastguard Worker# Handle --invoke-with command when launching Zygote with a wrapper command.
110*e4a36f41SAndroid Build Coastguard Workerallow zygote zygote_exec:file rx_file_perms;
111*e4a36f41SAndroid Build Coastguard Worker
112*e4a36f41SAndroid Build Coastguard Worker# Allow zygote to write to statsd.
113*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(zygote, statsdw, statsd)
114*e4a36f41SAndroid Build Coastguard Worker
115*e4a36f41SAndroid Build Coastguard Worker# Root fs.
116*e4a36f41SAndroid Build Coastguard Workerr_dir_file(zygote, rootfs)
117*e4a36f41SAndroid Build Coastguard Worker
118*e4a36f41SAndroid Build Coastguard Worker# System file accesses.
119*e4a36f41SAndroid Build Coastguard Workerr_dir_file(zygote, system_file)
120*e4a36f41SAndroid Build Coastguard Worker
121*e4a36f41SAndroid Build Coastguard Worker# /oem accesses.
122*e4a36f41SAndroid Build Coastguard Workerallow zygote oemfs:dir search;
123*e4a36f41SAndroid Build Coastguard Worker
124*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
125*e4a36f41SAndroid Build Coastguard Worker  # Allow zygote to create and write method traces in /data/misc/trace.
126*e4a36f41SAndroid Build Coastguard Worker  allow zygote method_trace_data_file:dir w_dir_perms;
127*e4a36f41SAndroid Build Coastguard Worker  allow zygote method_trace_data_file:file { create w_file_perms };
128*e4a36f41SAndroid Build Coastguard Worker')
129*e4a36f41SAndroid Build Coastguard Worker
130*e4a36f41SAndroid Build Coastguard Workerallow zygote ion_device:chr_file r_file_perms;
131*e4a36f41SAndroid Build Coastguard Workerallow zygote tmpfs:dir r_dir_perms;
132*e4a36f41SAndroid Build Coastguard Worker
133*e4a36f41SAndroid Build Coastguard Workerallow zygote same_process_hal_file:file { execute read open getattr map };
134*e4a36f41SAndroid Build Coastguard Worker
135*e4a36f41SAndroid Build Coastguard Worker# Let the zygote access overlays so it can initialize the AssetManager.
136*e4a36f41SAndroid Build Coastguard Workerget_prop(zygote, overlay_prop)
137*e4a36f41SAndroid Build Coastguard Workerget_prop(zygote, exported_overlay_prop)
138*e4a36f41SAndroid Build Coastguard Worker
139*e4a36f41SAndroid Build Coastguard Worker# Allow the zygote to access the runtime feature flag properties.
140*e4a36f41SAndroid Build Coastguard Workerget_prop(zygote, device_config_runtime_native_prop)
141*e4a36f41SAndroid Build Coastguard Workerget_prop(zygote, device_config_runtime_native_boot_prop)
142*e4a36f41SAndroid Build Coastguard Worker
143*e4a36f41SAndroid Build Coastguard Worker# ingore spurious denials
144*e4a36f41SAndroid Build Coastguard Workerdontaudit zygote self:global_capability_class_set sys_resource;
145*e4a36f41SAndroid Build Coastguard Worker
146*e4a36f41SAndroid Build Coastguard Worker###
147*e4a36f41SAndroid Build Coastguard Worker### neverallow rules
148*e4a36f41SAndroid Build Coastguard Worker###
149*e4a36f41SAndroid Build Coastguard Worker
150*e4a36f41SAndroid Build Coastguard Worker# Ensure that all types assigned to app processes are included
151*e4a36f41SAndroid Build Coastguard Worker# in the appdomain attribute, so that all allow and neverallow rules
152*e4a36f41SAndroid Build Coastguard Worker# written on appdomain are applied to all app processes.
153*e4a36f41SAndroid Build Coastguard Worker# This is achieved by ensuring that it is impossible for zygote to
154*e4a36f41SAndroid Build Coastguard Worker# setcon (dyntransition) to any types other than those associated
155*e4a36f41SAndroid Build Coastguard Worker# with appdomain plus system_server_startup, webview_zygote and
156*e4a36f41SAndroid Build Coastguard Worker# app_zygote.
157*e4a36f41SAndroid Build Coastguard Workerneverallow zygote ~{
158*e4a36f41SAndroid Build Coastguard Worker  appdomain
159*e4a36f41SAndroid Build Coastguard Worker  system_server_startup
160*e4a36f41SAndroid Build Coastguard Worker  webview_zygote
161*e4a36f41SAndroid Build Coastguard Worker  app_zygote
162*e4a36f41SAndroid Build Coastguard Worker}:process dyntransition;
163*e4a36f41SAndroid Build Coastguard Worker
164*e4a36f41SAndroid Build Coastguard Worker# Zygote should never execute anything from /data except for /data/dalvik-cache files.
165*e4a36f41SAndroid Build Coastguard Workerneverallow zygote {
166*e4a36f41SAndroid Build Coastguard Worker  data_file_type
167*e4a36f41SAndroid Build Coastguard Worker  -dalvikcache_data_file # map PROT_EXEC
168*e4a36f41SAndroid Build Coastguard Worker}:file no_x_file_perms;
169*e4a36f41SAndroid Build Coastguard Worker
170*e4a36f41SAndroid Build Coastguard Worker# Do not allow access to Bluetooth-related system properties and files
171*e4a36f41SAndroid Build Coastguard Workerneverallow zygote {
172*e4a36f41SAndroid Build Coastguard Worker  bluetooth_a2dp_offload_prop
173*e4a36f41SAndroid Build Coastguard Worker  bluetooth_audio_hal_prop
174*e4a36f41SAndroid Build Coastguard Worker  bluetooth_prop
175*e4a36f41SAndroid Build Coastguard Worker  exported_bluetooth_prop
176*e4a36f41SAndroid Build Coastguard Worker}:file create_file_perms;
177