aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Ignatov <rdna@fb.com>2019-01-04 04:07:07 -0500
committerAlexei Starovoitov <ast@kernel.org>2019-01-04 23:23:33 -0500
commite8e36984080b55ac5e57bdb09a5b570f2fc8e963 (patch)
treed7a0a1a4a052f8cbf7ea95b05e6383c28028fe81
parentec90ad334986fa5856d11dd272f7f22fa86c55c4 (diff)
bpf: Fix [::] -> [::1] rewrite in sys_sendmsg
sys_sendmsg has supported unspecified destination IPv6 (wildcard) for unconnected UDP sockets since 876c7f41. When [::] is passed by user as destination, sys_sendmsg rewrites it with [::1] to be consistent with BSD (see "BSD'ism" comment in the code). This didn't work when cgroup-bpf was enabled though since the rewrite [::] -> [::1] happened before passing control to cgroup-bpf block where fl6.daddr was updated with passed by user sockaddr_in6.sin6_addr (that might or might not be changed by BPF program). That way if user passed [::] as dst IPv6 it was first rewritten with [::1] by original code from 876c7f41, but then rewritten back with [::] by cgroup-bpf block. It happened even when BPF_CGROUP_UDP6_SENDMSG program was not present (CONFIG_CGROUP_BPF=y was enough). The fix is to apply BSD'ism after cgroup-bpf block so that [::] is replaced with [::1] no matter where it came from: passed by user to sys_sendmsg or set by BPF_CGROUP_UDP6_SENDMSG program. Fixes: 1cedee13d25a ("bpf: Hooks for sys_sendmsg") Reported-by: Nitin Rawat <nitin.rawat@intel.com> Signed-off-by: Andrey Ignatov <rdna@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r--net/ipv6/udp.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 9cbf363172bd..7c3505006f8e 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -1390,10 +1390,7 @@ do_udp_sendmsg:
1390 ipc6.opt = opt; 1390 ipc6.opt = opt;
1391 1391
1392 fl6.flowi6_proto = sk->sk_protocol; 1392 fl6.flowi6_proto = sk->sk_protocol;
1393 if (!ipv6_addr_any(daddr)) 1393 fl6.daddr = *daddr;
1394 fl6.daddr = *daddr;
1395 else
1396 fl6.daddr.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */
1397 if (ipv6_addr_any(&fl6.saddr) && !ipv6_addr_any(&np->saddr)) 1394 if (ipv6_addr_any(&fl6.saddr) && !ipv6_addr_any(&np->saddr))
1398 fl6.saddr = np->saddr; 1395 fl6.saddr = np->saddr;
1399 fl6.fl6_sport = inet->inet_sport; 1396 fl6.fl6_sport = inet->inet_sport;
@@ -1421,6 +1418,9 @@ do_udp_sendmsg:
1421 } 1418 }
1422 } 1419 }
1423 1420
1421 if (ipv6_addr_any(&fl6.daddr))
1422 fl6.daddr.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */
1423
1424 final_p = fl6_update_dst(&fl6, opt, &final); 1424 final_p = fl6_update_dst(&fl6, opt, &final);
1425 if (final_p) 1425 if (final_p)
1426 connected = false; 1426 connected = false;