]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
bpf: Support dual-stack sockets in bpf_tcp_check_syncookie
authorMaxim Mikityanskiy <maximmi@nvidia.com>
Wed, 6 Apr 2022 12:41:12 +0000 (15:41 +0300)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 12:41:09 +0000 (14:41 +0200)
commite164f1c0ff248898dc08423583d76407aacbbf88
treeeafb38377694eb8c577c41035be1a825e9d32d0b
parent155bf86f1fd0ac19d9201eff50937735c2b333a9
bpf: Support dual-stack sockets in bpf_tcp_check_syncookie

BugLink: https://bugs.launchpad.net/bugs/1969107
[ Upstream commit 2e8702cc0cfa1080f29fd64003c00a3e24ac38de ]

bpf_tcp_gen_syncookie looks at the IP version in the IP header and
validates the address family of the socket. It supports IPv4 packets in
AF_INET6 dual-stack sockets.

On the other hand, bpf_tcp_check_syncookie looks only at the address
family of the socket, ignoring the real IP version in headers, and
validates only the packet size. This implementation has some drawbacks:

1. Packets are not validated properly, allowing a BPF program to trick
   bpf_tcp_check_syncookie into handling an IPv6 packet on an IPv4
   socket.

2. Dual-stack sockets fail the checks on IPv4 packets. IPv4 clients end
   up receiving a SYNACK with the cookie, but the following ACK gets
   dropped.

This patch fixes these issues by changing the checks in
bpf_tcp_check_syncookie to match the ones in bpf_tcp_gen_syncookie. IP
version from the header is taken into account, and it is validated
properly with address family.

Fixes: 399040847084 ("bpf: add helper to check for a valid SYN cookie")
Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Acked-by: Arthur Fabre <afabre@cloudflare.com>
Link: https://lore.kernel.org/bpf/20220406124113.2795730-1-maximmi@nvidia.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 1816af613e56c4f9fd0ef1234aa3fbd7644cc9c4)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
net/core/filter.c