]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Fix [::] -> [::1] rewrite in sys_sendmsg
authorAndrey Ignatov <rdna@fb.com>
Fri, 4 Jan 2019 09:07:07 +0000 (01:07 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 5 Jan 2019 04:23:33 +0000 (20:23 -0800)
commit32a96ee016a3336369d4cf1c97986c875dda4e5b
treed7a0a1a4a052f8cbf7ea95b05e6383c28028fe81
parentd5d01367e61085eceabb627fbce6a69088e81f0d
bpf: Fix [::] -> [::1] rewrite in sys_sendmsg

sys_sendmsg has supported unspecified destination IPv6 (wildcard) for
unconnected UDP sockets since 43856d23. 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
43856d23, 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: 3d7de0dd045a ("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>
net/ipv6/udp.c