diff options
author | Eric Dumazet <edumazet@google.com> | 2024-02-02 09:54:04 +0000 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-02-16 19:10:49 +0100 |
commit | 4a5e31bdd3c1702b520506d9cf8c41085f75c7f2 (patch) | |
tree | b8c2604f17ee73847c096f3e1b47777fb3490790 /net/ipv4 | |
parent | 2109eb2d6aaa449722f1b55c759f3ad48f2fa5b8 (diff) | |
download | linux-stable-4a5e31bdd3c1702b520506d9cf8c41085f75c7f2.tar.gz linux-stable-4a5e31bdd3c1702b520506d9cf8c41085f75c7f2.tar.bz2 linux-stable-4a5e31bdd3c1702b520506d9cf8c41085f75c7f2.zip |
inet: read sk->sk_family once in inet_recv_error()
[ Upstream commit eef00a82c568944f113f2de738156ac591bbd5cd ]
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: f4713a3dfad0 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/af_inet.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 1c58bd72e124..e59962f34caa 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1628,10 +1628,12 @@ EXPORT_SYMBOL(inet_current_timestamp); int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) { - if (sk->sk_family == AF_INET) + unsigned int family = READ_ONCE(sk->sk_family); + + if (family == AF_INET) return ip_recv_error(sk, msg, len, addr_len); #if IS_ENABLED(CONFIG_IPV6) - if (sk->sk_family == AF_INET6) + if (family == AF_INET6) return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len); #endif return -EINVAL; |