Skip to content

Commit 099ecf5

Browse files
edumazetdavem330
authored andcommitted
net: annotate lockless accesses to sk->sk_max_ack_backlog
sk->sk_max_ack_backlog can be read without any lock being held at least in TCP/DCCP cases. We need to use READ_ONCE()/WRITE_ONCE() to avoid load/store tearing and/or potential KCSAN warnings. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 288efe8 commit 099ecf5

File tree

9 files changed

+10
-10
lines changed

9 files changed

+10
-10
lines changed

include/net/sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ static inline void sk_acceptq_added(struct sock *sk)
869869

870870
static inline bool sk_acceptq_is_full(const struct sock *sk)
871871
{
872-
return READ_ONCE(sk->sk_ack_backlog) > sk->sk_max_ack_backlog;
872+
return READ_ONCE(sk->sk_ack_backlog) > READ_ONCE(sk->sk_max_ack_backlog);
873873
}
874874

875875
/*

net/dccp/proto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ int inet_dccp_listen(struct socket *sock, int backlog)
944944
if (!((1 << old_state) & (DCCPF_CLOSED | DCCPF_LISTEN)))
945945
goto out;
946946

947-
sk->sk_max_ack_backlog = backlog;
947+
WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
948948
/* Really, if the socket is already in listen state
949949
* we can only allow the backlog to be adjusted.
950950
*/

net/ipv4/af_inet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ int inet_listen(struct socket *sock, int backlog)
208208
if (!((1 << old_state) & (TCPF_CLOSE | TCPF_LISTEN)))
209209
goto out;
210210

211-
sk->sk_max_ack_backlog = backlog;
211+
WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
212212
/* Really, if the socket is already in listen state
213213
* we can only allow the backlog to be adjusted.
214214
*/

net/ipv4/inet_connection_sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ static void reqsk_timer_handler(struct timer_list *t)
716716
* ones are about to clog our table.
717717
*/
718718
qlen = reqsk_queue_len(queue);
719-
if ((qlen << 1) > max(8U, sk_listener->sk_max_ack_backlog)) {
719+
if ((qlen << 1) > max(8U, READ_ONCE(sk_listener->sk_max_ack_backlog))) {
720720
int young = reqsk_queue_len_young(queue) << 1;
721721

722722
while (thresh > 2) {

net/ipv4/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3226,7 +3226,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
32263226
* tcpi_sacked -> max backlog
32273227
*/
32283228
info->tcpi_unacked = READ_ONCE(sk->sk_ack_backlog);
3229-
info->tcpi_sacked = sk->sk_max_ack_backlog;
3229+
info->tcpi_sacked = READ_ONCE(sk->sk_max_ack_backlog);
32303230
return;
32313231
}
32323232

net/ipv4/tcp_diag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
2222

2323
if (inet_sk_state_load(sk) == TCP_LISTEN) {
2424
r->idiag_rqueue = READ_ONCE(sk->sk_ack_backlog);
25-
r->idiag_wqueue = sk->sk_max_ack_backlog;
25+
r->idiag_wqueue = READ_ONCE(sk->sk_max_ack_backlog);
2626
} else if (sk->sk_type == SOCK_STREAM) {
2727
const struct tcp_sock *tp = tcp_sk(sk);
2828

net/sched/em_meta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ META_COLLECTOR(int_sk_max_ack_bl)
532532
*err = -1;
533533
return;
534534
}
535-
dst->value = sk->sk_max_ack_backlog;
535+
dst->value = READ_ONCE(sk->sk_max_ack_backlog);
536536
}
537537

538538
META_COLLECTOR(int_sk_prio)

net/sctp/diag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static void sctp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
426426
r->idiag_wqueue = infox->asoc->sndbuf_used;
427427
} else {
428428
r->idiag_rqueue = READ_ONCE(sk->sk_ack_backlog);
429-
r->idiag_wqueue = sk->sk_max_ack_backlog;
429+
r->idiag_wqueue = READ_ONCE(sk->sk_max_ack_backlog);
430430
}
431431
if (infox->sctpinfo)
432432
sctp_get_sctp_info(sk, infox->asoc, infox->sctpinfo);

net/sctp/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8376,7 +8376,7 @@ static int sctp_listen_start(struct sock *sk, int backlog)
83768376
}
83778377
}
83788378

8379-
sk->sk_max_ack_backlog = backlog;
8379+
WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
83808380
return sctp_hash_endpoint(ep);
83818381
}
83828382

@@ -8430,7 +8430,7 @@ int sctp_inet_listen(struct socket *sock, int backlog)
84308430

84318431
/* If we are already listening, just update the backlog */
84328432
if (sctp_sstate(sk, LISTENING))
8433-
sk->sk_max_ack_backlog = backlog;
8433+
WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
84348434
else {
84358435
err = sctp_listen_start(sk, backlog);
84368436
if (err)

0 commit comments

Comments
 (0)