aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/tcp.h2
-rw-r--r--net/core/request_sock.c18
-rw-r--r--net/ipv4/inet_connection_sock.c7
-rw-r--r--net/ipv4/syncookies.c2
-rw-r--r--net/ipv4/tcp_fastopen.c7
-rw-r--r--net/ipv4/tcp_input.c2
-rw-r--r--net/ipv6/syncookies.c2
7 files changed, 15 insertions, 25 deletions
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 97dbf16f7d9d..f869ae8afbaf 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -111,7 +111,7 @@ struct tcp_request_sock_ops;
111struct tcp_request_sock { 111struct tcp_request_sock {
112 struct inet_request_sock req; 112 struct inet_request_sock req;
113 const struct tcp_request_sock_ops *af_specific; 113 const struct tcp_request_sock_ops *af_specific;
114 struct sock *listener; /* needed for TFO */ 114 bool tfo_listener;
115 u32 rcv_isn; 115 u32 rcv_isn;
116 u32 snt_isn; 116 u32 snt_isn;
117 u32 snt_synack; /* synack sent time */ 117 u32 snt_synack; /* synack sent time */
diff --git a/net/core/request_sock.c b/net/core/request_sock.c
index e910317ef6d9..cc39a2aa663a 100644
--- a/net/core/request_sock.c
+++ b/net/core/request_sock.c
@@ -153,24 +153,22 @@ void reqsk_queue_destroy(struct request_sock_queue *queue)
153 * case might also exist in tcp_v4_hnd_req() that will trigger this locking 153 * case might also exist in tcp_v4_hnd_req() that will trigger this locking
154 * order. 154 * order.
155 * 155 *
156 * When a TFO req is created, it needs to sock_hold its listener to prevent 156 * This function also sets "treq->tfo_listener" to false.
157 * the latter data structure from going away. 157 * treq->tfo_listener is used by the listener so it is protected by the
158 *
159 * This function also sets "treq->listener" to NULL and unreference listener
160 * socket. treq->listener is used by the listener so it is protected by the
161 * fastopenq->lock in this function. 158 * fastopenq->lock in this function.
162 */ 159 */
163void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req, 160void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
164 bool reset) 161 bool reset)
165{ 162{
166 struct sock *lsk = tcp_rsk(req)->listener; 163 struct sock *lsk = req->rsk_listener;
167 struct fastopen_queue *fastopenq = 164 struct fastopen_queue *fastopenq;
168 inet_csk(lsk)->icsk_accept_queue.fastopenq; 165
166 fastopenq = inet_csk(lsk)->icsk_accept_queue.fastopenq;
169 167
170 tcp_sk(sk)->fastopen_rsk = NULL; 168 tcp_sk(sk)->fastopen_rsk = NULL;
171 spin_lock_bh(&fastopenq->lock); 169 spin_lock_bh(&fastopenq->lock);
172 fastopenq->qlen--; 170 fastopenq->qlen--;
173 tcp_rsk(req)->listener = NULL; 171 tcp_rsk(req)->tfo_listener = false;
174 if (req->sk) /* the child socket hasn't been accepted yet */ 172 if (req->sk) /* the child socket hasn't been accepted yet */
175 goto out; 173 goto out;
176 174
@@ -179,7 +177,6 @@ void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
179 * special RST handling below. 177 * special RST handling below.
180 */ 178 */
181 spin_unlock_bh(&fastopenq->lock); 179 spin_unlock_bh(&fastopenq->lock);
182 sock_put(lsk);
183 reqsk_put(req); 180 reqsk_put(req);
184 return; 181 return;
185 } 182 }
@@ -201,5 +198,4 @@ void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
201 fastopenq->qlen++; 198 fastopenq->qlen++;
202out: 199out:
203 spin_unlock_bh(&fastopenq->lock); 200 spin_unlock_bh(&fastopenq->lock);
204 sock_put(lsk);
205} 201}
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 3390ba6f96b2..741f0d96a7f7 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -325,7 +325,7 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err)
325 sk_acceptq_removed(sk); 325 sk_acceptq_removed(sk);
326 if (sk->sk_protocol == IPPROTO_TCP && queue->fastopenq != NULL) { 326 if (sk->sk_protocol == IPPROTO_TCP && queue->fastopenq != NULL) {
327 spin_lock_bh(&queue->fastopenq->lock); 327 spin_lock_bh(&queue->fastopenq->lock);
328 if (tcp_rsk(req)->listener) { 328 if (tcp_rsk(req)->tfo_listener) {
329 /* We are still waiting for the final ACK from 3WHS 329 /* We are still waiting for the final ACK from 3WHS
330 * so can't free req now. Instead, we set req->sk to 330 * so can't free req now. Instead, we set req->sk to
331 * NULL to signify that the child socket is taken 331 * NULL to signify that the child socket is taken
@@ -817,9 +817,9 @@ void inet_csk_listen_stop(struct sock *sk)
817 817
818 percpu_counter_inc(sk->sk_prot->orphan_count); 818 percpu_counter_inc(sk->sk_prot->orphan_count);
819 819
820 if (sk->sk_protocol == IPPROTO_TCP && tcp_rsk(req)->listener) { 820 if (sk->sk_protocol == IPPROTO_TCP && tcp_rsk(req)->tfo_listener) {
821 BUG_ON(tcp_sk(child)->fastopen_rsk != req); 821 BUG_ON(tcp_sk(child)->fastopen_rsk != req);
822 BUG_ON(sk != tcp_rsk(req)->listener); 822 BUG_ON(sk != req->rsk_listener);
823 823
824 /* Paranoid, to prevent race condition if 824 /* Paranoid, to prevent race condition if
825 * an inbound pkt destined for child is 825 * an inbound pkt destined for child is
@@ -828,7 +828,6 @@ void inet_csk_listen_stop(struct sock *sk)
828 * tcp_v4_destroy_sock(). 828 * tcp_v4_destroy_sock().
829 */ 829 */
830 tcp_sk(child)->fastopen_rsk = NULL; 830 tcp_sk(child)->fastopen_rsk = NULL;
831 sock_put(sk);
832 } 831 }
833 inet_csk_destroy_sock(child); 832 inet_csk_destroy_sock(child);
834 833
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index eb940750bb1b..574b67765a06 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -345,7 +345,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
345 ireq->tstamp_ok = tcp_opt.saw_tstamp; 345 ireq->tstamp_ok = tcp_opt.saw_tstamp;
346 req->ts_recent = tcp_opt.saw_tstamp ? tcp_opt.rcv_tsval : 0; 346 req->ts_recent = tcp_opt.saw_tstamp ? tcp_opt.rcv_tsval : 0;
347 treq->snt_synack = tcp_opt.saw_tstamp ? tcp_opt.rcv_tsecr : 0; 347 treq->snt_synack = tcp_opt.saw_tstamp ? tcp_opt.rcv_tsecr : 0;
348 treq->listener = NULL; 348 treq->tfo_listener = false;
349 ireq->ireq_family = AF_INET; 349 ireq->ireq_family = AF_INET;
350 350
351 ireq->ir_iif = sk->sk_bound_dev_if; 351 ireq->ir_iif = sk->sk_bound_dev_if;
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index 84381319e1bc..186fd394ec0a 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -155,12 +155,7 @@ static bool tcp_fastopen_create_child(struct sock *sk,
155 tp = tcp_sk(child); 155 tp = tcp_sk(child);
156 156
157 tp->fastopen_rsk = req; 157 tp->fastopen_rsk = req;
158 /* Do a hold on the listner sk so that if the listener is being 158 tcp_rsk(req)->tfo_listener = true;
159 * closed, the child that has been accepted can live on and still
160 * access listen_lock.
161 */
162 sock_hold(sk);
163 tcp_rsk(req)->listener = sk;
164 159
165 /* RFC1323: The window in SYN & SYN/ACK segments is never 160 /* RFC1323: The window in SYN & SYN/ACK segments is never
166 * scaled. So correct it appropriately. 161 * scaled. So correct it appropriately.
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index fbe518981d36..a94ddb96fc85 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -6120,7 +6120,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
6120 if (err || want_cookie) 6120 if (err || want_cookie)
6121 goto drop_and_free; 6121 goto drop_and_free;
6122 6122
6123 tcp_rsk(req)->listener = NULL; 6123 tcp_rsk(req)->tfo_listener = false;
6124 af_ops->queue_hash_add(sk, req, TCP_TIMEOUT_INIT); 6124 af_ops->queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
6125 } 6125 }
6126 6126
diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c
index 039e74dd29fe..1ef0c926ce9d 100644
--- a/net/ipv6/syncookies.c
+++ b/net/ipv6/syncookies.c
@@ -195,7 +195,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
195 195
196 ireq = inet_rsk(req); 196 ireq = inet_rsk(req);
197 treq = tcp_rsk(req); 197 treq = tcp_rsk(req);
198 treq->listener = NULL; 198 treq->tfo_listener = false;
199 ireq->ireq_family = AF_INET6; 199 ireq->ireq_family = AF_INET6;
200 200
201 if (security_inet_conn_request(sk, skb, req)) 201 if (security_inet_conn_request(sk, skb, req))