Skip to content

Commit eef00a8

Browse files
edumazetdavem330
authored andcommitted
inet: read sk->sk_family once in inet_recv_error()
inet_recv_error() is called without holding the socket lock. IPv6 socket could mutate to IPv4 with IPV6_ADDRFORM socket option and trigger a KCSAN warning. Fixes: f4713a3 ("net-timestamp: make tcp_recvmsg call ipv6_recv_error for AF_INET6 socks") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Willem de Bruijn <willemb@google.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9cae43d commit eef00a8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/ipv4/af_inet.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,10 +1628,12 @@ EXPORT_SYMBOL(inet_current_timestamp);
16281628

16291629
int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
16301630
{
1631-
if (sk->sk_family == AF_INET)
1631+
unsigned int family = READ_ONCE(sk->sk_family);
1632+
1633+
if (family == AF_INET)
16321634
return ip_recv_error(sk, msg, len, addr_len);
16331635
#if IS_ENABLED(CONFIG_IPV6)
1634-
if (sk->sk_family == AF_INET6)
1636+
if (family == AF_INET6)
16351637
return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
16361638
#endif
16371639
return -EINVAL;

0 commit comments

Comments
 (0)