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. If this file doesn't 40# exist, suppress the denial. 41allow netd system_file:file lock; 42dontaudit netd system_file:dir write; 43 44# Allow netd to write to qtaguid ctrl file. 45# TODO: Add proper rules to prevent other process to access qtaguid_proc file 46# after migration complete 47allow netd proc_qtaguid_ctrl:file rw_file_perms; 48# Allow netd to read /dev/qtaguid. This is the same privilege level that normal apps have. 49allow netd qtaguid_device:chr_file r_file_perms; 50 51r_dir_file(netd, proc_net_type) 52# For /proc/sys/net/ipv[46]/route/flush. 53allow netd proc_net_type:file rw_file_perms; 54 55# Enables PppController and interface enumeration (among others) 56allow netd sysfs:dir r_dir_perms; 57r_dir_file(netd, sysfs_net) 58 59# Allows setting interface MTU 60allow netd sysfs_net:file w_file_perms; 61 62# TODO: added to match above sysfs rule. Remove me? 63allow netd sysfs_usb:file write; 64 65r_dir_file(netd, cgroup_v2) 66 67# TODO: netd previously thought it needed these permissions to do WiFi related 68# work. However, after all the WiFi stuff is gone, we still need them. 69# Why? 70allow netd self:global_capability_class_set { dac_override dac_read_search chown }; 71 72# Needed to update /data/misc/net/rt_tables 73allow netd net_data_file:file create_file_perms; 74allow netd net_data_file:dir rw_dir_perms; 75allow netd self:global_capability_class_set fowner; 76 77# Needed to lock the iptables lock. 78allow netd system_file:file lock; 79 80# Allow netd to spawn dnsmasq in it's own domain 81allow netd dnsmasq:process signal; 82 83# Allow netd to publish a binder service and make binder calls. 84binder_use(netd) 85add_service(netd, netd_service) 86add_service(netd, dnsresolver_service) 87add_service(netd, mdns_service) 88allow netd dumpstate:fifo_file { getattr write }; 89 90# Allow netd to call into the system server so it can check permissions. 91allow netd system_server:binder call; 92allow netd permission_service:service_manager find; 93 94# Allow netd to talk to the framework service which collects netd events. 95allow netd netd_listener_service:service_manager find; 96 97# Allow netd to operate on sockets that are passed to it. 98allow netd netdomain:{ 99 icmp_socket 100 tcp_socket 101 udp_socket 102 rawip_socket 103 tun_socket 104} { read write getattr setattr getopt setopt }; 105allow netd netdomain:fd use; 106 107# give netd permission to read and write netlink xfrm 108allow netd self:netlink_xfrm_socket { create_socket_perms_no_ioctl nlmsg_write nlmsg_read }; 109 110# Allow netd to register as hal server. 111add_hwservice(netd, system_net_netd_hwservice) 112hwbinder_use(netd) 113 114### 115### Neverallow rules 116### 117### netd should NEVER do any of this 118 119# Block device access. 120neverallow netd dev_type:blk_file { read write }; 121 122# ptrace any other app 123neverallow netd { domain }:process ptrace; 124 125# Write to /system. 126neverallow netd system_file:dir_file_class_set write; 127 128# Write to files in /data/data or system files on /data 129neverallow netd { app_data_file_type system_data_file }:dir_file_class_set write; 130 131# only system_server, dumpstate and network stack app may find netd service 132neverallow { 133 domain 134 -system_server 135 -dumpstate 136 -network_stack 137 -netd 138 -netutils_wrapper 139} netd_service:service_manager find; 140 141# only system_server, dumpstate and network stack app may find dnsresolver service 142neverallow { 143 domain 144 -system_server 145 -dumpstate 146 -network_stack 147 -netd 148 -netutils_wrapper 149} dnsresolver_service:service_manager find; 150 151# only system_server, dumpstate and network stack app may find mdns service 152neverallow { 153 domain 154 -system_server 155 -dumpstate 156 -network_stack 157 -netd 158 -netutils_wrapper 159} mdns_service:service_manager find; 160 161# apps may not interact with netd over binder. 162neverallow { appdomain -network_stack } netd:binder call; 163neverallow netd { appdomain -network_stack userdebug_or_eng(`-su') }:binder call; 164 165# If an already existing file is opened with O_CREATE, the kernel might generate 166# a false report of a create denial. Silence these denials and make sure that 167# inappropriate permissions are not granted. 168neverallow netd proc_net:dir no_w_dir_perms; 169dontaudit netd proc_net:dir write; 170 171neverallow netd sysfs_net:dir no_w_dir_perms; 172dontaudit netd sysfs_net:dir write; 173 174# Netd should not have SYS_ADMIN privs. 175neverallow netd self:capability sys_admin; 176dontaudit netd self:capability sys_admin; 177 178# Netd should not have SYS_MODULE privs, nor should it be requesting module loads 179# (things it requires should be built directly into the kernel) 180dontaudit netd self:capability sys_module; 181 182dontaudit netd kernel:system module_request; 183 184dontaudit netd appdomain:unix_stream_socket { read write }; 185