Skip to content

Commit 288efe8

Browse files
edumazetdavem330
authored andcommitted
net: annotate lockless accesses to sk->sk_ack_backlog
sk->sk_ack_backlog can be read without any lock being held. 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 7976a11 commit 288efe8

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

include/net/sock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,17 +859,17 @@ static inline gfp_t sk_gfp_mask(const struct sock *sk, gfp_t gfp_mask)
859859

860860
static inline void sk_acceptq_removed(struct sock *sk)
861861
{
862-
sk->sk_ack_backlog--;
862+
WRITE_ONCE(sk->sk_ack_backlog, sk->sk_ack_backlog - 1);
863863
}
864864

865865
static inline void sk_acceptq_added(struct sock *sk)
866866
{
867-
sk->sk_ack_backlog++;
867+
WRITE_ONCE(sk->sk_ack_backlog, sk->sk_ack_backlog + 1);
868868
}
869869

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

875875
/*

net/ipv4/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
32253225
* tcpi_unacked -> Number of children ready for accept()
32263226
* tcpi_sacked -> max backlog
32273227
*/
3228-
info->tcpi_unacked = sk->sk_ack_backlog;
3228+
info->tcpi_unacked = READ_ONCE(sk->sk_ack_backlog);
32293229
info->tcpi_sacked = sk->sk_max_ack_backlog;
32303230
return;
32313231
}

net/ipv4/tcp_diag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
2121
struct tcp_info *info = _info;
2222

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

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2451,7 +2451,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
24512451

24522452
state = inet_sk_state_load(sk);
24532453
if (state == TCP_LISTEN)
2454-
rx_queue = sk->sk_ack_backlog;
2454+
rx_queue = READ_ONCE(sk->sk_ack_backlog);
24552455
else
24562456
/* Because we don't lock the socket,
24572457
* we might find a transient negative value.

net/ipv6/tcp_ipv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
18911891

18921892
state = inet_sk_state_load(sp);
18931893
if (state == TCP_LISTEN)
1894-
rx_queue = sp->sk_ack_backlog;
1894+
rx_queue = READ_ONCE(sp->sk_ack_backlog);
18951895
else
18961896
/* Because we don't lock the socket,
18971897
* we might find a transient negative value.

net/sched/em_meta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ META_COLLECTOR(int_sk_ack_bl)
521521
*err = -1;
522522
return;
523523
}
524-
dst->value = sk->sk_ack_backlog;
524+
dst->value = READ_ONCE(sk->sk_ack_backlog);
525525
}
526526

527527
META_COLLECTOR(int_sk_max_ack_bl)

net/sctp/diag.c

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

0 commit comments

Comments
 (0)