xref: /aosp_15_r20/system/sepolicy/prebuilts/api/31.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 Workerallow netd fs_bpf:dir search;
68*e4a36f41SAndroid Build Coastguard Workerallow netd fs_bpf:file { read write };
69*e4a36f41SAndroid Build Coastguard Worker
70*e4a36f41SAndroid Build Coastguard Worker# TODO: netd previously thought it needed these permissions to do WiFi related
71*e4a36f41SAndroid Build Coastguard Worker#       work.  However, after all the WiFi stuff is gone, we still need them.
72*e4a36f41SAndroid Build Coastguard Worker#       Why?
73*e4a36f41SAndroid Build Coastguard Workerallow netd self:global_capability_class_set { dac_override dac_read_search chown };
74*e4a36f41SAndroid Build Coastguard Worker
75*e4a36f41SAndroid Build Coastguard Worker# Needed to update /data/misc/net/rt_tables
76*e4a36f41SAndroid Build Coastguard Workerallow netd net_data_file:file create_file_perms;
77*e4a36f41SAndroid Build Coastguard Workerallow netd net_data_file:dir rw_dir_perms;
78*e4a36f41SAndroid Build Coastguard Workerallow netd self:global_capability_class_set fowner;
79*e4a36f41SAndroid Build Coastguard Worker
80*e4a36f41SAndroid Build Coastguard Worker# Needed to lock the iptables lock.
81*e4a36f41SAndroid Build Coastguard Workerallow netd system_file:file lock;
82*e4a36f41SAndroid Build Coastguard Worker
83*e4a36f41SAndroid Build Coastguard Worker# Allow netd to spawn dnsmasq in it's own domain
84*e4a36f41SAndroid Build Coastguard Workerallow netd dnsmasq:process signal;
85*e4a36f41SAndroid Build Coastguard Worker
86*e4a36f41SAndroid Build Coastguard Worker# Allow netd to publish a binder service and make binder calls.
87*e4a36f41SAndroid Build Coastguard Workerbinder_use(netd)
88*e4a36f41SAndroid Build Coastguard Workeradd_service(netd, netd_service)
89*e4a36f41SAndroid Build Coastguard Workeradd_service(netd, dnsresolver_service)
90*e4a36f41SAndroid Build Coastguard Workerallow netd dumpstate:fifo_file  { getattr write };
91*e4a36f41SAndroid Build Coastguard Worker
92*e4a36f41SAndroid Build Coastguard Worker# Allow netd to call into the system server so it can check permissions.
93*e4a36f41SAndroid Build Coastguard Workerallow netd system_server:binder call;
94*e4a36f41SAndroid Build Coastguard Workerallow netd permission_service:service_manager find;
95*e4a36f41SAndroid Build Coastguard Worker
96*e4a36f41SAndroid Build Coastguard Worker# Allow netd to talk to the framework service which collects netd events.
97*e4a36f41SAndroid Build Coastguard Workerallow netd netd_listener_service:service_manager find;
98*e4a36f41SAndroid Build Coastguard Worker
99*e4a36f41SAndroid Build Coastguard Worker# Allow netd to operate on sockets that are passed to it.
100*e4a36f41SAndroid Build Coastguard Workerallow netd netdomain:{
101*e4a36f41SAndroid Build Coastguard Worker  icmp_socket
102*e4a36f41SAndroid Build Coastguard Worker  tcp_socket
103*e4a36f41SAndroid Build Coastguard Worker  udp_socket
104*e4a36f41SAndroid Build Coastguard Worker  rawip_socket
105*e4a36f41SAndroid Build Coastguard Worker  tun_socket
106*e4a36f41SAndroid Build Coastguard Worker} { read write getattr setattr getopt setopt };
107*e4a36f41SAndroid Build Coastguard Workerallow netd netdomain:fd use;
108*e4a36f41SAndroid Build Coastguard Worker
109*e4a36f41SAndroid Build Coastguard Worker# give netd permission to read and write netlink xfrm
110*e4a36f41SAndroid Build Coastguard Workerallow netd self:netlink_xfrm_socket { create_socket_perms_no_ioctl nlmsg_write nlmsg_read };
111*e4a36f41SAndroid Build Coastguard Worker
112*e4a36f41SAndroid Build Coastguard Worker# Allow netd to register as hal server.
113*e4a36f41SAndroid Build Coastguard Workeradd_hwservice(netd, system_net_netd_hwservice)
114*e4a36f41SAndroid Build Coastguard Workerhwbinder_use(netd)
115*e4a36f41SAndroid Build Coastguard Worker
116*e4a36f41SAndroid Build Coastguard Worker###
117*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules
118*e4a36f41SAndroid Build Coastguard Worker###
119*e4a36f41SAndroid Build Coastguard Worker### netd should NEVER do any of this
120*e4a36f41SAndroid Build Coastguard Worker
121*e4a36f41SAndroid Build Coastguard Worker# Block device access.
122*e4a36f41SAndroid Build Coastguard Workerneverallow netd dev_type:blk_file { read write };
123*e4a36f41SAndroid Build Coastguard Worker
124*e4a36f41SAndroid Build Coastguard Worker# ptrace any other app
125*e4a36f41SAndroid Build Coastguard Workerneverallow netd { domain }:process ptrace;
126*e4a36f41SAndroid Build Coastguard Worker
127*e4a36f41SAndroid Build Coastguard Worker# Write to /system.
128*e4a36f41SAndroid Build Coastguard Workerneverallow netd system_file:dir_file_class_set write;
129*e4a36f41SAndroid Build Coastguard Worker
130*e4a36f41SAndroid Build Coastguard Worker# Write to files in /data/data or system files on /data
131*e4a36f41SAndroid Build Coastguard Workerneverallow netd { app_data_file_type system_data_file }:dir_file_class_set write;
132*e4a36f41SAndroid Build Coastguard Worker
133*e4a36f41SAndroid Build Coastguard Worker# only system_server, dumpstate and network stack app may find netd service
134*e4a36f41SAndroid Build Coastguard Workerneverallow {
135*e4a36f41SAndroid Build Coastguard Worker    domain
136*e4a36f41SAndroid Build Coastguard Worker    -system_server
137*e4a36f41SAndroid Build Coastguard Worker    -dumpstate
138*e4a36f41SAndroid Build Coastguard Worker    -network_stack
139*e4a36f41SAndroid Build Coastguard Worker    -netd
140*e4a36f41SAndroid Build Coastguard Worker    -netutils_wrapper
141*e4a36f41SAndroid Build Coastguard Worker} netd_service:service_manager find;
142*e4a36f41SAndroid Build Coastguard Worker
143*e4a36f41SAndroid Build Coastguard Worker# only system_server, dumpstate and network stack app may find dnsresolver service
144*e4a36f41SAndroid Build Coastguard Workerneverallow {
145*e4a36f41SAndroid Build Coastguard Worker    domain
146*e4a36f41SAndroid Build Coastguard Worker    -system_server
147*e4a36f41SAndroid Build Coastguard Worker    -dumpstate
148*e4a36f41SAndroid Build Coastguard Worker    -network_stack
149*e4a36f41SAndroid Build Coastguard Worker    -netd
150*e4a36f41SAndroid Build Coastguard Worker    -netutils_wrapper
151*e4a36f41SAndroid Build Coastguard Worker} dnsresolver_service:service_manager find;
152*e4a36f41SAndroid Build Coastguard Worker
153*e4a36f41SAndroid Build Coastguard Worker# apps may not interact with netd over binder.
154*e4a36f41SAndroid Build Coastguard Workerneverallow { appdomain -network_stack } netd:binder call;
155*e4a36f41SAndroid Build Coastguard Workerneverallow netd { appdomain -network_stack userdebug_or_eng(`-su') }:binder call;
156*e4a36f41SAndroid Build Coastguard Worker
157*e4a36f41SAndroid Build Coastguard Worker# If an already existing file is opened with O_CREATE, the kernel might generate
158*e4a36f41SAndroid Build Coastguard Worker# a false report of a create denial. Silence these denials and make sure that
159*e4a36f41SAndroid Build Coastguard Worker# inappropriate permissions are not granted.
160*e4a36f41SAndroid Build Coastguard Workerneverallow netd proc_net:dir no_w_dir_perms;
161*e4a36f41SAndroid Build Coastguard Workerdontaudit netd proc_net:dir write;
162*e4a36f41SAndroid Build Coastguard Worker
163*e4a36f41SAndroid Build Coastguard Workerneverallow netd sysfs_net:dir no_w_dir_perms;
164*e4a36f41SAndroid Build Coastguard Workerdontaudit netd sysfs_net:dir write;
165*e4a36f41SAndroid Build Coastguard Worker
166*e4a36f41SAndroid Build Coastguard Worker# Netd should not have SYS_ADMIN privs.
167*e4a36f41SAndroid Build Coastguard Workerneverallow netd self:capability sys_admin;
168*e4a36f41SAndroid Build Coastguard Workerdontaudit netd self:capability sys_admin;
169*e4a36f41SAndroid Build Coastguard Worker
170*e4a36f41SAndroid Build Coastguard Worker# Netd should not have SYS_MODULE privs, nor should it be requesting module loads
171*e4a36f41SAndroid Build Coastguard Worker# (things it requires should be built directly into the kernel)
172*e4a36f41SAndroid Build Coastguard Workerdontaudit netd self:capability sys_module;
173*e4a36f41SAndroid Build Coastguard Worker
174*e4a36f41SAndroid Build Coastguard Workerdontaudit netd kernel:system module_request;
175*e4a36f41SAndroid Build Coastguard Worker
176*e4a36f41SAndroid Build Coastguard Workerdontaudit netd appdomain:unix_stream_socket { read write };
177