Skip to content

Commit 484b16d

Browse files
edumazetopsiff
authored andcommitted
inet_diag: annotate data-races in inet_diag_bc_sk()
[ Upstream commit 4fd84a0 ] 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]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 296357dcdc4b5860210857e15460c97dae69987c)
1 parent 120bb6c commit 484b16d

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
@@ -783,7 +783,7 @@ static void entry_fill_addrs(struct inet_diag_entry *entry,
783783
const struct sock *sk)
784784
{
785785
#if IS_ENABLED(CONFIG_IPV6)
786-
if (sk->sk_family == AF_INET6) {
786+
if (entry->family == AF_INET6) {
787787
entry->saddr = sk->sk_v6_rcv_saddr.s6_addr32;
788788
entry->daddr = sk->sk_v6_daddr.s6_addr32;
789789
} else
@@ -796,18 +796,18 @@ static void entry_fill_addrs(struct inet_diag_entry *entry,
796796

797797
int inet_diag_bc_sk(const struct nlattr *bc, struct sock *sk)
798798
{
799-
struct inet_sock *inet = inet_sk(sk);
799+
const struct inet_sock *inet = inet_sk(sk);
800800
struct inet_diag_entry entry;
801801

802802
if (!bc)
803803
return 1;
804804

805-
entry.family = sk->sk_family;
805+
entry.family = READ_ONCE(sk->sk_family);
806806
entry_fill_addrs(&entry, sk);
807-
entry.sport = inet->inet_num;
808-
entry.dport = ntohs(inet->inet_dport);
809-
entry.ifindex = sk->sk_bound_dev_if;
810-
entry.userlocks = sk_fullsock(sk) ? sk->sk_userlocks : 0;
807+
entry.sport = READ_ONCE(inet->inet_num);
808+
entry.dport = ntohs(READ_ONCE(inet->inet_dport));
809+
entry.ifindex = READ_ONCE(sk->sk_bound_dev_if);
810+
entry.userlocks = sk_fullsock(sk) ? READ_ONCE(sk->sk_userlocks) : 0;
811811
if (sk_fullsock(sk))
812812
entry.mark = READ_ONCE(sk->sk_mark);
813813
else if (sk->sk_state == TCP_NEW_SYN_RECV)

0 commit comments

Comments
 (0)