Skip to content

Commit 4fd84a0

Browse files
edumazetkuba-moo
authored andcommitted
inet_diag: annotate data-races in inet_diag_bc_sk()
inet_diag_bc_sk() runs with an unlocked socket, annotate potential races with READ_ONCE(). Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8e60447 commit 4fd84a0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

net/ipv4/inet_diag.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static void entry_fill_addrs(struct inet_diag_entry *entry,
580580
const struct sock *sk)
581581
{
582582
#if IS_ENABLED(CONFIG_IPV6)
583-
if (sk->sk_family == AF_INET6) {
583+
if (entry->family == AF_INET6) {
584584
entry->saddr = sk->sk_v6_rcv_saddr.s6_addr32;
585585
entry->daddr = sk->sk_v6_daddr.s6_addr32;
586586
} else
@@ -593,18 +593,18 @@ static void entry_fill_addrs(struct inet_diag_entry *entry,
593593

594594
int inet_diag_bc_sk(const struct nlattr *bc, struct sock *sk)
595595
{
596-
struct inet_sock *inet = inet_sk(sk);
596+
const struct inet_sock *inet = inet_sk(sk);
597597
struct inet_diag_entry entry;
598598

599599
if (!bc)
600600
return 1;
601601

602-
entry.family = sk->sk_family;
602+
entry.family = READ_ONCE(sk->sk_family);
603603
entry_fill_addrs(&entry, sk);
604-
entry.sport = inet->inet_num;
605-
entry.dport = ntohs(inet->inet_dport);
606-
entry.ifindex = sk->sk_bound_dev_if;
607-
entry.userlocks = sk_fullsock(sk) ? sk->sk_userlocks : 0;
604+
entry.sport = READ_ONCE(inet->inet_num);
605+
entry.dport = ntohs(READ_ONCE(inet->inet_dport));
606+
entry.ifindex = READ_ONCE(sk->sk_bound_dev_if);
607+
entry.userlocks = sk_fullsock(sk) ? READ_ONCE(sk->sk_userlocks) : 0;
608608
if (sk_fullsock(sk))
609609
entry.mark = READ_ONCE(sk->sk_mark);
610610
else if (sk->sk_state == TCP_NEW_SYN_RECV)

0 commit comments

Comments
 (0)