xref: /aosp_15_r20/system/sepolicy/prebuilts/api/33.0/public/shell.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# Domain for shell processes spawned by ADB or console service.
2*e4a36f41SAndroid Build Coastguard Workertype shell, domain, mlstrustedsubject;
3*e4a36f41SAndroid Build Coastguard Workertype shell_exec, system_file_type, exec_type, file_type;
4*e4a36f41SAndroid Build Coastguard Worker
5*e4a36f41SAndroid Build Coastguard Worker# Create and use network sockets.
6*e4a36f41SAndroid Build Coastguard Workernet_domain(shell)
7*e4a36f41SAndroid Build Coastguard Worker
8*e4a36f41SAndroid Build Coastguard Worker# logcat
9*e4a36f41SAndroid Build Coastguard Workerread_logd(shell)
10*e4a36f41SAndroid Build Coastguard Workercontrol_logd(shell)
11*e4a36f41SAndroid Build Coastguard Workerget_prop(shell, logd_prop)
12*e4a36f41SAndroid Build Coastguard Worker# logcat -L (directly, or via dumpstate)
13*e4a36f41SAndroid Build Coastguard Workerallow shell pstorefs:dir search;
14*e4a36f41SAndroid Build Coastguard Workerallow shell pstorefs:file r_file_perms;
15*e4a36f41SAndroid Build Coastguard Worker
16*e4a36f41SAndroid Build Coastguard Worker# Root fs.
17*e4a36f41SAndroid Build Coastguard Workerallow shell rootfs:dir r_dir_perms;
18*e4a36f41SAndroid Build Coastguard Worker
19*e4a36f41SAndroid Build Coastguard Worker# read files in /data/anr
20*e4a36f41SAndroid Build Coastguard Workerallow shell anr_data_file:dir r_dir_perms;
21*e4a36f41SAndroid Build Coastguard Workerallow shell anr_data_file:file r_file_perms;
22*e4a36f41SAndroid Build Coastguard Worker
23*e4a36f41SAndroid Build Coastguard Worker# Access /data/local/tmp.
24*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:dir create_dir_perms;
25*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:file create_file_perms;
26*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:file rx_file_perms;
27*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:lnk_file create_file_perms;
28*e4a36f41SAndroid Build Coastguard Worker
29*e4a36f41SAndroid Build Coastguard Worker# Access /data/local/tests.
30*e4a36f41SAndroid Build Coastguard Workerallow shell shell_test_data_file:dir create_dir_perms;
31*e4a36f41SAndroid Build Coastguard Workerallow shell shell_test_data_file:file create_file_perms;
32*e4a36f41SAndroid Build Coastguard Workerallow shell shell_test_data_file:file rx_file_perms;
33*e4a36f41SAndroid Build Coastguard Workerallow shell shell_test_data_file:lnk_file create_file_perms;
34*e4a36f41SAndroid Build Coastguard Workerallow shell shell_test_data_file:sock_file create_file_perms;
35*e4a36f41SAndroid Build Coastguard Worker
36*e4a36f41SAndroid Build Coastguard Worker# Read and delete from /data/local/traces.
37*e4a36f41SAndroid Build Coastguard Workerallow shell trace_data_file:file { r_file_perms unlink };
38*e4a36f41SAndroid Build Coastguard Workerallow shell trace_data_file:dir { r_dir_perms remove_name write };
39*e4a36f41SAndroid Build Coastguard Worker
40*e4a36f41SAndroid Build Coastguard Worker# Access /data/misc/profman.
41*e4a36f41SAndroid Build Coastguard Workerallow shell profman_dump_data_file:dir { write remove_name r_dir_perms };
42*e4a36f41SAndroid Build Coastguard Workerallow shell profman_dump_data_file:file { unlink r_file_perms };
43*e4a36f41SAndroid Build Coastguard Worker
44*e4a36f41SAndroid Build Coastguard Worker# Read/execute files in /data/nativetest
45*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
46*e4a36f41SAndroid Build Coastguard Worker  allow shell nativetest_data_file:dir r_dir_perms;
47*e4a36f41SAndroid Build Coastguard Worker  allow shell nativetest_data_file:file rx_file_perms;
48*e4a36f41SAndroid Build Coastguard Worker')
49*e4a36f41SAndroid Build Coastguard Worker
50*e4a36f41SAndroid Build Coastguard Worker# adb bugreport
51*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(shell, dumpstate, dumpstate)
52*e4a36f41SAndroid Build Coastguard Worker
53*e4a36f41SAndroid Build Coastguard Workerallow shell devpts:chr_file rw_file_perms;
54*e4a36f41SAndroid Build Coastguard Workerallow shell tty_device:chr_file rw_file_perms;
55*e4a36f41SAndroid Build Coastguard Workerallow shell console_device:chr_file rw_file_perms;
56*e4a36f41SAndroid Build Coastguard Worker
57*e4a36f41SAndroid Build Coastguard Workerallow shell input_device:dir r_dir_perms;
58*e4a36f41SAndroid Build Coastguard Workerallow shell input_device:chr_file r_file_perms;
59*e4a36f41SAndroid Build Coastguard Worker
60*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, system_file)
61*e4a36f41SAndroid Build Coastguard Workerallow shell system_file:file x_file_perms;
62*e4a36f41SAndroid Build Coastguard Workerallow shell toolbox_exec:file rx_file_perms;
63*e4a36f41SAndroid Build Coastguard Workerallow shell tzdatacheck_exec:file rx_file_perms;
64*e4a36f41SAndroid Build Coastguard Workerallow shell shell_exec:file rx_file_perms;
65*e4a36f41SAndroid Build Coastguard Workerallow shell zygote_exec:file rx_file_perms;
66*e4a36f41SAndroid Build Coastguard Worker
67*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, apk_data_file)
68*e4a36f41SAndroid Build Coastguard Worker
69*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
70*e4a36f41SAndroid Build Coastguard Worker  # "systrace --boot" support - allow boottrace service to run
71*e4a36f41SAndroid Build Coastguard Worker  allow shell boottrace_data_file:dir rw_dir_perms;
72*e4a36f41SAndroid Build Coastguard Worker  allow shell boottrace_data_file:file create_file_perms;
73*e4a36f41SAndroid Build Coastguard Worker')
74*e4a36f41SAndroid Build Coastguard Worker
75*e4a36f41SAndroid Build Coastguard Worker# allow shell access to services
76*e4a36f41SAndroid Build Coastguard Workerallow shell servicemanager:service_manager list;
77*e4a36f41SAndroid Build Coastguard Worker# don't allow shell to access GateKeeper service
78*e4a36f41SAndroid Build Coastguard Worker# TODO: why is this so broad? Tightening candidate? It needs at list:
79*e4a36f41SAndroid Build Coastguard Worker# - dumpstate_service (so it can receive dumpstate progress updates)
80*e4a36f41SAndroid Build Coastguard Workerallow shell {
81*e4a36f41SAndroid Build Coastguard Worker  service_manager_type
82*e4a36f41SAndroid Build Coastguard Worker  -apex_service
83*e4a36f41SAndroid Build Coastguard Worker  -dnsresolver_service
84*e4a36f41SAndroid Build Coastguard Worker  -gatekeeper_service
85*e4a36f41SAndroid Build Coastguard Worker  -incident_service
86*e4a36f41SAndroid Build Coastguard Worker  -installd_service
87*e4a36f41SAndroid Build Coastguard Worker  -iorapd_service
88*e4a36f41SAndroid Build Coastguard Worker  -mdns_service
89*e4a36f41SAndroid Build Coastguard Worker  -netd_service
90*e4a36f41SAndroid Build Coastguard Worker  -system_suspend_control_internal_service
91*e4a36f41SAndroid Build Coastguard Worker  -system_suspend_control_service
92*e4a36f41SAndroid Build Coastguard Worker  -virtual_touchpad_service
93*e4a36f41SAndroid Build Coastguard Worker  -vold_service
94*e4a36f41SAndroid Build Coastguard Worker  -default_android_service
95*e4a36f41SAndroid Build Coastguard Worker}:service_manager find;
96*e4a36f41SAndroid Build Coastguard Workerallow shell dumpstate:binder call;
97*e4a36f41SAndroid Build Coastguard Worker
98*e4a36f41SAndroid Build Coastguard Worker# allow shell to get information from hwservicemanager
99*e4a36f41SAndroid Build Coastguard Worker# for instance, listing hardware services with lshal
100*e4a36f41SAndroid Build Coastguard Workerhwbinder_use(shell)
101*e4a36f41SAndroid Build Coastguard Workerallow shell hwservicemanager:hwservice_manager list;
102*e4a36f41SAndroid Build Coastguard Worker
103*e4a36f41SAndroid Build Coastguard Worker# allow shell to look through /proc/ for lsmod, ps, top, netstat, vmstat.
104*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, proc_net_type)
105*e4a36f41SAndroid Build Coastguard Worker
106*e4a36f41SAndroid Build Coastguard Workerallow shell {
107*e4a36f41SAndroid Build Coastguard Worker  proc_asound
108*e4a36f41SAndroid Build Coastguard Worker  proc_filesystems
109*e4a36f41SAndroid Build Coastguard Worker  proc_interrupts
110*e4a36f41SAndroid Build Coastguard Worker  proc_loadavg # b/124024827
111*e4a36f41SAndroid Build Coastguard Worker  proc_meminfo
112*e4a36f41SAndroid Build Coastguard Worker  proc_modules
113*e4a36f41SAndroid Build Coastguard Worker  proc_pid_max
114*e4a36f41SAndroid Build Coastguard Worker  proc_slabinfo
115*e4a36f41SAndroid Build Coastguard Worker  proc_stat
116*e4a36f41SAndroid Build Coastguard Worker  proc_timer
117*e4a36f41SAndroid Build Coastguard Worker  proc_uptime
118*e4a36f41SAndroid Build Coastguard Worker  proc_version
119*e4a36f41SAndroid Build Coastguard Worker  proc_vmstat
120*e4a36f41SAndroid Build Coastguard Worker  proc_zoneinfo
121*e4a36f41SAndroid Build Coastguard Worker}:file r_file_perms;
122*e4a36f41SAndroid Build Coastguard Worker
123*e4a36f41SAndroid Build Coastguard Worker# allow listing network interfaces under /sys/class/net.
124*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs_net:dir r_dir_perms;
125*e4a36f41SAndroid Build Coastguard Worker
126*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, cgroup)
127*e4a36f41SAndroid Build Coastguard Workerallow shell cgroup_desc_file:file r_file_perms;
128*e4a36f41SAndroid Build Coastguard Workerallow shell cgroup_desc_api_file:file r_file_perms;
129*e4a36f41SAndroid Build Coastguard Workerallow shell vendor_cgroup_desc_file:file r_file_perms;
130*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, cgroup_v2)
131*e4a36f41SAndroid Build Coastguard Workerallow shell domain:dir { search open read getattr };
132*e4a36f41SAndroid Build Coastguard Workerallow shell domain:{ file lnk_file } { open read getattr };
133*e4a36f41SAndroid Build Coastguard Worker
134*e4a36f41SAndroid Build Coastguard Worker# statvfs() of /proc and other labeled filesystems
135*e4a36f41SAndroid Build Coastguard Worker# (yaffs2, jffs2, ext2, ext3, ext4, xfs, btrfs, f2fs, squashfs, overlay)
136*e4a36f41SAndroid Build Coastguard Workerallow shell { proc labeledfs }:filesystem getattr;
137*e4a36f41SAndroid Build Coastguard Worker
138*e4a36f41SAndroid Build Coastguard Worker# stat() of /dev
139*e4a36f41SAndroid Build Coastguard Workerallow shell device:dir getattr;
140*e4a36f41SAndroid Build Coastguard Worker
141*e4a36f41SAndroid Build Coastguard Worker# allow shell to read /proc/pid/attr/current for ps -Z
142*e4a36f41SAndroid Build Coastguard Workerallow shell domain:process getattr;
143*e4a36f41SAndroid Build Coastguard Worker
144*e4a36f41SAndroid Build Coastguard Worker# Allow pulling the SELinux policy for CTS purposes
145*e4a36f41SAndroid Build Coastguard Workerallow shell selinuxfs:dir r_dir_perms;
146*e4a36f41SAndroid Build Coastguard Workerallow shell selinuxfs:file r_file_perms;
147*e4a36f41SAndroid Build Coastguard Worker
148*e4a36f41SAndroid Build Coastguard Worker# enable shell domain to read/write files/dirs for bootchart data
149*e4a36f41SAndroid Build Coastguard Worker# User will creates the start and stop file via adb shell
150*e4a36f41SAndroid Build Coastguard Worker# and read other files created by init process under /data/bootchart
151*e4a36f41SAndroid Build Coastguard Workerallow shell bootchart_data_file:dir rw_dir_perms;
152*e4a36f41SAndroid Build Coastguard Workerallow shell bootchart_data_file:file create_file_perms;
153*e4a36f41SAndroid Build Coastguard Worker
154*e4a36f41SAndroid Build Coastguard Worker# Make sure strace works for the non-privileged shell user
155*e4a36f41SAndroid Build Coastguard Workerallow shell self:process ptrace;
156*e4a36f41SAndroid Build Coastguard Worker
157*e4a36f41SAndroid Build Coastguard Worker# allow shell to get battery info
158*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs:dir r_dir_perms;
159*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs_batteryinfo:dir r_dir_perms;
160*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs_batteryinfo:file r_file_perms;
161*e4a36f41SAndroid Build Coastguard Worker
162*e4a36f41SAndroid Build Coastguard Worker# Allow access to ion memory allocation device.
163*e4a36f41SAndroid Build Coastguard Workerallow shell ion_device:chr_file rw_file_perms;
164*e4a36f41SAndroid Build Coastguard Worker
165*e4a36f41SAndroid Build Coastguard Worker#
166*e4a36f41SAndroid Build Coastguard Worker# filesystem test for insecure chr_file's is done
167*e4a36f41SAndroid Build Coastguard Worker# via a host side test
168*e4a36f41SAndroid Build Coastguard Worker#
169*e4a36f41SAndroid Build Coastguard Workerallow shell dev_type:dir r_dir_perms;
170*e4a36f41SAndroid Build Coastguard Workerallow shell dev_type:chr_file getattr;
171*e4a36f41SAndroid Build Coastguard Worker
172*e4a36f41SAndroid Build Coastguard Worker# /dev/fd is a symlink
173*e4a36f41SAndroid Build Coastguard Workerallow shell proc:lnk_file getattr;
174*e4a36f41SAndroid Build Coastguard Worker
175*e4a36f41SAndroid Build Coastguard Worker#
176*e4a36f41SAndroid Build Coastguard Worker# filesystem test for insucre blk_file's is done
177*e4a36f41SAndroid Build Coastguard Worker# via hostside test
178*e4a36f41SAndroid Build Coastguard Worker#
179*e4a36f41SAndroid Build Coastguard Workerallow shell dev_type:blk_file getattr;
180*e4a36f41SAndroid Build Coastguard Worker
181*e4a36f41SAndroid Build Coastguard Worker# read selinux policy files
182*e4a36f41SAndroid Build Coastguard Workerallow shell file_contexts_file:file r_file_perms;
183*e4a36f41SAndroid Build Coastguard Workerallow shell property_contexts_file:file r_file_perms;
184*e4a36f41SAndroid Build Coastguard Workerallow shell seapp_contexts_file:file r_file_perms;
185*e4a36f41SAndroid Build Coastguard Workerallow shell service_contexts_file:file r_file_perms;
186*e4a36f41SAndroid Build Coastguard Workerallow shell sepolicy_file:file r_file_perms;
187*e4a36f41SAndroid Build Coastguard Worker
188*e4a36f41SAndroid Build Coastguard Worker# Allow shell to start up vendor shell
189*e4a36f41SAndroid Build Coastguard Workerallow shell vendor_shell_exec:file rx_file_perms;
190*e4a36f41SAndroid Build Coastguard Worker
191*e4a36f41SAndroid Build Coastguard Worker# Everything is labeled as rootfs in recovery mode. Allow shell to
192*e4a36f41SAndroid Build Coastguard Worker# execute them.
193*e4a36f41SAndroid Build Coastguard Workerrecovery_only(`
194*e4a36f41SAndroid Build Coastguard Worker  allow shell rootfs:file rx_file_perms;
195*e4a36f41SAndroid Build Coastguard Worker')
196*e4a36f41SAndroid Build Coastguard Worker
197*e4a36f41SAndroid Build Coastguard Worker###
198*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules
199*e4a36f41SAndroid Build Coastguard Worker###
200*e4a36f41SAndroid Build Coastguard Worker
201*e4a36f41SAndroid Build Coastguard Worker# Do not allow shell to hard link to any files.
202*e4a36f41SAndroid Build Coastguard Worker# In particular, if shell hard links to app data
203*e4a36f41SAndroid Build Coastguard Worker# files, installd will not be able to guarantee the deletion
204*e4a36f41SAndroid Build Coastguard Worker# of the linked to file. Hard links also contribute to security
205*e4a36f41SAndroid Build Coastguard Worker# bugs, so we want to ensure the shell user never has this
206*e4a36f41SAndroid Build Coastguard Worker# capability.
207*e4a36f41SAndroid Build Coastguard Workerneverallow shell file_type:file link;
208*e4a36f41SAndroid Build Coastguard Worker
209*e4a36f41SAndroid Build Coastguard Worker# Do not allow privileged socket ioctl commands
210*e4a36f41SAndroid Build Coastguard Workerneverallowxperm shell domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
211*e4a36f41SAndroid Build Coastguard Worker
212*e4a36f41SAndroid Build Coastguard Worker# limit shell access to sensitive char drivers to
213*e4a36f41SAndroid Build Coastguard Worker# only getattr required for host side test.
214*e4a36f41SAndroid Build Coastguard Workerneverallow shell {
215*e4a36f41SAndroid Build Coastguard Worker  fuse_device
216*e4a36f41SAndroid Build Coastguard Worker  hw_random_device
217*e4a36f41SAndroid Build Coastguard Worker  port_device
218*e4a36f41SAndroid Build Coastguard Worker}:chr_file ~getattr;
219*e4a36f41SAndroid Build Coastguard Worker
220*e4a36f41SAndroid Build Coastguard Worker# Limit shell to only getattr on blk devices for host side tests.
221*e4a36f41SAndroid Build Coastguard Workerneverallow shell dev_type:blk_file ~getattr;
222*e4a36f41SAndroid Build Coastguard Worker
223*e4a36f41SAndroid Build Coastguard Worker# b/30861057: Shell access to existing input devices is an abuse
224*e4a36f41SAndroid Build Coastguard Worker# vector. The shell user can inject events that look like they
225*e4a36f41SAndroid Build Coastguard Worker# originate from the touchscreen etc.
226*e4a36f41SAndroid Build Coastguard Worker# Everyone should have already moved to UiAutomation#injectInputEvent
227*e4a36f41SAndroid Build Coastguard Worker# if they are running instrumentation tests (i.e. CTS), Monkey for
228*e4a36f41SAndroid Build Coastguard Worker# their stress tests, and the input command (adb shell input ...) for
229*e4a36f41SAndroid Build Coastguard Worker# injecting swipes and things.
230*e4a36f41SAndroid Build Coastguard Workerneverallow shell input_device:chr_file no_w_file_perms;
231