Skip to content

Commit 70f360d

Browse files
edumazetkuba-moo
authored andcommitted
tcp: annotate data-races around fastopenq.max_qlen
This field can be read locklessly. Fixes: 1536e28 ("tcp: Add a TCP_FASTOPEN socket option to get a max backlog on its listner") Signed-off-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20230719212857.3943972-12-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 26023e9 commit 70f360d

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

include/linux/tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ static inline void fastopen_queue_tune(struct sock *sk, int backlog)
513513
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
514514
int somaxconn = READ_ONCE(sock_net(sk)->core.sysctl_somaxconn);
515515

516-
queue->fastopenq.max_qlen = min_t(unsigned int, backlog, somaxconn);
516+
WRITE_ONCE(queue->fastopenq.max_qlen, min_t(unsigned int, backlog, somaxconn));
517517
}
518518

519519
static inline void tcp_move_syn(struct tcp_sock *tp,

net/ipv4/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4145,7 +4145,7 @@ int do_tcp_getsockopt(struct sock *sk, int level,
41454145
break;
41464146

41474147
case TCP_FASTOPEN:
4148-
val = icsk->icsk_accept_queue.fastopenq.max_qlen;
4148+
val = READ_ONCE(icsk->icsk_accept_queue.fastopenq.max_qlen);
41494149
break;
41504150

41514151
case TCP_FASTOPEN_CONNECT:

net/ipv4/tcp_fastopen.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,
296296
static bool tcp_fastopen_queue_check(struct sock *sk)
297297
{
298298
struct fastopen_queue *fastopenq;
299+
int max_qlen;
299300

300301
/* Make sure the listener has enabled fastopen, and we don't
301302
* exceed the max # of pending TFO requests allowed before trying
@@ -308,10 +309,11 @@ static bool tcp_fastopen_queue_check(struct sock *sk)
308309
* temporarily vs a server not supporting Fast Open at all.
309310
*/
310311
fastopenq = &inet_csk(sk)->icsk_accept_queue.fastopenq;
311-
if (fastopenq->max_qlen == 0)
312+
max_qlen = READ_ONCE(fastopenq->max_qlen);
313+
if (max_qlen == 0)
312314
return false;
313315

314-
if (fastopenq->qlen >= fastopenq->max_qlen) {
316+
if (fastopenq->qlen >= max_qlen) {
315317
struct request_sock *req1;
316318
spin_lock(&fastopenq->lock);
317319
req1 = fastopenq->rskq_rst_head;

0 commit comments

Comments
 (0)