aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp_timer.c
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2019-10-10 23:17:38 -0400
committerDavid S. Miller <davem@davemloft.net>2019-10-13 13:13:08 -0400
commitd983ea6f16b835dcde2ee9a58a1e764ce68bfccc (patch)
tree2bc283f36a6769e0247c49420f0c2149f147f08c /net/ipv4/tcp_timer.c
parent8caf8a91f34d55e8e3b1355ee8d658cb472146e2 (diff)
tcp: add rcu protection around tp->fastopen_rsk
Both tcp_v4_err() and tcp_v6_err() do the following operations while they do not own the socket lock : fastopen = tp->fastopen_rsk; snd_una = fastopen ? tcp_rsk(fastopen)->snt_isn : tp->snd_una; The problem is that without appropriate barrier, the compiler might reload tp->fastopen_rsk and trigger a NULL deref. request sockets are protected by RCU, we can simply add the missing annotations and barriers to solve the issue. Fixes: 168a8f58059a ("tcp: TCP Fast Open Server - main code path") Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_timer.c')
-rw-r--r--net/ipv4/tcp_timer.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 05be564414e9..dd5a6317a801 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -386,15 +386,13 @@ abort: tcp_write_err(sk);
386 * Timer for Fast Open socket to retransmit SYNACK. Note that the 386 * Timer for Fast Open socket to retransmit SYNACK. Note that the
387 * sk here is the child socket, not the parent (listener) socket. 387 * sk here is the child socket, not the parent (listener) socket.
388 */ 388 */
389static void tcp_fastopen_synack_timer(struct sock *sk) 389static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)
390{ 390{
391 struct inet_connection_sock *icsk = inet_csk(sk); 391 struct inet_connection_sock *icsk = inet_csk(sk);
392 int max_retries = icsk->icsk_syn_retries ? : 392 int max_retries = icsk->icsk_syn_retries ? :
393 sock_net(sk)->ipv4.sysctl_tcp_synack_retries + 1; /* add one more retry for fastopen */ 393 sock_net(sk)->ipv4.sysctl_tcp_synack_retries + 1; /* add one more retry for fastopen */
394 struct tcp_sock *tp = tcp_sk(sk); 394 struct tcp_sock *tp = tcp_sk(sk);
395 struct request_sock *req;
396 395
397 req = tcp_sk(sk)->fastopen_rsk;
398 req->rsk_ops->syn_ack_timeout(req); 396 req->rsk_ops->syn_ack_timeout(req);
399 397
400 if (req->num_timeout >= max_retries) { 398 if (req->num_timeout >= max_retries) {
@@ -435,11 +433,14 @@ void tcp_retransmit_timer(struct sock *sk)
435 struct tcp_sock *tp = tcp_sk(sk); 433 struct tcp_sock *tp = tcp_sk(sk);
436 struct net *net = sock_net(sk); 434 struct net *net = sock_net(sk);
437 struct inet_connection_sock *icsk = inet_csk(sk); 435 struct inet_connection_sock *icsk = inet_csk(sk);
436 struct request_sock *req;
438 437
439 if (tp->fastopen_rsk) { 438 req = rcu_dereference_protected(tp->fastopen_rsk,
439 lockdep_sock_is_held(sk));
440 if (req) {
440 WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV && 441 WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV &&
441 sk->sk_state != TCP_FIN_WAIT1); 442 sk->sk_state != TCP_FIN_WAIT1);
442 tcp_fastopen_synack_timer(sk); 443 tcp_fastopen_synack_timer(sk, req);
443 /* Before we receive ACK to our SYN-ACK don't retransmit 444 /* Before we receive ACK to our SYN-ACK don't retransmit
444 * anything else (e.g., data or FIN segments). 445 * anything else (e.g., data or FIN segments).
445 */ 446 */