Skip to content

Commit c55ae13

Browse files
committed
adb_shell: add SELinux policy for adbd and interactive adb shell session
Add SELinux policy support for adbd and interactive adb shell sessions. The new module defines the adbd_t and adb_shell_t domains and the domain transition from adbd_t to adb_shell_t when launching an interactive shell. The policy grants the permissions required for PTY allocation, shell execution, temporary file handling, runtime configuration access, filesystem traversal, and interaction with common system resources needed during adb shell startup. Additional debugging and diagnostic capabilities are provided through the adb_shell_extended_access tunable, which is disabled by default. When enabled, it grants access to selected kernel state information, sysctls, SELinux policy information, kernel logs, and other resources useful for troubleshooting. This allows interactive adb shell functionality while keeping additional debugging permissions optional. Signed-off-by: Jaihind Yadav <jaihindy@qti.qualcomm.com>
1 parent bf750a6 commit c55ae13

3 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/usr/bin/adbd -- gen_context(system_u:object_r:adbd_exec_t,s0)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## <summary>Policy for adb shell</summary>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
policy_module(adb_shell, 1.0)
2+
3+
########################################
4+
#
5+
# Declarations
6+
#
7+
8+
## <desc>
9+
## <p>
10+
## Allow extended adb shell functionality for debugging and interactive shell access.
11+
## </p>
12+
## </desc>
13+
gen_tunable(adb_shell_extended_access, false)
14+
15+
type adb_shell_t;
16+
type adbd_exec_t;
17+
type adbd_t;
18+
domain_type(adbd_t)
19+
domain_type(adb_shell_t)
20+
21+
# ========================================
22+
# Transition: adbd → shell → adb_shell
23+
# ========================================
24+
25+
init_daemon_domain(adbd_t, adbd_exec_t)
26+
corecmd_shell_domtrans(adbd_t,adb_shell_t)
27+
#domain_auto_transition_pattern(adbd_t, shell_exec_t, adb_shell_t)
28+
role system_r types adb_shell_t;
29+
30+
# ========================================
31+
# # adbd_t Local Policy
32+
#
33+
34+
corecmd_search_bin(adbd_t)
35+
term_use_generic_ptys(adbd_t)
36+
term_use_ptmx(adbd_t)
37+
files_read_etc_files(adbd_t)
38+
allow adbd_t self:capability sys_resource;
39+
dev_rw_usbfs(adbd_t)
40+
41+
# ========================================
42+
# adb_shell_t Local Policy
43+
#
44+
corecmd_shell_entry_type(adb_shell_t)
45+
corecmd_exec_bin(adb_shell_t)
46+
allow adb_shell_t self:fifo_file read;
47+
allow adb_shell_t self:process setpgid;
48+
allow adb_shell_t adbd_t:fd use;
49+
50+
term_use_ptmx(adb_shell_t)
51+
term_use_generic_ptys(adb_shell_t)
52+
53+
files_read_etc_files(adb_shell_t)
54+
55+
files_search_var(adb_shell_t)
56+
logging_search_logs(adb_shell_t)
57+
logging_list_logs(adb_shell_t)
58+
59+
fs_getattr_xattr_fs(adb_shell_t)
60+
61+
files_search_var(adb_shell_t)
62+
files_search_tmp(adb_shell_t)
63+
files_search_spool(adb_shell_t)
64+
65+
dev_search_sysfs(adb_shell_t)
66+
67+
kernel_search_proc(adb_shell_t)
68+
69+
userdom_search_user_home_dirs(adb_shell_t)
70+
71+
files_read_usr_symlinks(adb_shell_t)
72+
files_getattr_var_lib_dirs(adb_shell_t)
73+
seutil_read_config(adb_shell_t)
74+
files_read_mnt_files(adb_shell_t)
75+
files_search_default(adb_shell_t)
76+
fs_list_auto_mountpoints(adb_shell_t)
77+
files_read_var_symlinks(adb_shell_t)
78+
files_read_mnt_symlinks(adb_shell_t)
79+
80+
dbus_system_bus_client(adb_shell_t)
81+
82+
optional_policy(`
83+
dnsmasq_domtrans(adb_shell_t)
84+
')
85+
86+
87+
tunable_policy(`adb_shell_extended_access',`
88+
89+
kernel_read_vm_sysctls(adb_shell_t)
90+
kernel_read_fs_sysctls(adb_shell_t)
91+
92+
dev_read_kmsg(adb_shell_t)
93+
94+
selinux_read_policy(adb_shell_t)
95+
96+
mount_exec(adb_shell_t)
97+
98+
dmesg_exec(adb_shell_t)
99+
kernel_read_ring_buffer(adb_shell_t)
100+
101+
files_read_etc_runtime_files(adb_shell_t)
102+
files_read_usr_symlinks(adb_shell_t)
103+
104+
files_manage_var_dirs(adb_shell_t)
105+
files_manage_var_files(adb_shell_t)
106+
107+
selinux_get_fs_mount(adb_shell_t)
108+
109+
userdom_use_user_terminals(adb_shell_t)
110+
111+
')

0 commit comments

Comments
 (0)