xref: /aosp_15_r20/system/sepolicy/private/adbd.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker### ADB daemon
2*e4a36f41SAndroid Build Coastguard Worker
3*e4a36f41SAndroid Build Coastguard Workertypeattribute adbd coredomain;
4*e4a36f41SAndroid Build Coastguard Workertypeattribute adbd mlstrustedsubject;
5*e4a36f41SAndroid Build Coastguard Workertypeattribute adbd adbd_common;
6*e4a36f41SAndroid Build Coastguard Worker
7*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(adbd)
8*e4a36f41SAndroid Build Coastguard Worker
9*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(adbd, shell_exec, shell)
10*e4a36f41SAndroid Build Coastguard Worker
11*e4a36f41SAndroid Build Coastguard Worker# Allow adb to setcon() to tradeinmode.
12*e4a36f41SAndroid Build Coastguard Workerallow adbd self:process setcurrent;
13*e4a36f41SAndroid Build Coastguard Workerallow adbd adbd_tradeinmode:process dyntransition;
14*e4a36f41SAndroid Build Coastguard Worker
15*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
16*e4a36f41SAndroid Build Coastguard Worker  allow adbd su:process dyntransition;
17*e4a36f41SAndroid Build Coastguard Worker')
18*e4a36f41SAndroid Build Coastguard Worker
19*e4a36f41SAndroid Build Coastguard Worker# When 'adb shell' is executed in recovery mode, adbd explicitly
20*e4a36f41SAndroid Build Coastguard Worker# switches into shell domain using setcon() because the shell executable
21*e4a36f41SAndroid Build Coastguard Worker# is not labeled as shell but as rootfs.
22*e4a36f41SAndroid Build Coastguard Workerrecovery_only(`
23*e4a36f41SAndroid Build Coastguard Worker  domain_trans(adbd, rootfs, shell)
24*e4a36f41SAndroid Build Coastguard Worker  allow adbd shell:process dyntransition;
25*e4a36f41SAndroid Build Coastguard Worker
26*e4a36f41SAndroid Build Coastguard Worker  # Allows reboot fastboot to enter fastboot directly
27*e4a36f41SAndroid Build Coastguard Worker  unix_socket_connect(adbd, recovery, recovery)
28*e4a36f41SAndroid Build Coastguard Worker')
29*e4a36f41SAndroid Build Coastguard Worker
30*e4a36f41SAndroid Build Coastguard Worker# Control Perfetto traced and obtain traces from it.
31*e4a36f41SAndroid Build Coastguard Worker# Needed to allow port forwarding directly to traced.
32*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(adbd, traced_consumer, traced)
33*e4a36f41SAndroid Build Coastguard Worker
34*e4a36f41SAndroid Build Coastguard Worker# Do not sanitize the environment or open fds of the shell. Allow signaling
35*e4a36f41SAndroid Build Coastguard Worker# created processes.
36*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:process { noatsecure signal };
37*e4a36f41SAndroid Build Coastguard Worker
38*e4a36f41SAndroid Build Coastguard Worker# Set UID and GID to shell.  Set supplementary groups.
39*e4a36f41SAndroid Build Coastguard Workerallow adbd self:global_capability_class_set { setuid setgid };
40*e4a36f41SAndroid Build Coastguard Worker
41*e4a36f41SAndroid Build Coastguard Worker# Drop capabilities from bounding set on user builds.
42*e4a36f41SAndroid Build Coastguard Workerallow adbd self:global_capability_class_set setpcap;
43*e4a36f41SAndroid Build Coastguard Worker
44*e4a36f41SAndroid Build Coastguard Worker# ignore spurious denials for adbd when disk space is low.
45*e4a36f41SAndroid Build Coastguard Workerdontaudit adbd self:global_capability_class_set sys_resource;
46*e4a36f41SAndroid Build Coastguard Worker
47*e4a36f41SAndroid Build Coastguard Worker# Create and use network sockets.
48*e4a36f41SAndroid Build Coastguard Workernet_domain(adbd)
49*e4a36f41SAndroid Build Coastguard Worker# Access /dev/usb-ffs/adb/ep0
50*e4a36f41SAndroid Build Coastguard Workerallow adbd functionfs:dir search;
51*e4a36f41SAndroid Build Coastguard Workerallow adbd functionfs:file rw_file_perms;
52*e4a36f41SAndroid Build Coastguard Workerallowxperm adbd functionfs:file ioctl {
53*e4a36f41SAndroid Build Coastguard Worker  FUNCTIONFS_ENDPOINT_DESC
54*e4a36f41SAndroid Build Coastguard Worker  FUNCTIONFS_CLEAR_HALT
55*e4a36f41SAndroid Build Coastguard Worker};
56*e4a36f41SAndroid Build Coastguard Worker
57*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/local/traces/*
58*e4a36f41SAndroid Build Coastguard Workerallow adbd trace_data_file:dir r_dir_perms;
59*e4a36f41SAndroid Build Coastguard Workerallow adbd trace_data_file:file r_file_perms;
60*e4a36f41SAndroid Build Coastguard Worker
61*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/misc/profman.
62*e4a36f41SAndroid Build Coastguard Workerallow adbd profman_dump_data_file:dir r_dir_perms;
63*e4a36f41SAndroid Build Coastguard Workerallow adbd profman_dump_data_file:file r_file_perms;
64*e4a36f41SAndroid Build Coastguard Worker
65*e4a36f41SAndroid Build Coastguard Worker# adb push/pull sdcard.
66*e4a36f41SAndroid Build Coastguard Workerallow adbd tmpfs:dir search;
67*e4a36f41SAndroid Build Coastguard Workerallow adbd rootfs:lnk_file r_file_perms;  # /sdcard symlink
68*e4a36f41SAndroid Build Coastguard Workerallow adbd tmpfs:lnk_file r_file_perms;   # /mnt/sdcard symlink
69*e4a36f41SAndroid Build Coastguard Workerallow adbd { sdcard_type fuse }:dir create_dir_perms;
70*e4a36f41SAndroid Build Coastguard Workerallow adbd { sdcard_type fuse }:file create_file_perms;
71*e4a36f41SAndroid Build Coastguard Worker
72*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/anr/traces.txt
73*e4a36f41SAndroid Build Coastguard Workerallow adbd anr_data_file:dir r_dir_perms;
74*e4a36f41SAndroid Build Coastguard Workerallow adbd anr_data_file:file r_file_perms;
75*e4a36f41SAndroid Build Coastguard Worker
76*e4a36f41SAndroid Build Coastguard Worker# adb pull /vendor/framework/*
77*e4a36f41SAndroid Build Coastguard Workerallow adbd vendor_framework_file:dir r_dir_perms;
78*e4a36f41SAndroid Build Coastguard Workerallow adbd vendor_framework_file:file r_file_perms;
79*e4a36f41SAndroid Build Coastguard Worker
80*e4a36f41SAndroid Build Coastguard Worker# Set service.adb.*, sys.powerctl, and sys.usb.ffs.ready properties.
81*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, shell_prop)
82*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, powerctl_prop)
83*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, ffs_config_prop)
84*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, ffs_control_prop)
85*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, adbd_tradeinmode_prop)
86*e4a36f41SAndroid Build Coastguard Worker
87*e4a36f41SAndroid Build Coastguard Worker# Allow adbd start/stop mdnsd via ctl.start
88*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, ctl_mdnsd_prop)
89*e4a36f41SAndroid Build Coastguard Worker
90*e4a36f41SAndroid Build Coastguard Worker# Read device's overlayfs related properties and files
91*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
92*e4a36f41SAndroid Build Coastguard Worker  get_prop(adbd, persistent_properties_ready_prop)
93*e4a36f41SAndroid Build Coastguard Worker  r_dir_file(adbd, sysfs_dt_firmware_android)
94*e4a36f41SAndroid Build Coastguard Worker')
95*e4a36f41SAndroid Build Coastguard Worker
96*e4a36f41SAndroid Build Coastguard Worker# Run /system/bin/bu
97*e4a36f41SAndroid Build Coastguard Workerallow adbd system_file:file rx_file_perms;
98*e4a36f41SAndroid Build Coastguard Worker
99*e4a36f41SAndroid Build Coastguard Worker# Perform binder IPC to surfaceflinger (screencap)
100*e4a36f41SAndroid Build Coastguard Worker# XXX Run screencap in a separate domain?
101*e4a36f41SAndroid Build Coastguard Workerbinder_use(adbd)
102*e4a36f41SAndroid Build Coastguard Workerbinder_call(adbd, surfaceflinger)
103*e4a36f41SAndroid Build Coastguard Workerbinder_call(adbd, gpuservice)
104*e4a36f41SAndroid Build Coastguard Worker# b/13188914
105*e4a36f41SAndroid Build Coastguard Workerallow adbd gpu_device:chr_file rw_file_perms;
106*e4a36f41SAndroid Build Coastguard Workerallow adbd gpu_device:dir r_dir_perms;
107*e4a36f41SAndroid Build Coastguard Workerallow adbd ion_device:chr_file rw_file_perms;
108*e4a36f41SAndroid Build Coastguard Workerr_dir_file(adbd, system_file)
109*e4a36f41SAndroid Build Coastguard Worker
110*e4a36f41SAndroid Build Coastguard Worker# Needed for various screenshots
111*e4a36f41SAndroid Build Coastguard Workerhal_client_domain(adbd, hal_graphics_allocator)
112*e4a36f41SAndroid Build Coastguard Worker
113*e4a36f41SAndroid Build Coastguard Worker# Read /data/misc/adb/adb_keys.
114*e4a36f41SAndroid Build Coastguard Workerallow adbd adb_keys_file:dir search;
115*e4a36f41SAndroid Build Coastguard Workerallow adbd adb_keys_file:file r_file_perms;
116*e4a36f41SAndroid Build Coastguard Worker
117*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
118*e4a36f41SAndroid Build Coastguard Worker  # Write debugging information to /data/adb
119*e4a36f41SAndroid Build Coastguard Worker  # when persist.adb.trace_mask is set
120*e4a36f41SAndroid Build Coastguard Worker  # https://code.google.com/p/android/issues/detail?id=72895
121*e4a36f41SAndroid Build Coastguard Worker  allow adbd adb_data_file:dir rw_dir_perms;
122*e4a36f41SAndroid Build Coastguard Worker  allow adbd adb_data_file:file create_file_perms;
123*e4a36f41SAndroid Build Coastguard Worker')
124*e4a36f41SAndroid Build Coastguard Worker
125*e4a36f41SAndroid Build Coastguard Worker# ndk-gdb invokes adb forward to forward the gdbserver socket.
126*e4a36f41SAndroid Build Coastguard Workerallow adbd app_data_file:dir search;
127*e4a36f41SAndroid Build Coastguard Workerallow adbd app_data_file:sock_file write;
128*e4a36f41SAndroid Build Coastguard Workerallow adbd appdomain:unix_stream_socket connectto;
129*e4a36f41SAndroid Build Coastguard Worker
130*e4a36f41SAndroid Build Coastguard Worker# ndk-gdb invokes adb pull of app_process, linker, and libc.so.
131*e4a36f41SAndroid Build Coastguard Workerallow adbd zygote_exec:file r_file_perms;
132*e4a36f41SAndroid Build Coastguard Workerallow adbd system_file:file r_file_perms;
133*e4a36f41SAndroid Build Coastguard Worker
134*e4a36f41SAndroid Build Coastguard Worker# Allow pulling the SELinux policy for CTS purposes
135*e4a36f41SAndroid Build Coastguard Workerallow adbd selinuxfs:dir r_dir_perms;
136*e4a36f41SAndroid Build Coastguard Workerallow adbd selinuxfs:file r_file_perms;
137*e4a36f41SAndroid Build Coastguard Workerallow adbd kernel:security read_policy;
138*e4a36f41SAndroid Build Coastguard Workerallow adbd service_contexts_file:file r_file_perms;
139*e4a36f41SAndroid Build Coastguard Workerallow adbd file_contexts_file:file r_file_perms;
140*e4a36f41SAndroid Build Coastguard Workerallow adbd seapp_contexts_file:file r_file_perms;
141*e4a36f41SAndroid Build Coastguard Workerallow adbd property_contexts_file:file r_file_perms;
142*e4a36f41SAndroid Build Coastguard Workerallow adbd sepolicy_file:file r_file_perms;
143*e4a36f41SAndroid Build Coastguard Worker
144*e4a36f41SAndroid Build Coastguard Worker# Allow pulling config.gz for CTS purposes
145*e4a36f41SAndroid Build Coastguard Workerallow adbd config_gz:file r_file_perms;
146*e4a36f41SAndroid Build Coastguard Worker
147*e4a36f41SAndroid Build Coastguard Worker# For CTS listening ports test.
148*e4a36f41SAndroid Build Coastguard Workerallow adbd proc_net_tcp_udp:file r_file_perms;
149*e4a36f41SAndroid Build Coastguard Worker
150*e4a36f41SAndroid Build Coastguard Workerallow adbd gpu_service:service_manager find;
151*e4a36f41SAndroid Build Coastguard Workerallow adbd surfaceflinger_service:service_manager find;
152*e4a36f41SAndroid Build Coastguard Workerallow adbd bootchart_data_file:dir search;
153*e4a36f41SAndroid Build Coastguard Workerallow adbd bootchart_data_file:file r_file_perms;
154*e4a36f41SAndroid Build Coastguard Worker
155*e4a36f41SAndroid Build Coastguard Worker# Allow access to external storage; we have several visible mount points under /storage
156*e4a36f41SAndroid Build Coastguard Worker# and symlinks to primary storage at places like /storage/sdcard0 and /mnt/user/0/primary
157*e4a36f41SAndroid Build Coastguard Workerallow adbd storage_file:dir r_dir_perms;
158*e4a36f41SAndroid Build Coastguard Workerallow adbd storage_file:lnk_file r_file_perms;
159*e4a36f41SAndroid Build Coastguard Workerallow adbd mnt_user_file:dir r_dir_perms;
160*e4a36f41SAndroid Build Coastguard Workerallow adbd mnt_user_file:lnk_file r_file_perms;
161*e4a36f41SAndroid Build Coastguard Worker
162*e4a36f41SAndroid Build Coastguard Worker# Access to /data/media.
163*e4a36f41SAndroid Build Coastguard Worker# This should be removed if sdcardfs is modified to alter the secontext for its
164*e4a36f41SAndroid Build Coastguard Worker# accesses to the underlying FS.
165*e4a36f41SAndroid Build Coastguard Workerallow adbd media_rw_data_file:dir create_dir_perms;
166*e4a36f41SAndroid Build Coastguard Workerallow adbd media_rw_data_file:file create_file_perms;
167*e4a36f41SAndroid Build Coastguard Worker
168*e4a36f41SAndroid Build Coastguard Workerr_dir_file(adbd, apk_data_file)
169*e4a36f41SAndroid Build Coastguard Worker
170*e4a36f41SAndroid Build Coastguard Workerallow adbd rootfs:dir r_dir_perms;
171*e4a36f41SAndroid Build Coastguard Worker
172*e4a36f41SAndroid Build Coastguard Worker# Allow killing child "perfetto" binary processes, which auto-transition to
173*e4a36f41SAndroid Build Coastguard Worker# their own domain. Allows propagating termination of "adb shell perfetto ..."
174*e4a36f41SAndroid Build Coastguard Worker# invocations.
175*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto:process signal;
176*e4a36f41SAndroid Build Coastguard Worker
177*e4a36f41SAndroid Build Coastguard Worker# Allow to pull Perfetto traces.
178*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_traces_data_file:file r_file_perms;
179*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_traces_data_file:dir r_dir_perms;
180*e4a36f41SAndroid Build Coastguard Worker
181*e4a36f41SAndroid Build Coastguard Worker# Allow to push and manage configs in /data/misc/perfetto-configs.
182*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_configs_data_file:dir rw_dir_perms;
183*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_configs_data_file:file create_file_perms;
184*e4a36f41SAndroid Build Coastguard Worker
185*e4a36f41SAndroid Build Coastguard Worker# Connect to shell and use a socket transferred from it.
186*e4a36f41SAndroid Build Coastguard Worker# Used for e.g. abb.
187*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:unix_stream_socket { read write shutdown };
188*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:fd use;
189*e4a36f41SAndroid Build Coastguard Worker
190*e4a36f41SAndroid Build Coastguard Worker# adb push/pull /data/local/tmp.
191*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_data_file:dir create_dir_perms;
192*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_data_file:file create_file_perms;
193*e4a36f41SAndroid Build Coastguard Worker
194*e4a36f41SAndroid Build Coastguard Worker# Allow pull /vendor/apex files for CTS tests
195*e4a36f41SAndroid Build Coastguard Workerr_dir_file(adbd, vendor_apex_file)
196*e4a36f41SAndroid Build Coastguard Worker
197*e4a36f41SAndroid Build Coastguard Worker# Allow adb pull of updated apex files in /data/apex/active.
198*e4a36f41SAndroid Build Coastguard Workerallow adbd apex_data_file:dir search;
199*e4a36f41SAndroid Build Coastguard Workerallow adbd staging_data_file:file r_file_perms;
200*e4a36f41SAndroid Build Coastguard Worker
201*e4a36f41SAndroid Build Coastguard Worker# Allow adbd to pull /apex/apex-info-list.xml for CTS tests.
202*e4a36f41SAndroid Build Coastguard Workerallow adbd apex_info_file:file r_file_perms;
203*e4a36f41SAndroid Build Coastguard Worker
204*e4a36f41SAndroid Build Coastguard Worker# allow reading tombstones. users can already use bugreports to get those.
205*e4a36f41SAndroid Build Coastguard Workerallow adbd tombstone_data_file:dir r_dir_perms;
206*e4a36f41SAndroid Build Coastguard Workerallow adbd tombstone_data_file:file r_file_perms;
207*e4a36f41SAndroid Build Coastguard Worker
208*e4a36f41SAndroid Build Coastguard Worker# Access /data/local/tests.
209*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_test_data_file:dir create_dir_perms;
210*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_test_data_file:file create_file_perms;
211*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_test_data_file:lnk_file create_file_perms;
212*e4a36f41SAndroid Build Coastguard Worker
213*e4a36f41SAndroid Build Coastguard Worker###
214*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules
215*e4a36f41SAndroid Build Coastguard Worker###
216*e4a36f41SAndroid Build Coastguard Worker
217*e4a36f41SAndroid Build Coastguard Worker# No transitions from adbd to non-shell, non-crash_dump domains. adbd only ever
218*e4a36f41SAndroid Build Coastguard Worker# transitions to the shell or tradeinmode domain (except when it crashes). In
219*e4a36f41SAndroid Build Coastguard Worker# particular, we never want to see a transition from adbd to su (aka "adb root")
220*e4a36f41SAndroid Build Coastguard Workerneverallow adbd { domain -crash_dump -shell -adbd_tradeinmode }:process transition;
221*e4a36f41SAndroid Build Coastguard Workerneverallow adbd {
222*e4a36f41SAndroid Build Coastguard Worker    domain
223*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-su')
224*e4a36f41SAndroid Build Coastguard Worker    recovery_only(`-shell')
225*e4a36f41SAndroid Build Coastguard Worker    -adbd_tradeinmode
226*e4a36f41SAndroid Build Coastguard Worker}:process dyntransition;
227*e4a36f41SAndroid Build Coastguard Worker
228*e4a36f41SAndroid Build Coastguard Worker# Only init is allowed to enter the adbd domain via exec()
229*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } adbd:process transition;
230*e4a36f41SAndroid Build Coastguard Workerneverallow * adbd:process dyntransition;
231