Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 1 | # network manager |
| 2 | type netd, domain, mlstrustedsubject; |
| 3 | type netd_exec, system_file_type, exec_type, file_type; |
| 4 | |
| 5 | net_domain(netd) |
| 6 | # in addition to ioctls allowlisted for all domains, grant netd priv_sock_ioctls. |
| 7 | allowxperm netd self:udp_socket ioctl priv_sock_ioctls; |
| 8 | |
| 9 | r_dir_file(netd, cgroup) |
| 10 | |
| 11 | allow netd system_server:fd use; |
| 12 | |
| 13 | allow 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. |
| 20 | dontaudit netd self:global_capability_class_set fsetid; |
| 21 | |
| 22 | # Allow netd to open /dev/tun, set it up and pass it to clatd |
| 23 | allow netd tun_device:chr_file rw_file_perms; |
| 24 | allowxperm netd tun_device:chr_file ioctl { TUNGETIFF TUNSETIFF }; |
| 25 | allow netd self:tun_socket create; |
| 26 | |
| 27 | allow netd self:netlink_kobject_uevent_socket create_socket_perms_no_ioctl; |
| 28 | allow netd self:netlink_route_socket nlmsg_write; |
| 29 | allow netd self:netlink_nflog_socket create_socket_perms_no_ioctl; |
| 30 | allow netd self:netlink_socket create_socket_perms_no_ioctl; |
| 31 | allow netd self:netlink_tcpdiag_socket { create_socket_perms_no_ioctl nlmsg_read nlmsg_write }; |
| 32 | allow netd self:netlink_generic_socket create_socket_perms_no_ioctl; |
| 33 | allow netd self:netlink_netfilter_socket create_socket_perms_no_ioctl; |
| 34 | allow netd shell_exec:file rx_file_perms; |
| 35 | allow netd system_file:file x_file_perms; |
| 36 | not_full_treble(`allow netd vendor_file:file x_file_perms;') |
| 37 | allow 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. |
| 41 | allow netd system_file:file lock; |
| 42 | dontaudit 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 |
| 47 | allow 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. |
| 49 | allow netd qtaguid_device:chr_file r_file_perms; |
| 50 | |
| 51 | r_dir_file(netd, proc_net_type) |
| 52 | # For /proc/sys/net/ipv[46]/route/flush. |
| 53 | allow netd proc_net_type:file rw_file_perms; |
| 54 | |
| 55 | # Enables PppController and interface enumeration (among others) |
| 56 | allow netd sysfs:dir r_dir_perms; |
| 57 | r_dir_file(netd, sysfs_net) |
| 58 | |
| 59 | # Allows setting interface MTU |
| 60 | allow netd sysfs_net:file w_file_perms; |
| 61 | |
| 62 | # TODO: added to match above sysfs rule. Remove me? |
| 63 | allow netd sysfs_usb:file write; |
| 64 | |
| 65 | r_dir_file(netd, cgroup_v2) |
| 66 | |
| 67 | allow netd fs_bpf:dir search; |
| 68 | allow netd fs_bpf:file { read write }; |
| 69 | |
| 70 | # TODO: netd previously thought it needed these permissions to do WiFi related |
| 71 | # work. However, after all the WiFi stuff is gone, we still need them. |
| 72 | # Why? |
| 73 | allow netd self:global_capability_class_set { dac_override dac_read_search chown }; |
| 74 | |
| 75 | # Needed to update /data/misc/net/rt_tables |
| 76 | allow netd net_data_file:file create_file_perms; |
| 77 | allow netd net_data_file:dir rw_dir_perms; |
| 78 | allow netd self:global_capability_class_set fowner; |
| 79 | |
| 80 | # Needed to lock the iptables lock. |
| 81 | allow netd system_file:file lock; |
| 82 | |
| 83 | # Allow netd to spawn dnsmasq in it's own domain |
| 84 | allow netd dnsmasq:process signal; |
| 85 | |
| 86 | # Allow netd to publish a binder service and make binder calls. |
| 87 | binder_use(netd) |
| 88 | add_service(netd, netd_service) |
| 89 | add_service(netd, dnsresolver_service) |
| 90 | allow netd dumpstate:fifo_file { getattr write }; |
| 91 | |
| 92 | # Allow netd to call into the system server so it can check permissions. |
| 93 | allow netd system_server:binder call; |
| 94 | allow netd permission_service:service_manager find; |
| 95 | |
| 96 | # Allow netd to talk to the framework service which collects netd events. |
| 97 | allow netd netd_listener_service:service_manager find; |
| 98 | |
| 99 | # Allow netd to operate on sockets that are passed to it. |
| 100 | allow netd netdomain:{ |
| 101 | icmp_socket |
| 102 | tcp_socket |
| 103 | udp_socket |
| 104 | rawip_socket |
| 105 | tun_socket |
| 106 | } { read write getattr setattr getopt setopt }; |
| 107 | allow netd netdomain:fd use; |
| 108 | |
| 109 | # give netd permission to read and write netlink xfrm |
| 110 | allow netd self:netlink_xfrm_socket { create_socket_perms_no_ioctl nlmsg_write nlmsg_read }; |
| 111 | |
| 112 | # Allow netd to register as hal server. |
| 113 | add_hwservice(netd, system_net_netd_hwservice) |
| 114 | hwbinder_use(netd) |
| 115 | |
| 116 | ### |
| 117 | ### Neverallow rules |
| 118 | ### |
| 119 | ### netd should NEVER do any of this |
| 120 | |
| 121 | # Block device access. |
| 122 | neverallow netd dev_type:blk_file { read write }; |
| 123 | |
| 124 | # ptrace any other app |
| 125 | neverallow netd { domain }:process ptrace; |
| 126 | |
| 127 | # Write to /system. |
| 128 | neverallow netd system_file:dir_file_class_set write; |
| 129 | |
| 130 | # Write to files in /data/data or system files on /data |
| 131 | neverallow netd { app_data_file_type system_data_file }:dir_file_class_set write; |
| 132 | |
| 133 | # only system_server, dumpstate and network stack app may find netd service |
| 134 | neverallow { |
| 135 | domain |
| 136 | -system_server |
| 137 | -dumpstate |
| 138 | -network_stack |
| 139 | -netd |
| 140 | -netutils_wrapper |
| 141 | } netd_service:service_manager find; |
| 142 | |
| 143 | # only system_server, dumpstate and network stack app may find dnsresolver service |
| 144 | neverallow { |
| 145 | domain |
| 146 | -system_server |
| 147 | -dumpstate |
| 148 | -network_stack |
| 149 | -netd |
| 150 | -netutils_wrapper |
| 151 | } dnsresolver_service:service_manager find; |
| 152 | |
| 153 | # apps may not interact with netd over binder. |
| 154 | neverallow { appdomain -network_stack } netd:binder call; |
| 155 | neverallow netd { appdomain -network_stack userdebug_or_eng(`-su') }:binder call; |
| 156 | |
| 157 | # If an already existing file is opened with O_CREATE, the kernel might generate |
| 158 | # a false report of a create denial. Silence these denials and make sure that |
| 159 | # inappropriate permissions are not granted. |
| 160 | neverallow netd proc_net:dir no_w_dir_perms; |
| 161 | dontaudit netd proc_net:dir write; |
| 162 | |
| 163 | neverallow netd sysfs_net:dir no_w_dir_perms; |
| 164 | dontaudit netd sysfs_net:dir write; |
| 165 | |
| 166 | # Netd should not have SYS_ADMIN privs. |
| 167 | neverallow netd self:capability sys_admin; |
| 168 | dontaudit netd self:capability sys_admin; |
| 169 | |
| 170 | # Netd should not have SYS_MODULE privs, nor should it be requesting module loads |
| 171 | # (things it requires should be built directly into the kernel) |
| 172 | dontaudit netd self:capability sys_module; |
| 173 | |
| 174 | dontaudit netd kernel:system module_request; |
| 175 | |
| 176 | dontaudit netd appdomain:unix_stream_socket { read write }; |