1# network manager
2type netd, domain, mlstrustedsubject;
3type netd_exec, exec_type, file_type;
4
5net_domain(netd)
6# in addition to ioctls whitelisted for all domains, grant netd priv_sock_ioctls.
7allowxperm netd self:udp_socket ioctl priv_sock_ioctls;
8
9r_dir_file(netd, cgroup)
10allow netd system_server:fd use;
11
12allow netd self:capability { net_admin net_raw kill };
13# Note: fsetid is deliberately not included above. fsetid checks are
14# triggered by chmod on a directory or file owned by a group other
15# than one of the groups assigned to the current process to see if
16# the setgid bit should be cleared, regardless of whether the setgid
17# bit was even set.  We do not appear to truly need this capability
18# for netd to operate.
19dontaudit netd self:capability fsetid;
20
21allow netd self:netlink_kobject_uevent_socket create_socket_perms_no_ioctl;
22allow netd self:netlink_route_socket nlmsg_write;
23allow netd self:netlink_nflog_socket create_socket_perms_no_ioctl;
24allow netd self:netlink_socket create_socket_perms_no_ioctl;
25allow netd self:netlink_tcpdiag_socket { create_socket_perms_no_ioctl nlmsg_read nlmsg_write };
26allow netd self:netlink_generic_socket create_socket_perms_no_ioctl;
27allow netd self:netlink_netfilter_socket create_socket_perms_no_ioctl;
28allow netd shell_exec:file rx_file_perms;
29allow netd system_file:file x_file_perms;
30not_full_treble(`allow netd vendor_file:file x_file_perms;')
31allow netd devpts:chr_file rw_file_perms;
32
33# Acquire advisory lock on /system/etc/xtables.lock
34allow netd system_file:file lock;
35
36r_dir_file(netd, proc_net)
37# For /proc/sys/net/ipv[46]/route/flush.
38allow netd proc_net:file rw_file_perms;
39
40# Enables PppController and interface enumeration (among others)
41r_dir_file(netd, sysfs_type)
42# Allows setting interface MTU
43allow netd sysfs:file write;
44
45# TODO: added to match above sysfs rule. Remove me?
46allow netd sysfs_usb:file write;
47
48# TODO: netd previously thought it needed these permissions to do WiFi related
49#       work.  However, after all the WiFi stuff is gone, we still need them.
50#       Why?
51allow netd self:capability { dac_override chown };
52
53# Needed to update /data/misc/net/rt_tables
54allow netd net_data_file:file create_file_perms;
55allow netd net_data_file:dir rw_dir_perms;
56allow netd self:capability fowner;
57
58# Allow netd to spawn dnsmasq in it's own domain
59allow netd dnsmasq:process signal;
60
61# Allow netd to start clatd in its own domain
62allow netd clatd:process signal;
63
64set_prop(netd, ctl_mdnsd_prop)
65
66# Allow netd to publish a binder service and make binder calls.
67binder_use(netd)
68add_service(netd, netd_service)
69allow netd dumpstate:fifo_file  { getattr write };
70
71# Allow netd to call into the system server so it can check permissions.
72allow netd system_server:binder call;
73allow netd permission_service:service_manager find;
74
75# Allow netd to talk to the framework service which collects netd events.
76allow netd netd_listener_service:service_manager find;
77
78# Allow netd to operate on sockets that are passed to it.
79allow netd netdomain:{
80  tcp_socket
81  udp_socket
82  rawip_socket
83  tun_socket
84} { read write getattr setattr getopt setopt };
85allow netd netdomain:fd use;
86
87# give netd permission to read and write netlink xfrm
88allow netd self:netlink_xfrm_socket { create_socket_perms_no_ioctl nlmsg_write nlmsg_read };
89
90###
91### Neverallow rules
92###
93### netd should NEVER do any of this
94
95# Block device access.
96neverallow netd dev_type:blk_file { read write };
97
98# ptrace any other app
99neverallow netd { domain }:process ptrace;
100
101# Write to /system.
102neverallow netd system_file:dir_file_class_set write;
103
104# Write to files in /data/data or system files on /data
105neverallow netd { app_data_file system_data_file }:dir_file_class_set write;
106
107# only system_server, dumpstate and netd  may interact with netd over binder
108neverallow { domain -system_server -dumpstate -netd } netd_service:service_manager find;
109neverallow { domain -system_server -dumpstate } netd:binder call;
110neverallow netd { domain -system_server -servicemanager userdebug_or_eng(`-su') }:binder call;
111