Commit 2e8702c
bpf: Support dual-stack sockets in bpf_tcp_check_syncookie
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: 3990408 ("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.com1 parent 0a210af commit 2e8702c
1 file changed
Lines changed: 13 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7016 | 7016 | | |
7017 | 7017 | | |
7018 | 7018 | | |
| 7019 | + | |
| 7020 | + | |
| 7021 | + | |
7019 | 7022 | | |
7020 | 7023 | | |
7021 | 7024 | | |
7022 | 7025 | | |
7023 | 7026 | | |
7024 | | - | |
7025 | | - | |
7026 | | - | |
| 7027 | + | |
| 7028 | + | |
| 7029 | + | |
| 7030 | + | |
| 7031 | + | |
| 7032 | + | |
7027 | 7033 | | |
7028 | 7034 | | |
7029 | 7035 | | |
7030 | 7036 | | |
7031 | 7037 | | |
7032 | 7038 | | |
7033 | | - | |
| 7039 | + | |
7034 | 7040 | | |
7035 | 7041 | | |
7036 | 7042 | | |
| 7043 | + | |
| 7044 | + | |
| 7045 | + | |
7037 | 7046 | | |
7038 | 7047 | | |
7039 | 7048 | | |
| |||
0 commit comments