blob: a466ef12c9cceaafa6bb6b12472c08a8ffff4a54 [file] [log] [blame]
Alex Klyubinf5446eb2017-03-23 14:27:32 -07001typeattribute netd coredomain;
Steven Moreland65981752022-02-10 00:32:44 +00002typeattribute netd bpfdomain;
Alex Klyubinf5446eb2017-03-23 14:27:32 -07003
dcashmancc39f632016-07-22 13:13:11 -07004init_daemon_domain(netd)
5
6# Allow netd to spawn dnsmasq in it's own domain
7domain_auto_trans(netd, dnsmasq_exec, dnsmasq)
8
Maciej Żenczykowski37ca69e2023-11-18 03:36:05 +00009allow netd { fs_bpf fs_bpf_netd_readonly fs_bpf_netd_shared fs_bpf_vendor }:dir search;
10allow netd { fs_bpf fs_bpf_netd_readonly fs_bpf_netd_shared fs_bpf_vendor }:file { getattr read };
11allow netd { fs_bpf fs_bpf_netd_shared }:file write;
Maciej Żenczykowskib13921c2022-05-21 05:03:29 -070012
Chenbo Feng7b571042018-12-04 17:57:27 -080013# give netd permission to setup iptables rule with xt_bpf, attach program to cgroup, and read/write
14# the map created by bpfloader
15allow netd bpfloader:bpf { prog_run map_read map_write };
Joel Fernandesb76a6392019-01-11 08:32:45 -050016
Chenbo Feng8a5539b2019-02-27 17:44:26 -080017# in order to invoke side effect of close() on such a socket calling synchronize_rcu()
18# TODO: Remove this permission when 4.9 kernel is deprecated.
Ken Chen1aed0062022-01-28 15:04:09 +080019# TODO: Remove this after we remove all bpf interactions from netd.
Chenbo Feng8a5539b2019-02-27 17:44:26 -080020allow netd self:key_socket create;
21
Inseob Kim55e5c9b2020-03-04 17:20:35 +090022set_prop(netd, ctl_mdnsd_prop)
23set_prop(netd, netd_stable_secret_prop)
24
steven_fannd3e8f6f2021-01-26 13:34:00 +080025get_prop(netd, adbd_config_prop)
Inseob Kim55e5c9b2020-03-04 17:20:35 +090026get_prop(netd, hwservicemanager_prop)
27get_prop(netd, device_config_netd_native_prop)
lifr980c08c2018-11-21 22:53:48 +080028
29# Allow netd to write to statsd.
30unix_socket_send(netd, statsdw, statsd)
Remi NGUYEN VAN780fbad2019-01-28 13:08:42 +090031
32# Allow netd to send callbacks to network_stack
33binder_call(netd, network_stack)
34
Chalard Jeana4c9f7b2019-04-05 17:33:56 +090035# Allow netd to send dump info to dumpstate
36allow netd dumpstate:fd use;
37allow netd dumpstate:fifo_file { getattr write };
Inseob Kim55e5c9b2020-03-04 17:20:35 +090038
Inseob Kim75806ef2024-03-27 17:18:41 +090039net_domain(netd)
40# Connect to mdnsd via mdnsd socket.
41unix_socket_connect(netd, mdnsd, mdnsd)
42# in addition to ioctls allowlisted for all domains, grant netd priv_sock_ioctls.
43allowxperm netd self:udp_socket ioctl priv_sock_ioctls;
44
45r_dir_file(netd, cgroup)
46
47allow netd system_server:fd use;
48
49allow netd self:global_capability_class_set { net_admin net_raw kill };
50# Note: fsetid is deliberately not included above. fsetid checks are
51# triggered by chmod on a directory or file owned by a group other
52# than one of the groups assigned to the current process to see if
53# the setgid bit should be cleared, regardless of whether the setgid
54# bit was even set. We do not appear to truly need this capability
55# for netd to operate.
56dontaudit netd self:global_capability_class_set fsetid;
57
58# Allow netd to open /dev/tun, set it up and pass it to clatd
59allow netd tun_device:chr_file rw_file_perms;
60allowxperm netd tun_device:chr_file ioctl { TUNGETIFF TUNSETIFF };
61allow netd self:tun_socket create;
62
63allow netd self:netlink_kobject_uevent_socket create_socket_perms_no_ioctl;
64allow netd self:netlink_route_socket nlmsg_write;
65allow netd self:netlink_nflog_socket create_socket_perms_no_ioctl;
66allow netd self:netlink_socket create_socket_perms_no_ioctl;
67allow netd self:netlink_tcpdiag_socket { create_socket_perms_no_ioctl nlmsg_read nlmsg_write };
68allow netd self:netlink_generic_socket create_socket_perms_no_ioctl;
69allow netd self:netlink_netfilter_socket create_socket_perms_no_ioctl;
70allow netd shell_exec:file rx_file_perms;
71allow netd system_file:file x_file_perms;
72not_full_treble(`allow netd vendor_file:file x_file_perms;')
73allow netd devpts:chr_file rw_file_perms;
74
75# Acquire advisory lock on /system/etc/xtables.lock. If this file doesn't
76# exist, suppress the denial.
77allow netd system_file:file lock;
78dontaudit netd system_file:dir write;
79
80# Allow netd to write to qtaguid ctrl file.
81# TODO: Add proper rules to prevent other process to access qtaguid_proc file
82# after migration complete
83allow netd proc_qtaguid_ctrl:file rw_file_perms;
84# Allow netd to read /dev/qtaguid. This is the same privilege level that normal apps have.
85allow netd qtaguid_device:chr_file r_file_perms;
86
87r_dir_file(netd, proc_net_type)
88# For /proc/sys/net/ipv[46]/route/flush.
89allow netd proc_net_type:file rw_file_perms;
90
91# Enables PppController and interface enumeration (among others)
92allow netd sysfs:dir r_dir_perms;
93r_dir_file(netd, sysfs_net)
94
95# Allows setting interface MTU
96allow netd sysfs_net:file w_file_perms;
97
98# TODO: added to match above sysfs rule. Remove me?
99allow netd sysfs_usb:file write;
100
101r_dir_file(netd, cgroup_v2)
102
103# TODO: netd previously thought it needed these permissions to do WiFi related
104# work. However, after all the WiFi stuff is gone, we still need them.
105# Why?
106allow netd self:global_capability_class_set { dac_override dac_read_search chown };
107
108# Needed to update /data/misc/net/rt_tables
109allow netd net_data_file:file create_file_perms;
110allow netd net_data_file:dir rw_dir_perms;
111allow netd self:global_capability_class_set fowner;
112
113# Needed to lock the iptables lock.
114allow netd system_file:file lock;
115
116# Allow netd to spawn dnsmasq in it's own domain
117allow netd dnsmasq:process { sigkill signal };
118
119# Allow netd to publish a binder service and make binder calls.
120binder_use(netd)
121add_service(netd, netd_service)
122add_service(netd, dnsresolver_service)
123add_service(netd, mdns_service)
124allow netd dumpstate:fifo_file { getattr write };
125
126# Allow netd to call into the system server so it can check permissions.
127allow netd system_server:binder call;
128allow netd permission_service:service_manager find;
129
130# Allow netd to talk to the framework service which collects netd events.
131allow netd netd_listener_service:service_manager find;
132
133# Allow netd to operate on sockets that are passed to it.
134allow netd netdomain:{
135 icmp_socket
136 tcp_socket
137 udp_socket
138 rawip_socket
139 tun_socket
140} { read write getattr setattr getopt setopt };
141allow netd netdomain:fd use;
142
143# give netd permission to read and write netlink xfrm
144allow netd self:netlink_xfrm_socket { create_socket_perms_no_ioctl nlmsg_write nlmsg_read };
145
146# Allow netd to register as hal server.
147add_hwservice(netd, system_net_netd_hwservice)
148hwbinder_use(netd)
149
150# AIDL hal server
151binder_call(system_net_netd_service, servicemanager)
152add_service(netd, system_net_netd_service)
153
154###
155### Neverallow rules
156###
157### netd should NEVER do any of this
158
159# Block device access.
160neverallow netd dev_type:blk_file { read write };
161
162# ptrace any other app
163neverallow netd { domain }:process ptrace;
164
165# Write to /system.
166neverallow netd system_file_type:dir_file_class_set write;
167
168# Write to files in /data/data or system files on /data
169neverallow netd { app_data_file_type system_data_file }:dir_file_class_set write;
170
171# only system_server, dumpstate and network stack app may find netd service
172neverallow {
173 domain
174 -system_server
175 -dumpstate
176 -network_stack
177 -netd
178 -netutils_wrapper
179} netd_service:service_manager find;
180
181# only system_server, dumpstate and network stack app may find dnsresolver service
182neverallow {
183 domain
184 -system_server
185 -dumpstate
186 -network_stack
187 -netd
188 -netutils_wrapper
189} dnsresolver_service:service_manager find;
190
191# only system_server, dumpstate and network stack app may find mdns service
192neverallow {
193 domain
194 -system_server
195 -dumpstate
196 -network_stack
197 -netd
198 -netutils_wrapper
199} mdns_service:service_manager find;
200
201# apps may not interact with netd over binder.
202neverallow { appdomain -network_stack } netd:binder call;
203neverallow netd { appdomain -network_stack userdebug_or_eng(`-su') }:binder call;
204
205# If an already existing file is opened with O_CREATE, the kernel might generate
206# a false report of a create denial. Silence these denials and make sure that
207# inappropriate permissions are not granted.
208neverallow netd proc_net:dir no_w_dir_perms;
209dontaudit netd proc_net:dir write;
210
211neverallow netd sysfs_net:dir no_w_dir_perms;
212dontaudit netd sysfs_net:dir write;
213
214# Netd should not have SYS_ADMIN privs.
215neverallow netd self:capability sys_admin;
216dontaudit netd self:capability sys_admin;
217
218# Netd should not have SYS_MODULE privs, nor should it be requesting module loads
219# (things it requires should be built directly into the kernel)
220dontaudit netd self:capability sys_module;
221
222dontaudit netd appdomain:unix_stream_socket { read write };
223
Inseob Kim55e5c9b2020-03-04 17:20:35 +0900224# persist.netd.stable_secret contains RFC 7217 secret key which should never be
225# leaked to other processes. Make sure it never leaks.
226neverallow { domain -netd -init -dumpstate } netd_stable_secret_prop:file r_file_perms;
227
228# We want to ensure that no other process ever tries tampering with persist.netd.stable_secret,
229# the RFC 7217 secret key managed by netd. Doing so could compromise user privacy.
230neverallow { domain -netd -init } netd_stable_secret_prop:property_service set;