aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp_input.c
diff options
context:
space:
mode:
authorGuillaume Nault <gnault@redhat.com>2019-03-08 16:09:47 -0500
committerDavid S. Miller <davem@davemloft.net>2019-03-08 19:05:10 -0500
commit9d3e1368bb45893a75a5dfb7cd21fdebfa6b47af (patch)
tree803b92c4735eb270910bc9846273b00e65343729 /net/ipv4/tcp_input.c
parent09073525f8b9095931e5a82209b61abc7ce4c9d5 (diff)
tcp: handle inet_csk_reqsk_queue_add() failures
Commit 7716682cc58e ("tcp/dccp: fix another race at listener dismantle") let inet_csk_reqsk_queue_add() fail, and adjusted {tcp,dccp}_check_req() accordingly. However, TFO and syncookies weren't modified, thus leaking allocated resources on error. Contrary to tcp_check_req(), in both syncookies and TFO cases, we need to drop the request socket. Also, since the child socket is created with inet_csk_clone_lock(), we have to unlock it and drop an extra reference (->sk_refcount is initially set to 2 and inet_csk_reqsk_queue_add() drops only one ref). For TFO, we also need to revert the work done by tcp_try_fastopen() (with reqsk_fastopen_remove()). Fixes: 7716682cc58e ("tcp/dccp: fix another race at listener dismantle") Signed-off-by: Guillaume Nault <gnault@redhat.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_input.c')
-rw-r--r--net/ipv4/tcp_input.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 4eb0c8ca3c60..5def3c48870e 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -6498,7 +6498,13 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
6498 af_ops->send_synack(fastopen_sk, dst, &fl, req, 6498 af_ops->send_synack(fastopen_sk, dst, &fl, req,
6499 &foc, TCP_SYNACK_FASTOPEN); 6499 &foc, TCP_SYNACK_FASTOPEN);
6500 /* Add the child socket directly into the accept queue */ 6500 /* Add the child socket directly into the accept queue */
6501 inet_csk_reqsk_queue_add(sk, req, fastopen_sk); 6501 if (!inet_csk_reqsk_queue_add(sk, req, fastopen_sk)) {
6502 reqsk_fastopen_remove(fastopen_sk, req, false);
6503 bh_unlock_sock(fastopen_sk);
6504 sock_put(fastopen_sk);
6505 reqsk_put(req);
6506 goto drop;
6507 }
6502 sk->sk_data_ready(sk); 6508 sk->sk_data_ready(sk);
6503 bh_unlock_sock(fastopen_sk); 6509 bh_unlock_sock(fastopen_sk);
6504 sock_put(fastopen_sk); 6510 sock_put(fastopen_sk);