kernel_optimize_test/net/dccp
Ricardo Dias 01770a1661 tcp: fix race condition when creating child sockets from syncookies
When the TCP stack is in SYN flood mode, the server child socket is
created from the SYN cookie received in a TCP packet with the ACK flag
set.

The child socket is created when the server receives the first TCP
packet with a valid SYN cookie from the client. Usually, this packet
corresponds to the final step of the TCP 3-way handshake, the ACK
packet. But is also possible to receive a valid SYN cookie from the
first TCP data packet sent by the client, and thus create a child socket
from that SYN cookie.

Since a client socket is ready to send data as soon as it receives the
SYN+ACK packet from the server, the client can send the ACK packet (sent
by the TCP stack code), and the first data packet (sent by the userspace
program) almost at the same time, and thus the server will equally
receive the two TCP packets with valid SYN cookies almost at the same
instant.

When such event happens, the TCP stack code has a race condition that
occurs between the momement a lookup is done to the established
connections hashtable to check for the existence of a connection for the
same client, and the moment that the child socket is added to the
established connections hashtable. As a consequence, this race condition
can lead to a situation where we add two child sockets to the
established connections hashtable and deliver two sockets to the
userspace program to the same client.

This patch fixes the race condition by checking if an existing child
socket exists for the same client when we are adding the second child
socket to the established connections socket. If an existing child
socket exists, we drop the packet and discard the second child socket
to the same client.

Signed-off-by: Ricardo Dias <rdias@singlestore.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20201120111133.GA67501@rdias-suse-pc.lan
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-11-23 16:32:33 -08:00
..
ccids net: dccp: Convert to use the preferred fallthrough macro 2020-08-22 12:38:34 -07:00
ackvec.c net: dccp: delete repeated words 2020-08-24 17:31:20 -07:00
ackvec.h
ccid.c
ccid.h net: dccp: Replace zero-length array with flexible-array member 2020-02-28 12:08:37 -08:00
dccp.h net: pass a sockptr_t into ->setsockopt 2020-07-24 15:41:54 -07:00
diag.c inet_diag: Move the INET_DIAG_REQ_BYTECODE nlattr to cb->data 2020-02-27 18:50:19 -08:00
feat.c net: dccp: Convert to use the preferred fallthrough macro 2020-08-22 12:38:34 -07:00
feat.h
input.c net: dccp: Convert to use the preferred fallthrough macro 2020-08-22 12:38:34 -07:00
ipv4.c tcp: fix race condition when creating child sockets from syncookies 2020-11-23 16:32:33 -08:00
ipv6.c tcp: fix race condition when creating child sockets from syncookies 2020-11-23 16:32:33 -08:00
ipv6.h
Kconfig dccp: Replace HTTP links with HTTPS ones 2020-07-13 11:54:07 -07:00
Makefile
minisocks.c
options.c net: dccp: Convert to use the preferred fallthrough macro 2020-08-22 12:38:34 -07:00
output.c net: dccp: Convert to use the preferred fallthrough macro 2020-08-22 12:38:34 -07:00
proto.c net: dccp: Convert to use the preferred fallthrough macro 2020-08-22 12:38:34 -07:00
qpolicy.c
sysctl.c
timer.c inet: remove icsk_ack.blocked 2020-09-30 14:21:30 -07:00
trace.h