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