Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B826D347DF for ; Fri, 8 Dec 2023 16:06:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OIPwRceU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3FDBC433C8; Fri, 8 Dec 2023 16:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702051604; bh=6yqhLJTH7cwdGu7GCwuCX26R5k/m2WdF4DPqxvwFoc4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=OIPwRceUaptuNjQBbl4odDYy8M743FBjDLIL9GcofoZY++eZZzdx1CkcKhQZylBva newygO4IW0RMIBnPClgB4lze5NpRwXleqVsrZd0y0sf89MI9IEJLkioFY5KOPJT8Gd thh1XVB7ZTobVaqTimPHYzhAR6efOm4K4yNZy9Ohw1E6ybfe5z58z+MXXSq3Dul1R9 4Ux79+YU9iFuU6NSAZitzMobuKpAEHvh4U6mwXreuGIdO72HCbJtXBpjEDxKh09ZdU XEMsgqqlTZ0BmVuF8d0ZKeRbWKgtofC+j5WTsC/jcfObrIqgyLDzjKHvexaE5kMXIC x8OU9lpmasY/w== Message-ID: Date: Fri, 8 Dec 2023 09:06:43 -0700 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next 1/2] ipv6: annotate data-races around np->mcast_oif Content-Language: en-US To: Eric Dumazet , "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com References: <20231208101244.1019034-1-edumazet@google.com> <20231208101244.1019034-2-edumazet@google.com> From: David Ahern In-Reply-To: <20231208101244.1019034-2-edumazet@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/8/23 3:12 AM, Eric Dumazet wrote: > np->mcast_oif is read locklessly in some contexts. > > Make all accesses to this field lockless, adding appropriate > annotations. > > This also makes setsockopt( IPV6_MULTICAST_IF ) lockless. > > Signed-off-by: Eric Dumazet > --- > net/dccp/ipv6.c | 2 +- > net/ipv6/datagram.c | 4 +- > net/ipv6/icmp.c | 4 +- > net/ipv6/ipv6_sockglue.c | 74 +++++++++++++++++---------------- > net/ipv6/ping.c | 4 +- > net/ipv6/raw.c | 2 +- > net/ipv6/tcp_ipv6.c | 2 +- > net/ipv6/udp.c | 2 +- > net/l2tp/l2tp_ip6.c | 2 +- > net/netfilter/ipvs/ip_vs_sync.c | 2 +- > net/rds/tcp_listen.c | 2 +- > 11 files changed, 51 insertions(+), 49 deletions(-) > > diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c > index 7d661735cb9d519ab4691979f30365acda0a28c3..fe7e96e69960c013e84b48242e309525f7f618da 100644 > --- a/net/ipv6/ipv6_sockglue.c > +++ b/net/ipv6/ipv6_sockglue.c > @@ -509,6 +509,34 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname, > if (optlen < sizeof(int)) > return -EINVAL; > return ip6_sock_set_addr_preferences(sk, val); > + case IPV6_MULTICAST_IF: > + if (sk->sk_type == SOCK_STREAM) > + return -ENOPROTOOPT; > + if (optlen < sizeof(int)) > + return -EINVAL; > + if (val) { > + struct net_device *dev; > + int bound_dev_if, midx; > + > + rcu_read_lock(); > + > + dev = dev_get_by_index_rcu(net, val); > + if (!dev) { > + rcu_read_unlock(); > + return -ENODEV; > + } > + midx = l3mdev_master_ifindex_rcu(dev); > + > + rcu_read_unlock(); > + > + bound_dev_if = READ_ONCE(sk->sk_bound_dev_if); you snuck in an extra change with that code move. Reviewed-by: David Ahern > + if (bound_dev_if && > + bound_dev_if != val && > + (!midx || midx != bound_dev_if)) > + return -EINVAL; > + } > + WRITE_ONCE(np->mcast_oif, val); > + return 0; > } > if (needs_rtnl) > rtnl_lock(); > @@ -860,36 +888,6 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname, > break; > } > > - case IPV6_MULTICAST_IF: > - if (sk->sk_type == SOCK_STREAM) > - break; > - if (optlen < sizeof(int)) > - goto e_inval; > - > - if (val) { > - struct net_device *dev; > - int midx; > - > - rcu_read_lock(); > - > - dev = dev_get_by_index_rcu(net, val); > - if (!dev) { > - rcu_read_unlock(); > - retv = -ENODEV; > - break; > - } > - midx = l3mdev_master_ifindex_rcu(dev); > - > - rcu_read_unlock(); > - > - if (sk->sk_bound_dev_if && > - sk->sk_bound_dev_if != val && > - (!midx || midx != sk->sk_bound_dev_if)) > - goto e_inval; > - } > - np->mcast_oif = val; > - retv = 0; > - break; > case IPV6_ADD_MEMBERSHIP: > case IPV6_DROP_MEMBERSHIP: > {