xref: /aosp_15_r20/system/sepolicy/prebuilts/api/34.0/public/netd.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# network manager
2*e4a36f41SAndroid Build Coastguard Workertype netd, domain, mlstrustedsubject;
3*e4a36f41SAndroid Build Coastguard Workertype netd_exec, system_file_type, exec_type, file_type;
4*e4a36f41SAndroid Build Coastguard Worker
5*e4a36f41SAndroid Build Coastguard Workernet_domain(netd)
6*e4a36f41SAndroid Build Coastguard Worker# Connect to mdnsd via mdnsd socket.
7*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(netd, mdnsd, mdnsd)
8*e4a36f41SAndroid Build Coastguard Worker# in addition to ioctls allowlisted for all domains, grant netd priv_sock_ioctls.
9*e4a36f41SAndroid Build Coastguard Workerallowxperm netd self:udp_socket ioctl priv_sock_ioctls;
10*e4a36f41SAndroid Build Coastguard Worker
11*e4a36f41SAndroid Build Coastguard Workerr_dir_file(netd, cgroup)
12*e4a36f41SAndroid Build Coastguard Worker
13*e4a36f41SAndroid Build Coastguard Workerallow netd system_server:fd use;
14*e4a36f41SAndroid Build Coastguard Worker
15*e4a36f41SAndroid Build Coastguard Workerallow netd self:global_capability_class_set { net_admin net_raw kill };
16*e4a36f41SAndroid Build Coastguard Worker# Note: fsetid is deliberately not included above. fsetid checks are
17*e4a36f41SAndroid Build Coastguard Worker# triggered by chmod on a directory or file owned by a group other
18*e4a36f41SAndroid Build Coastguard Worker# than one of the groups assigned to the current process to see if
19*e4a36f41SAndroid Build Coastguard Worker# the setgid bit should be cleared, regardless of whether the setgid
20*e4a36f41SAndroid Build Coastguard Worker# bit was even set.  We do not appear to truly need this capability
21*e4a36f41SAndroid Build Coastguard Worker# for netd to operate.
22*e4a36f41SAndroid Build Coastguard Workerdontaudit netd self:global_capability_class_set fsetid;
23*e4a36f41SAndroid Build Coastguard Worker
24*e4a36f41SAndroid Build Coastguard Worker# Allow netd to open /dev/tun, set it up and pass it to clatd
25*e4a36f41SAndroid Build Coastguard Workerallow netd tun_device:chr_file rw_file_perms;
26*e4a36f41SAndroid Build Coastguard Workerallowxperm netd tun_device:chr_file ioctl { TUNGETIFF TUNSETIFF };
27*e4a36f41SAndroid Build Coastguard Workerallow netd self:tun_socket create;
28*e4a36f41SAndroid Build Coastguard Worker
29*e4a36f41SAndroid Build Coastguard Workerallow netd self:netlink_kobject_uevent_socket create_socket_perms_no_ioctl;
30*e4a36f41SAndroid Build Coastguard Workerallow netd self:netlink_route_socket nlmsg_write;
31*e4a36f41SAndroid Build Coastguard Workerallow netd self:netlink_nflog_socket create_socket_perms_no_ioctl;
32*e4a36f41SAndroid Build Coastguard Workerallow netd self:netlink_socket create_socket_perms_no_ioctl;
33*e4a36f41SAndroid Build Coastguard Workerallow netd self:netlink_tcpdiag_socket { create_socket_perms_no_ioctl nlmsg_read nlmsg_write };
34*e4a36f41SAndroid Build Coastguard Workerallow netd self:netlink_generic_socket create_socket_perms_no_ioctl;
35*e4a36f41SAndroid Build Coastguard Workerallow netd self:netlink_netfilter_socket create_socket_perms_no_ioctl;
36*e4a36f41SAndroid Build Coastguard Workerallow netd shell_exec:file rx_file_perms;
37*e4a36f41SAndroid Build Coastguard Workerallow netd system_file:file x_file_perms;
38*e4a36f41SAndroid Build Coastguard Workernot_full_treble(`allow netd vendor_file:file x_file_perms;')
39*e4a36f41SAndroid Build Coastguard Workerallow netd devpts:chr_file rw_file_perms;
40*e4a36f41SAndroid Build Coastguard Worker
41*e4a36f41SAndroid Build Coastguard Worker# Acquire advisory lock on /system/etc/xtables.lock. If this file doesn't
42*e4a36f41SAndroid Build Coastguard Worker# exist, suppress the denial.
43*e4a36f41SAndroid Build Coastguard Workerallow netd system_file:file lock;
44*e4a36f41SAndroid Build Coastguard Workerdontaudit netd system_file:dir write;
45*e4a36f41SAndroid Build Coastguard Worker
46*e4a36f41SAndroid Build Coastguard Worker# Allow netd to write to qtaguid ctrl file.
47*e4a36f41SAndroid Build Coastguard Worker# TODO: Add proper rules to prevent other process to access qtaguid_proc file
48*e4a36f41SAndroid Build Coastguard Worker# after migration complete
49*e4a36f41SAndroid Build Coastguard Workerallow netd proc_qtaguid_ctrl:file rw_file_perms;
50*e4a36f41SAndroid Build Coastguard Worker# Allow netd to read /dev/qtaguid. This is the same privilege level that normal apps have.
51*e4a36f41SAndroid Build Coastguard Workerallow netd qtaguid_device:chr_file r_file_perms;
52*e4a36f41SAndroid Build Coastguard Worker
53*e4a36f41SAndroid Build Coastguard Workerr_dir_file(netd, proc_net_type)
54*e4a36f41SAndroid Build Coastguard Worker# For /proc/sys/net/ipv[46]/route/flush.
55*e4a36f41SAndroid Build Coastguard Workerallow netd proc_net_type:file rw_file_perms;
56*e4a36f41SAndroid Build Coastguard Worker
57*e4a36f41SAndroid Build Coastguard Worker# Enables PppController and interface enumeration (among others)
58*e4a36f41SAndroid Build Coastguard Workerallow netd sysfs:dir r_dir_perms;
59*e4a36f41SAndroid Build Coastguard Workerr_dir_file(netd, sysfs_net)
60*e4a36f41SAndroid Build Coastguard Worker
61*e4a36f41SAndroid Build Coastguard Worker# Allows setting interface MTU
62*e4a36f41SAndroid Build Coastguard Workerallow netd sysfs_net:file w_file_perms;
63*e4a36f41SAndroid Build Coastguard Worker
64*e4a36f41SAndroid Build Coastguard Worker# TODO: added to match above sysfs rule. Remove me?
65*e4a36f41SAndroid Build Coastguard Workerallow netd sysfs_usb:file write;
66*e4a36f41SAndroid Build Coastguard Worker
67*e4a36f41SAndroid Build Coastguard Workerr_dir_file(netd, cgroup_v2)
68*e4a36f41SAndroid Build Coastguard Worker
69*e4a36f41SAndroid Build Coastguard Worker# TODO: netd previously thought it needed these permissions to do WiFi related
70*e4a36f41SAndroid Build Coastguard Worker#       work.  However, after all the WiFi stuff is gone, we still need them.
71*e4a36f41SAndroid Build Coastguard Worker#       Why?
72*e4a36f41SAndroid Build Coastguard Workerallow netd self:global_capability_class_set { dac_override dac_read_search chown };
73*e4a36f41SAndroid Build Coastguard Worker
74*e4a36f41SAndroid Build Coastguard Worker# Needed to update /data/misc/net/rt_tables
75*e4a36f41SAndroid Build Coastguard Workerallow netd net_data_file:file create_file_perms;
76*e4a36f41SAndroid Build Coastguard Workerallow netd net_data_file:dir rw_dir_perms;
77*e4a36f41SAndroid Build Coastguard Workerallow netd self:global_capability_class_set fowner;
78*e4a36f41SAndroid Build Coastguard Worker
79*e4a36f41SAndroid Build Coastguard Worker# Needed to lock the iptables lock.
80*e4a36f41SAndroid Build Coastguard Workerallow netd system_file:file lock;
81*e4a36f41SAndroid Build Coastguard Worker
82*e4a36f41SAndroid Build Coastguard Worker# Allow netd to spawn dnsmasq in it's own domain
83*e4a36f41SAndroid Build Coastguard Workerallow netd dnsmasq:process signal;
84*e4a36f41SAndroid Build Coastguard Worker
85*e4a36f41SAndroid Build Coastguard Worker# Allow netd to publish a binder service and make binder calls.
86*e4a36f41SAndroid Build Coastguard Workerbinder_use(netd)
87*e4a36f41SAndroid Build Coastguard Workeradd_service(netd, netd_service)
88*e4a36f41SAndroid Build Coastguard Workeradd_service(netd, dnsresolver_service)
89*e4a36f41SAndroid Build Coastguard Workeradd_service(netd, mdns_service)
90*e4a36f41SAndroid Build Coastguard Workerallow netd dumpstate:fifo_file  { getattr write };
91*e4a36f41SAndroid Build Coastguard Worker
92*e4a36f41SAndroid Build Coastguard Worker# Allow netd to call into the system server so it can check permissions.
93*e4a36f41SAndroid Build Coastguard Workerallow netd system_server:binder call;
94*e4a36f41SAndroid Build Coastguard Workerallow netd permission_service:service_manager find;
95*e4a36f41SAndroid Build Coastguard Worker
96*e4a36f41SAndroid Build Coastguard Worker# Allow netd to talk to the framework service which collects netd events.
97*e4a36f41SAndroid Build Coastguard Workerallow netd netd_listener_service:service_manager find;
98*e4a36f41SAndroid Build Coastguard Worker
99*e4a36f41SAndroid Build Coastguard Worker# Allow netd to operate on sockets that are passed to it.
100*e4a36f41SAndroid Build Coastguard Workerallow netd netdomain:{
101*e4a36f41SAndroid Build Coastguard Worker  icmp_socket
102*e4a36f41SAndroid Build Coastguard Worker  tcp_socket
103*e4a36f41SAndroid Build Coastguard Worker  udp_socket
104*e4a36f41SAndroid Build Coastguard Worker  rawip_socket
105*e4a36f41SAndroid Build Coastguard Worker  tun_socket
106*e4a36f41SAndroid Build Coastguard Worker} { read write getattr setattr getopt setopt };
107*e4a36f41SAndroid Build Coastguard Workerallow netd netdomain:fd use;
108*e4a36f41SAndroid Build Coastguard Worker
109*e4a36f41SAndroid Build Coastguard Worker# give netd permission to read and write netlink xfrm
110*e4a36f41SAndroid Build Coastguard Workerallow netd self:netlink_xfrm_socket { create_socket_perms_no_ioctl nlmsg_write nlmsg_read };
111*e4a36f41SAndroid Build Coastguard Worker
112*e4a36f41SAndroid Build Coastguard Worker# Allow netd to register as hal server.
113*e4a36f41SAndroid Build Coastguard Workeradd_hwservice(netd, system_net_netd_hwservice)
114*e4a36f41SAndroid Build Coastguard Workerhwbinder_use(netd)
115*e4a36f41SAndroid Build Coastguard Worker
116*e4a36f41SAndroid Build Coastguard Worker# AIDL hal server
117*e4a36f41SAndroid Build Coastguard Workerbinder_call(system_net_netd_service, servicemanager)
118*e4a36f41SAndroid Build Coastguard Workeradd_service(netd, system_net_netd_service)
119*e4a36f41SAndroid Build Coastguard Worker
120*e4a36f41SAndroid Build Coastguard Worker###
121*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules
122*e4a36f41SAndroid Build Coastguard Worker###
123*e4a36f41SAndroid Build Coastguard Worker### netd should NEVER do any of this
124*e4a36f41SAndroid Build Coastguard Worker
125*e4a36f41SAndroid Build Coastguard Worker# Block device access.
126*e4a36f41SAndroid Build Coastguard Workerneverallow netd dev_type:blk_file { read write };
127*e4a36f41SAndroid Build Coastguard Worker
128*e4a36f41SAndroid Build Coastguard Worker# ptrace any other app
129*e4a36f41SAndroid Build Coastguard Workerneverallow netd { domain }:process ptrace;
130*e4a36f41SAndroid Build Coastguard Worker
131*e4a36f41SAndroid Build Coastguard Worker# Write to /system.
132*e4a36f41SAndroid Build Coastguard Workerneverallow netd system_file:dir_file_class_set write;
133*e4a36f41SAndroid Build Coastguard Worker
134*e4a36f41SAndroid Build Coastguard Worker# Write to files in /data/data or system files on /data
135*e4a36f41SAndroid Build Coastguard Workerneverallow netd { app_data_file_type system_data_file }:dir_file_class_set write;
136*e4a36f41SAndroid Build Coastguard Worker
137*e4a36f41SAndroid Build Coastguard Worker# only system_server, dumpstate and network stack app may find netd service
138*e4a36f41SAndroid Build Coastguard Workerneverallow {
139*e4a36f41SAndroid Build Coastguard Worker    domain
140*e4a36f41SAndroid Build Coastguard Worker    -system_server
141*e4a36f41SAndroid Build Coastguard Worker    -dumpstate
142*e4a36f41SAndroid Build Coastguard Worker    -network_stack
143*e4a36f41SAndroid Build Coastguard Worker    -netd
144*e4a36f41SAndroid Build Coastguard Worker    -netutils_wrapper
145*e4a36f41SAndroid Build Coastguard Worker} netd_service:service_manager find;
146*e4a36f41SAndroid Build Coastguard Worker
147*e4a36f41SAndroid Build Coastguard Worker# only system_server, dumpstate and network stack app may find dnsresolver service
148*e4a36f41SAndroid Build Coastguard Workerneverallow {
149*e4a36f41SAndroid Build Coastguard Worker    domain
150*e4a36f41SAndroid Build Coastguard Worker    -system_server
151*e4a36f41SAndroid Build Coastguard Worker    -dumpstate
152*e4a36f41SAndroid Build Coastguard Worker    -network_stack
153*e4a36f41SAndroid Build Coastguard Worker    -netd
154*e4a36f41SAndroid Build Coastguard Worker    -netutils_wrapper
155*e4a36f41SAndroid Build Coastguard Worker} dnsresolver_service:service_manager find;
156*e4a36f41SAndroid Build Coastguard Worker
157*e4a36f41SAndroid Build Coastguard Worker# only system_server, dumpstate and network stack app may find mdns service
158*e4a36f41SAndroid Build Coastguard Workerneverallow {
159*e4a36f41SAndroid Build Coastguard Worker    domain
160*e4a36f41SAndroid Build Coastguard Worker    -system_server
161*e4a36f41SAndroid Build Coastguard Worker    -dumpstate
162*e4a36f41SAndroid Build Coastguard Worker    -network_stack
163*e4a36f41SAndroid Build Coastguard Worker    -netd
164*e4a36f41SAndroid Build Coastguard Worker    -netutils_wrapper
165*e4a36f41SAndroid Build Coastguard Worker} mdns_service:service_manager find;
166*e4a36f41SAndroid Build Coastguard Worker
167*e4a36f41SAndroid Build Coastguard Worker# apps may not interact with netd over binder.
168*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -network_stack } netd:binder call;
169*e4a36f41SAndroid Build Coastguard Workerneverallow netd { appdomain -network_stack userdebug_or_eng(`-su') }:binder call;
170*e4a36f41SAndroid Build Coastguard Worker
171*e4a36f41SAndroid Build Coastguard Worker# If an already existing file is opened with O_CREATE, the kernel might generate
172*e4a36f41SAndroid Build Coastguard Worker# a false report of a create denial. Silence these denials and make sure that
173*e4a36f41SAndroid Build Coastguard Worker# inappropriate permissions are not granted.
174*e4a36f41SAndroid Build Coastguard Workerneverallow netd proc_net:dir no_w_dir_perms;
175*e4a36f41SAndroid Build Coastguard Workerdontaudit netd proc_net:dir write;
176*e4a36f41SAndroid Build Coastguard Worker
177*e4a36f41SAndroid Build Coastguard Workerneverallow netd sysfs_net:dir no_w_dir_perms;
178*e4a36f41SAndroid Build Coastguard Workerdontaudit netd sysfs_net:dir write;
179*e4a36f41SAndroid Build Coastguard Worker
180*e4a36f41SAndroid Build Coastguard Worker# Netd should not have SYS_ADMIN privs.
181*e4a36f41SAndroid Build Coastguard Workerneverallow netd self:capability sys_admin;
182*e4a36f41SAndroid Build Coastguard Workerdontaudit netd self:capability sys_admin;
183*e4a36f41SAndroid Build Coastguard Worker
184*e4a36f41SAndroid Build Coastguard Worker# Netd should not have SYS_MODULE privs, nor should it be requesting module loads
185*e4a36f41SAndroid Build Coastguard Worker# (things it requires should be built directly into the kernel)
186*e4a36f41SAndroid Build Coastguard Workerdontaudit netd self:capability sys_module;
187*e4a36f41SAndroid Build Coastguard Worker
188*e4a36f41SAndroid Build Coastguard Workerdontaudit netd kernel:system module_request;
189*e4a36f41SAndroid Build Coastguard Worker
190*e4a36f41SAndroid Build Coastguard Workerdontaudit netd appdomain:unix_stream_socket { read write };
191