xref: /aosp_15_r20/system/sepolicy/prebuilts/api/29.0/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 Worker
6*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(adbd)
7*e4a36f41SAndroid Build Coastguard Worker
8*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(adbd, shell_exec, shell)
9*e4a36f41SAndroid Build Coastguard Worker
10*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
11*e4a36f41SAndroid Build Coastguard Worker  allow adbd self:process setcurrent;
12*e4a36f41SAndroid Build Coastguard Worker  allow adbd su:process dyntransition;
13*e4a36f41SAndroid Build Coastguard Worker')
14*e4a36f41SAndroid Build Coastguard Worker
15*e4a36f41SAndroid Build Coastguard Worker# When 'adb shell' is executed in recovery mode, adbd explicitly
16*e4a36f41SAndroid Build Coastguard Worker# switches into shell domain using setcon() because the shell executable
17*e4a36f41SAndroid Build Coastguard Worker# is not labeled as shell but as rootfs.
18*e4a36f41SAndroid Build Coastguard Workerrecovery_only(`
19*e4a36f41SAndroid Build Coastguard Worker  domain_trans(adbd, rootfs, shell)
20*e4a36f41SAndroid Build Coastguard Worker  allow adbd shell:process dyntransition;
21*e4a36f41SAndroid Build Coastguard Worker
22*e4a36f41SAndroid Build Coastguard Worker  # Allows reboot fastboot to enter fastboot directly
23*e4a36f41SAndroid Build Coastguard Worker  unix_socket_connect(adbd, recovery, recovery)
24*e4a36f41SAndroid Build Coastguard Worker')
25*e4a36f41SAndroid Build Coastguard Worker
26*e4a36f41SAndroid Build Coastguard Worker# Control Perfetto traced and obtain traces from it.
27*e4a36f41SAndroid Build Coastguard Worker# Needed to allow port forwarding directly to traced.
28*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(adbd, traced_consumer, traced)
29*e4a36f41SAndroid Build Coastguard Worker
30*e4a36f41SAndroid Build Coastguard Worker# Do not sanitize the environment or open fds of the shell. Allow signaling
31*e4a36f41SAndroid Build Coastguard Worker# created processes.
32*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:process { noatsecure signal };
33*e4a36f41SAndroid Build Coastguard Worker
34*e4a36f41SAndroid Build Coastguard Worker# Set UID and GID to shell.  Set supplementary groups.
35*e4a36f41SAndroid Build Coastguard Workerallow adbd self:global_capability_class_set { setuid setgid };
36*e4a36f41SAndroid Build Coastguard Worker
37*e4a36f41SAndroid Build Coastguard Worker# Drop capabilities from bounding set on user builds.
38*e4a36f41SAndroid Build Coastguard Workerallow adbd self:global_capability_class_set setpcap;
39*e4a36f41SAndroid Build Coastguard Worker
40*e4a36f41SAndroid Build Coastguard Worker# ignore spurious denials for adbd when disk space is low.
41*e4a36f41SAndroid Build Coastguard Workerdontaudit adbd self:global_capability_class_set sys_resource;
42*e4a36f41SAndroid Build Coastguard Worker
43*e4a36f41SAndroid Build Coastguard Worker# adbd probes for vsock support. Do not generate denials when
44*e4a36f41SAndroid Build Coastguard Worker# this occurs. (b/123569840)
45*e4a36f41SAndroid Build Coastguard Workerdontaudit adbd self:{ socket vsock_socket } create;
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
50*e4a36f41SAndroid Build Coastguard Worker# Access /dev/usb-ffs/adb/ep0
51*e4a36f41SAndroid Build Coastguard Workerallow adbd functionfs:dir search;
52*e4a36f41SAndroid Build Coastguard Workerallow adbd functionfs:file rw_file_perms;
53*e4a36f41SAndroid Build Coastguard Workerallowxperm adbd functionfs:file ioctl {
54*e4a36f41SAndroid Build Coastguard Worker  FUNCTIONFS_ENDPOINT_DESC
55*e4a36f41SAndroid Build Coastguard Worker  FUNCTIONFS_CLEAR_HALT
56*e4a36f41SAndroid Build Coastguard Worker};
57*e4a36f41SAndroid Build Coastguard Worker
58*e4a36f41SAndroid Build Coastguard Worker# Use a pseudo tty.
59*e4a36f41SAndroid Build Coastguard Workerallow adbd devpts:chr_file rw_file_perms;
60*e4a36f41SAndroid Build Coastguard Worker
61*e4a36f41SAndroid Build Coastguard Worker# adb push/pull /data/local/tmp.
62*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_data_file:dir create_dir_perms;
63*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_data_file:file create_file_perms;
64*e4a36f41SAndroid Build Coastguard Worker
65*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/local/traces/*
66*e4a36f41SAndroid Build Coastguard Workerallow adbd trace_data_file:dir r_dir_perms;
67*e4a36f41SAndroid Build Coastguard Workerallow adbd trace_data_file:file r_file_perms;
68*e4a36f41SAndroid Build Coastguard Worker
69*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/misc/profman.
70*e4a36f41SAndroid Build Coastguard Workerallow adbd profman_dump_data_file:dir r_dir_perms;
71*e4a36f41SAndroid Build Coastguard Workerallow adbd profman_dump_data_file:file r_file_perms;
72*e4a36f41SAndroid Build Coastguard Worker
73*e4a36f41SAndroid Build Coastguard Worker# adb push/pull sdcard.
74*e4a36f41SAndroid Build Coastguard Workerallow adbd tmpfs:dir search;
75*e4a36f41SAndroid Build Coastguard Workerallow adbd rootfs:lnk_file r_file_perms;  # /sdcard symlink
76*e4a36f41SAndroid Build Coastguard Workerallow adbd tmpfs:lnk_file r_file_perms;   # /mnt/sdcard symlink
77*e4a36f41SAndroid Build Coastguard Workerallow adbd sdcard_type:dir create_dir_perms;
78*e4a36f41SAndroid Build Coastguard Workerallow adbd sdcard_type:file create_file_perms;
79*e4a36f41SAndroid Build Coastguard Worker
80*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/anr/traces.txt
81*e4a36f41SAndroid Build Coastguard Workerallow adbd anr_data_file:dir r_dir_perms;
82*e4a36f41SAndroid Build Coastguard Workerallow adbd anr_data_file:file r_file_perms;
83*e4a36f41SAndroid Build Coastguard Worker
84*e4a36f41SAndroid Build Coastguard Worker# Set service.adb.*, sys.powerctl, and sys.usb.ffs.ready properties.
85*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, shell_prop)
86*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, powerctl_prop)
87*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, ffs_prop)
88*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, exported_ffs_prop)
89*e4a36f41SAndroid Build Coastguard Worker
90*e4a36f41SAndroid Build Coastguard Worker# Access device logging gating property
91*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, device_logging_prop)
92*e4a36f41SAndroid Build Coastguard Worker
93*e4a36f41SAndroid Build Coastguard Worker# Read device's serial number from system properties
94*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, serialno_prop)
95*e4a36f41SAndroid Build Coastguard Worker
96*e4a36f41SAndroid Build Coastguard Worker# Read whether or not Test Harness Mode is enabled
97*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, test_harness_prop)
98*e4a36f41SAndroid Build Coastguard Worker
99*e4a36f41SAndroid Build Coastguard Worker# Read device's overlayfs related properties and files
100*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
101*e4a36f41SAndroid Build Coastguard Worker  get_prop(adbd, persistent_properties_ready_prop)
102*e4a36f41SAndroid Build Coastguard Worker  r_dir_file(adbd, sysfs_dt_firmware_android)
103*e4a36f41SAndroid Build Coastguard Worker')
104*e4a36f41SAndroid Build Coastguard Worker
105*e4a36f41SAndroid Build Coastguard Worker# Run /system/bin/bu
106*e4a36f41SAndroid Build Coastguard Workerallow adbd system_file:file rx_file_perms;
107*e4a36f41SAndroid Build Coastguard Worker
108*e4a36f41SAndroid Build Coastguard Worker# Perform binder IPC to surfaceflinger (screencap)
109*e4a36f41SAndroid Build Coastguard Worker# XXX Run screencap in a separate domain?
110*e4a36f41SAndroid Build Coastguard Workerbinder_use(adbd)
111*e4a36f41SAndroid Build Coastguard Workerbinder_call(adbd, surfaceflinger)
112*e4a36f41SAndroid Build Coastguard Workerbinder_call(adbd, gpuservice)
113*e4a36f41SAndroid Build Coastguard Worker# b/13188914
114*e4a36f41SAndroid Build Coastguard Workerallow adbd gpu_device:chr_file rw_file_perms;
115*e4a36f41SAndroid Build Coastguard Workerallow adbd ion_device:chr_file rw_file_perms;
116*e4a36f41SAndroid Build Coastguard Workerr_dir_file(adbd, system_file)
117*e4a36f41SAndroid Build Coastguard Worker
118*e4a36f41SAndroid Build Coastguard Worker# Needed for various screenshots
119*e4a36f41SAndroid Build Coastguard Workerhal_client_domain(adbd, hal_graphics_allocator)
120*e4a36f41SAndroid Build Coastguard Worker
121*e4a36f41SAndroid Build Coastguard Worker# Read /data/misc/adb/adb_keys.
122*e4a36f41SAndroid Build Coastguard Workerallow adbd adb_keys_file:dir search;
123*e4a36f41SAndroid Build Coastguard Workerallow adbd adb_keys_file:file r_file_perms;
124*e4a36f41SAndroid Build Coastguard Worker
125*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
126*e4a36f41SAndroid Build Coastguard Worker  # Write debugging information to /data/adb
127*e4a36f41SAndroid Build Coastguard Worker  # when persist.adb.trace_mask is set
128*e4a36f41SAndroid Build Coastguard Worker  # https://code.google.com/p/android/issues/detail?id=72895
129*e4a36f41SAndroid Build Coastguard Worker  allow adbd adb_data_file:dir rw_dir_perms;
130*e4a36f41SAndroid Build Coastguard Worker  allow adbd adb_data_file:file create_file_perms;
131*e4a36f41SAndroid Build Coastguard Worker')
132*e4a36f41SAndroid Build Coastguard Worker
133*e4a36f41SAndroid Build Coastguard Worker# ndk-gdb invokes adb forward to forward the gdbserver socket.
134*e4a36f41SAndroid Build Coastguard Workerallow adbd app_data_file:dir search;
135*e4a36f41SAndroid Build Coastguard Workerallow adbd app_data_file:sock_file write;
136*e4a36f41SAndroid Build Coastguard Workerallow adbd appdomain:unix_stream_socket connectto;
137*e4a36f41SAndroid Build Coastguard Worker
138*e4a36f41SAndroid Build Coastguard Worker# ndk-gdb invokes adb pull of app_process, linker, and libc.so.
139*e4a36f41SAndroid Build Coastguard Workerallow adbd zygote_exec:file r_file_perms;
140*e4a36f41SAndroid Build Coastguard Workerallow adbd system_file:file r_file_perms;
141*e4a36f41SAndroid Build Coastguard Worker
142*e4a36f41SAndroid Build Coastguard Worker# Allow pulling the SELinux policy for CTS purposes
143*e4a36f41SAndroid Build Coastguard Workerallow adbd selinuxfs:dir r_dir_perms;
144*e4a36f41SAndroid Build Coastguard Workerallow adbd selinuxfs:file r_file_perms;
145*e4a36f41SAndroid Build Coastguard Workerallow adbd kernel:security read_policy;
146*e4a36f41SAndroid Build Coastguard Workerallow adbd service_contexts_file:file r_file_perms;
147*e4a36f41SAndroid Build Coastguard Workerallow adbd file_contexts_file:file r_file_perms;
148*e4a36f41SAndroid Build Coastguard Workerallow adbd seapp_contexts_file:file r_file_perms;
149*e4a36f41SAndroid Build Coastguard Workerallow adbd property_contexts_file:file r_file_perms;
150*e4a36f41SAndroid Build Coastguard Workerallow adbd sepolicy_file:file r_file_perms;
151*e4a36f41SAndroid Build Coastguard Worker
152*e4a36f41SAndroid Build Coastguard Worker# Allow pulling config.gz for CTS purposes
153*e4a36f41SAndroid Build Coastguard Workerallow adbd config_gz:file r_file_perms;
154*e4a36f41SAndroid Build Coastguard Worker
155*e4a36f41SAndroid Build Coastguard Worker# For CTS listening ports test.
156*e4a36f41SAndroid Build Coastguard Workerallow adbd proc_net_tcp_udp:file r_file_perms;
157*e4a36f41SAndroid Build Coastguard Worker
158*e4a36f41SAndroid Build Coastguard Workerallow adbd gpu_service:service_manager find;
159*e4a36f41SAndroid Build Coastguard Workerallow adbd surfaceflinger_service:service_manager find;
160*e4a36f41SAndroid Build Coastguard Workerallow adbd bootchart_data_file:dir search;
161*e4a36f41SAndroid Build Coastguard Workerallow adbd bootchart_data_file:file r_file_perms;
162*e4a36f41SAndroid Build Coastguard Worker
163*e4a36f41SAndroid Build Coastguard Worker# Allow access to external storage; we have several visible mount points under /storage
164*e4a36f41SAndroid Build Coastguard Worker# and symlinks to primary storage at places like /storage/sdcard0 and /mnt/user/0/primary
165*e4a36f41SAndroid Build Coastguard Workerallow adbd storage_file:dir r_dir_perms;
166*e4a36f41SAndroid Build Coastguard Workerallow adbd storage_file:lnk_file r_file_perms;
167*e4a36f41SAndroid Build Coastguard Workerallow adbd mnt_user_file:dir r_dir_perms;
168*e4a36f41SAndroid Build Coastguard Workerallow adbd mnt_user_file:lnk_file r_file_perms;
169*e4a36f41SAndroid Build Coastguard Worker
170*e4a36f41SAndroid Build Coastguard Worker# Access to /data/media.
171*e4a36f41SAndroid Build Coastguard Worker# This should be removed if sdcardfs is modified to alter the secontext for its
172*e4a36f41SAndroid Build Coastguard Worker# accesses to the underlying FS.
173*e4a36f41SAndroid Build Coastguard Workerallow adbd media_rw_data_file:dir create_dir_perms;
174*e4a36f41SAndroid Build Coastguard Workerallow adbd media_rw_data_file:file create_file_perms;
175*e4a36f41SAndroid Build Coastguard Worker
176*e4a36f41SAndroid Build Coastguard Workerr_dir_file(adbd, apk_data_file)
177*e4a36f41SAndroid Build Coastguard Worker
178*e4a36f41SAndroid Build Coastguard Workerallow adbd rootfs:dir r_dir_perms;
179*e4a36f41SAndroid Build Coastguard Worker
180*e4a36f41SAndroid Build Coastguard Worker# Allow to pull Perfetto traces.
181*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_traces_data_file:file r_file_perms;
182*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_traces_data_file:dir r_dir_perms;
183*e4a36f41SAndroid Build Coastguard Worker
184*e4a36f41SAndroid Build Coastguard Worker# Connect to shell and use a socket transferred from it.
185*e4a36f41SAndroid Build Coastguard Worker# Used for e.g. abb.
186*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:unix_stream_socket { read write };
187*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:fd use;
188*e4a36f41SAndroid Build Coastguard Worker
189*e4a36f41SAndroid Build Coastguard Worker###
190*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules
191*e4a36f41SAndroid Build Coastguard Worker###
192*e4a36f41SAndroid Build Coastguard Worker
193*e4a36f41SAndroid Build Coastguard Worker# No transitions from adbd to non-shell, non-crash_dump domains. adbd only ever
194*e4a36f41SAndroid Build Coastguard Worker# transitions to the shell domain (except when it crashes). In particular, we
195*e4a36f41SAndroid Build Coastguard Worker# never want to see a transition from adbd to su (aka "adb root")
196*e4a36f41SAndroid Build Coastguard Workerneverallow adbd { domain -crash_dump -shell }:process transition;
197*e4a36f41SAndroid Build Coastguard Workerneverallow adbd { domain userdebug_or_eng(`-su') recovery_only(`-shell') }:process dyntransition;
198