Commit 1b04c68
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 <[email protected]>
Reviewed-by: Tariq Toukan <[email protected]>1 parent e726e00 commit 1b04c68
File tree
2 files changed
+72
-23
lines changed- net/core
- tools/testing/selftests/bpf
2 files changed
+72
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6777 | 6777 | | |
6778 | 6778 | | |
6779 | 6779 | | |
| 6780 | + | |
| 6781 | + | |
| 6782 | + | |
6780 | 6783 | | |
6781 | 6784 | | |
6782 | 6785 | | |
6783 | 6786 | | |
6784 | 6787 | | |
6785 | | - | |
6786 | | - | |
6787 | | - | |
| 6788 | + | |
| 6789 | + | |
| 6790 | + | |
| 6791 | + | |
| 6792 | + | |
| 6793 | + | |
6788 | 6794 | | |
6789 | 6795 | | |
6790 | 6796 | | |
6791 | 6797 | | |
6792 | 6798 | | |
6793 | 6799 | | |
6794 | | - | |
| 6800 | + | |
6795 | 6801 | | |
6796 | 6802 | | |
6797 | 6803 | | |
| 6804 | + | |
| 6805 | + | |
| 6806 | + | |
6798 | 6807 | | |
6799 | 6808 | | |
6800 | 6809 | | |
| |||
Lines changed: 59 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
31 | 40 | | |
32 | 41 | | |
33 | 42 | | |
| |||
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
50 | | - | |
| 59 | + | |
51 | 60 | | |
52 | | - | |
53 | | - | |
54 | 61 | | |
55 | 62 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
116 | 118 | | |
117 | 119 | | |
118 | 120 | | |
119 | | - | |
| 121 | + | |
| 122 | + | |
120 | 123 | | |
121 | 124 | | |
122 | 125 | | |
| |||
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
145 | | - | |
| 148 | + | |
146 | 149 | | |
147 | 150 | | |
148 | 151 | | |
| |||
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
202 | 220 | | |
203 | 221 | | |
204 | 222 | | |
205 | 223 | | |
| 224 | + | |
| 225 | + | |
206 | 226 | | |
207 | 227 | | |
| 228 | + | |
208 | 229 | | |
209 | 230 | | |
210 | 231 | | |
| |||
224 | 245 | | |
225 | 246 | | |
226 | 247 | | |
| 248 | + | |
227 | 249 | | |
228 | 250 | | |
229 | 251 | | |
230 | 252 | | |
231 | 253 | | |
232 | 254 | | |
233 | | - | |
234 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
235 | 263 | | |
236 | 264 | | |
237 | 265 | | |
238 | | - | |
239 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
240 | 277 | | |
241 | 278 | | |
242 | | - | |
| 279 | + | |
| 280 | + | |
243 | 281 | | |
244 | 282 | | |
245 | | - | |
| 283 | + | |
| 284 | + | |
246 | 285 | | |
247 | 286 | | |
248 | 287 | | |
| |||
252 | 291 | | |
253 | 292 | | |
254 | 293 | | |
| 294 | + | |
255 | 295 | | |
256 | 296 | | |
257 | 297 | | |
0 commit comments