• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Domain for shell processes spawned by ADB or console service.
2type shell, domain, mlstrustedsubject;
3type shell_exec, exec_type, file_type;
4
5# Create and use network sockets.
6net_domain(shell)
7
8# logcat
9read_logd(shell)
10control_logd(shell)
11# logcat -L (directly, or via dumpstate)
12allow shell pstorefs:dir search;
13allow shell pstorefs:file r_file_perms;
14
15# Root fs.
16allow shell rootfs:dir r_dir_perms;
17
18# read files in /data/anr
19allow shell anr_data_file:dir r_dir_perms;
20allow shell anr_data_file:file r_file_perms;
21
22# Access /data/local/tmp.
23allow shell shell_data_file:dir create_dir_perms;
24allow shell shell_data_file:file create_file_perms;
25allow shell shell_data_file:file rx_file_perms;
26allow shell shell_data_file:lnk_file create_file_perms;
27
28# Access /data/misc/profman.
29allow shell profman_dump_data_file:dir { search getattr write remove_name };
30allow shell profman_dump_data_file:file { getattr unlink };
31
32# Read/execute files in /data/nativetest
33userdebug_or_eng(`
34  allow shell nativetest_data_file:dir r_dir_perms;
35  allow shell nativetest_data_file:file rx_file_perms;
36')
37
38# adb bugreport
39unix_socket_connect(shell, dumpstate, dumpstate)
40
41allow shell devpts:chr_file rw_file_perms;
42allow shell tty_device:chr_file rw_file_perms;
43allow shell console_device:chr_file rw_file_perms;
44allow shell input_device:dir r_dir_perms;
45allow shell input_device:chr_file rw_file_perms;
46r_dir_file(shell, system_file)
47allow shell system_file:file x_file_perms;
48allow shell toolbox_exec:file rx_file_perms;
49allow shell shell_exec:file rx_file_perms;
50allow shell zygote_exec:file rx_file_perms;
51
52r_dir_file(shell, apk_data_file)
53
54# Set properties.
55set_prop(shell, shell_prop)
56set_prop(shell, ctl_bugreport_prop)
57set_prop(shell, ctl_dumpstate_prop)
58set_prop(shell, dumpstate_prop)
59set_prop(shell, debug_prop)
60set_prop(shell, powerctl_prop)
61set_prop(shell, log_tag_prop)
62set_prop(shell, wifi_log_prop)
63# adjust is_loggable properties
64userdebug_or_eng(`set_prop(shell, log_prop)')
65# logpersist script
66userdebug_or_eng(`set_prop(shell, logpersistd_logging_prop)')
67
68userdebug_or_eng(`
69  # "systrace --boot" support - allow boottrace service to run
70  allow shell boottrace_data_file:dir rw_dir_perms;
71  allow shell boottrace_data_file:file create_file_perms;
72  set_prop(shell, persist_debug_prop)
73')
74
75# Read device's serial number from system properties
76get_prop(shell, serialno_prop)
77
78# Read state of logging-related properties
79get_prop(shell, device_logging_prop)
80
81# allow shell access to services
82allow shell servicemanager:service_manager list;
83# don't allow shell to access GateKeeper service
84# TODO: why is this so broad? Tightening candidate? It needs at list:
85# - dumpstate_service (so it can receive dumpstate progress updates)
86allow shell { service_manager_type -gatekeeper_service -incident_service -installd_service -netd_service -virtual_touchpad_service -vr_hwc_service }:service_manager find;
87allow shell dumpstate:binder call;
88
89# allow shell to get information from hwservicemanager
90# for instance, listing hardware services with lshal
91hwbinder_use(shell)
92allow shell hwservicemanager:hwservice_manager list;
93
94# allow shell to look through /proc/ for ps, top, netstat
95r_dir_file(shell, proc)
96r_dir_file(shell, proc_net)
97allow shell proc_interrupts:file r_file_perms;
98allow shell proc_meminfo:file r_file_perms;
99allow shell proc_stat:file r_file_perms;
100allow shell proc_timer:file r_file_perms;
101allow shell proc_zoneinfo:file r_file_perms;
102r_dir_file(shell, cgroup)
103allow shell domain:dir { search open read getattr };
104allow shell domain:{ file lnk_file } { open read getattr };
105
106# statvfs() of /proc and other labeled filesystems
107# (yaffs2, jffs2, ext2, ext3, ext4, xfs, btrfs, f2fs, squashfs)
108allow shell { proc labeledfs }:filesystem getattr;
109
110# stat() of /dev
111allow shell device:dir getattr;
112
113# allow shell to read /proc/pid/attr/current for ps -Z
114allow shell domain:process getattr;
115
116# Allow pulling the SELinux policy for CTS purposes
117allow shell selinuxfs:dir r_dir_perms;
118allow shell selinuxfs:file r_file_perms;
119
120# enable shell domain to read/write files/dirs for bootchart data
121# User will creates the start and stop file via adb shell
122# and read other files created by init process under /data/bootchart
123allow shell bootchart_data_file:dir rw_dir_perms;
124allow shell bootchart_data_file:file create_file_perms;
125
126# Make sure strace works for the non-privileged shell user
127allow shell self:process ptrace;
128
129# allow shell to get battery info
130allow shell sysfs_batteryinfo:file r_file_perms;
131allow shell sysfs:dir r_dir_perms;
132
133# Allow access to ion memory allocation device.
134allow shell ion_device:chr_file rw_file_perms;
135
136#
137# filesystem test for insecure chr_file's is done
138# via a host side test
139#
140allow shell dev_type:dir r_dir_perms;
141allow shell dev_type:chr_file getattr;
142
143# /dev/fd is a symlink
144allow shell proc:lnk_file getattr;
145
146#
147# filesystem test for insucre blk_file's is done
148# via hostside test
149#
150allow shell dev_type:blk_file getattr;
151
152# read selinux policy files
153allow shell file_contexts_file:file r_file_perms;
154allow shell property_contexts_file:file r_file_perms;
155allow shell seapp_contexts_file:file r_file_perms;
156allow shell service_contexts_file:file r_file_perms;
157allow shell sepolicy_file:file r_file_perms;
158
159###
160### Neverallow rules
161###
162
163# Do not allow shell to hard link to any files.
164# In particular, if shell hard links to app data
165# files, installd will not be able to guarantee the deletion
166# of the linked to file. Hard links also contribute to security
167# bugs, so we want to ensure the shell user never has this
168# capability.
169neverallow shell file_type:file link;
170
171# Do not allow privileged socket ioctl commands
172neverallowxperm shell domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
173
174# limit shell access to sensitive char drivers to
175# only getattr required for host side test.
176neverallow shell {
177  fuse_device
178  hw_random_device
179  kmem_device
180  port_device
181}:chr_file ~getattr;
182
183# Limit shell to only getattr on blk devices for host side tests.
184neverallow shell dev_type:blk_file ~getattr;
185