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