Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20250828102738.2065992-4-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
4fd84a0a 8e60447f

+7 -7
+7 -7
net/ipv4/inet_diag.c
··· 580 580 const struct sock *sk) 581 581 { 582 582 #if IS_ENABLED(CONFIG_IPV6) 583 - if (sk->sk_family == AF_INET6) { 583 + if (entry->family == AF_INET6) { 584 584 entry->saddr = sk->sk_v6_rcv_saddr.s6_addr32; 585 585 entry->daddr = sk->sk_v6_daddr.s6_addr32; 586 586 } else ··· 593 593 594 594 int inet_diag_bc_sk(const struct nlattr *bc, struct sock *sk) 595 595 { 596 - struct inet_sock *inet = inet_sk(sk); 596 + const struct inet_sock *inet = inet_sk(sk); 597 597 struct inet_diag_entry entry; 598 598 599 599 if (!bc) 600 600 return 1; 601 601 602 - entry.family = sk->sk_family; 602 + entry.family = READ_ONCE(sk->sk_family); 603 603 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; 608 608 if (sk_fullsock(sk)) 609 609 entry.mark = READ_ONCE(sk->sk_mark); 610 610 else if (sk->sk_state == TCP_NEW_SYN_RECV)