ipv6: more data-race annotations
Subsystems (8)
cover ipv6: more data-race annotations
Small follow up series, taking care of races around np->mcast_oif and np->ucast_oif.
Eric Dumazet (2):
ipv6: annotate data-races around np->mcast_oif
ipv6: annotate data-races around np->ucast_oif
net/dccp/ipv6.c | 2 +- net/ipv6/datagram.c | 6 +- net/ipv6/icmp.c | 8 +- net/ipv6/ipv6_sockglue.c | 132 ++++++++++++++++---------------- net/ipv6/ping.c | 8 +- net/ipv6/raw.c | 4 +- net/ipv6/tcp_ipv6.c | 2 +- net/ipv6/udp.c | 4 +- net/l2tp/l2tp_ip6.c | 4 +- net/netfilter/ipvs/ip_vs_sync.c | 2 +- net/rds/tcp_listen.c | 2 +- 11 files changed, 85 insertions(+), 89 deletions(-)
Signature · 1 line
2.43.0.472.g3155946c3a-goog
PATCH 1/2 ipv6: annotate data-races around np->mcast_oif
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.
--- 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(-)
net/dccp/ipv6.c +1 -1
@@ -669,7 +669,7 @@ static int dccp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) ipv6_pktoptions:if (!((1 << sk->sk_state) & (DCCPF_CLOSED |DCCPF_LISTEN ))) {if (np->rxopt.bits.rxinfo || np->rxopt.bits.rxoinfo) - np->mcast_oif =inet6_iif (opt_skb); +WRITE_ONCE (np->mcast_oif,inet6_iif (opt_skb));if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)WRITE_ONCE (np->mcast_hops,ipv6_hdr (opt_skb)->hop_limit);if (np->rxopt.bits.rxflow || np->rxopt.bits.rxtclass)
net/ipv6/datagram.c +2 -2
@@ -60,7 +60,7 @@ static void ip6_datagram_flow_key_init(struct flowi6 *fl6,if (!oif) {if (ipv6_addr_is_multicast (&fl6->daddr)) - oif = np->mcast_oif; + oif =READ_ONCE (np->mcast_oif);else oif = np->ucast_oif; }
@@ -229,7 +229,7 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, }if (!sk->sk_bound_dev_if && (addr_type &IPV6_ADDR_MULTICAST )) -WRITE_ONCE (sk->sk_bound_dev_if, np->mcast_oif); +WRITE_ONCE (sk->sk_bound_dev_if,READ_ONCE (np->mcast_oif));/* Connect to link-local address requires an interface */ if (!sk->sk_bound_dev_if) {
net/ipv6/icmp.c +2 -2
@@ -584,7 +584,7 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, tmp_hdr.icmp6_pointer =htonl (info);if (!fl6.flowi6_oif &&ipv6_addr_is_multicast (&fl6.daddr)) - fl6.flowi6_oif = np->mcast_oif; + fl6.flowi6_oif =READ_ONCE (np->mcast_oif);else if (!fl6.flowi6_oif) fl6.flowi6_oif = np->ucast_oif;
@@ -770,7 +770,7 @@ static enum skb_drop_reason icmpv6_echo_reply(struct sk_buff *skb) np =inet6_sk (sk);if (!fl6.flowi6_oif &&ipv6_addr_is_multicast (&fl6.daddr)) - fl6.flowi6_oif = np->mcast_oif; + fl6.flowi6_oif =READ_ONCE (np->mcast_oif);else if (!fl6.flowi6_oif) fl6.flowi6_oif = np->ucast_oif;
net/ipv6/ipv6_sockglue.c +38 -36
108 lines not on this page · raw message
net/ipv6/ping.c +2 -2
@@ -107,7 +107,7 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) oif = np->sticky_pktinfo.ipi6_ifindex;if (!oif &&ipv6_addr_is_multicast (daddr)) - oif = np->mcast_oif; + oif =READ_ONCE (np->mcast_oif);else if (!oif) oif = np->ucast_oif;
@@ -157,7 +157,7 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) rt = (struct rt6_info *) dst;if (!fl6.flowi6_oif &&ipv6_addr_is_multicast (&fl6.daddr)) - fl6.flowi6_oif = np->mcast_oif; + fl6.flowi6_oif =READ_ONCE (np->mcast_oif);else if (!fl6.flowi6_oif) fl6.flowi6_oif = np->ucast_oif;
net/ipv6/raw.c +1 -1
@@ -876,7 +876,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) final_p =fl6_update_dst (&fl6, opt, &final);if (!fl6.flowi6_oif &&ipv6_addr_is_multicast (&fl6.daddr)) - fl6.flowi6_oif = np->mcast_oif; + fl6.flowi6_oif =READ_ONCE (np->mcast_oif);else if (!fl6.flowi6_oif) fl6.flowi6_oif = np->ucast_oif;security_sk_classify_flow (sk,flowi6_to_flowi_common (&fl6));
net/ipv6/tcp_ipv6.c +1 -1
@@ -1702,7 +1702,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)if (TCP_SKB_CB (opt_skb)->end_seq == tp->rcv_nxt && !((1 << sk->sk_state) & (TCPF_CLOSE |TCPF_LISTEN ))) {if (np->rxopt.bits.rxinfo || np->rxopt.bits.rxoinfo) - np->mcast_oif =tcp_v6_iif (opt_skb); +WRITE_ONCE (np->mcast_oif,tcp_v6_iif (opt_skb));if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)WRITE_ONCE (np->mcast_hops,ipv6_hdr (opt_skb)->hop_limit);
net/ipv6/udp.c +1 -1
@@ -1541,7 +1541,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) connected = false;if (!fl6->flowi6_oif &&ipv6_addr_is_multicast (&fl6->daddr)) { - fl6->flowi6_oif = np->mcast_oif; + fl6->flowi6_oif =READ_ONCE (np->mcast_oif); connected = false; }else if (!fl6->flowi6_oif) fl6->flowi6_oif = np->ucast_oif;
net/l2tp/l2tp_ip6.c +1 -1
@@ -599,7 +599,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) final_p =fl6_update_dst (&fl6, opt, &final);if (!fl6.flowi6_oif &&ipv6_addr_is_multicast (&fl6.daddr)) - fl6.flowi6_oif = np->mcast_oif; + fl6.flowi6_oif =READ_ONCE (np->mcast_oif);else if (!fl6.flowi6_oif) fl6.flowi6_oif = np->ucast_oif;
net/netfilter/ipvs/ip_vs_sync.c +1 -1
@@ -1365,7 +1365,7 @@ static int set_mcast_if(struct sock *sk, struct net_device *dev)struct ipv6_pinfo *np =inet6_sk (sk);/* IPV6_MULTICAST_IF */ - np->mcast_oif = dev->ifindex; + WRITE_ONCE(np->mcast_oif, dev->ifindex); }#endif release_sock (sk);
net/rds/tcp_listen.c +1 -1
@@ -165,7 +165,7 @@ int rds_tcp_accept_one(struct socket *sock)struct ipv6_pinfo *inet6; inet6 =inet6_sk (new_sock->sk); - dev_if = inet6->mcast_oif; + dev_if =READ_ONCE (inet6->mcast_oif); }else { dev_if = new_sock->sk->sk_bound_dev_if; }
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH net-next 1/2] ipv6: annotate data-races around np->mcast_oif
Quoted 43 lines · Eric Dumazet
np->mcast_oifis 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 <[email protected]>--- 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(-)net/ipv6/ipv6_sockglue.c +11
-0@@ -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 (); +
net/ipv6/ipv6_sockglue.c int do_ipv6_setsockopt(struct sock *sk, int level, int optname, · line 532
Quoted 10 lines
net/ipv6/ipv6_sockglue.c +10
-0+ 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.
Quoted 47 lines
net/ipv6/ipv6_sockglue.c +7
-30+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 : {
PATCH 2/2 ipv6: annotate data-races around np->ucast_oif
In reply to Eric Dumazetnp->ucast_oif is read locklessly in some contexts.
Make all accesses to this field lockless, adding appropriate annotations.
This also makes setsockopt( IPV6_UNICAST_IF ) lockless.
--- net/ipv6/datagram.c | 2 +- net/ipv6/icmp.c | 4 +-- net/ipv6/ipv6_sockglue.c | 58 ++++++++++++++++++---------------------- net/ipv6/ping.c | 4 +-- net/ipv6/raw.c | 2 +- net/ipv6/udp.c | 2 +- net/l2tp/l2tp_ip6.c | 2 +- 7 files changed, 34 insertions(+), 40 deletions(-)
net/ipv6/datagram.c +1 -1
@@ -62,7 +62,7 @@ static void ip6_datagram_flow_key_init(struct flowi6 *fl6,if (ipv6_addr_is_multicast (&fl6->daddr)) oif =READ_ONCE (np->mcast_oif);else - oif = np->ucast_oif; + oif =READ_ONCE (np->ucast_oif); } fl6->flowi6_oif = oif;
net/ipv6/icmp.c +2 -2
@@ -586,7 +586,7 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,if (!fl6.flowi6_oif &&ipv6_addr_is_multicast (&fl6.daddr)) fl6.flowi6_oif =READ_ONCE (np->mcast_oif);else if (!fl6.flowi6_oif) - fl6.flowi6_oif = np->ucast_oif; + fl6.flowi6_oif =READ_ONCE (np->ucast_oif);ipcm6_init_sk (&ipc6, sk); ipc6.sockc.mark = mark;
@@ -772,7 +772,7 @@ static enum skb_drop_reason icmpv6_echo_reply(struct sk_buff *skb)if (!fl6.flowi6_oif &&ipv6_addr_is_multicast (&fl6.daddr)) fl6.flowi6_oif =READ_ONCE (np->mcast_oif);else if (!fl6.flowi6_oif) - fl6.flowi6_oif = np->ucast_oif; + fl6.flowi6_oif =READ_ONCE (np->ucast_oif);if (ip6_dst_lookup (net, sk, &dst, &fl6)) goto out;
net/ipv6/ipv6_sockglue.c +26 -32
76 lines not on this page · raw message
net/ipv6/ping.c +2 -2
@@ -109,7 +109,7 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)if (!oif &&ipv6_addr_is_multicast (daddr)) oif =READ_ONCE (np->mcast_oif);else if (!oif) - oif = np->ucast_oif; + oif =READ_ONCE (np->ucast_oif); addr_type =ipv6_addr_type (daddr); if ((__ipv6_addr_needs_scope_id(addr_type) && !oif) ||
@@ -159,7 +159,7 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)if (!fl6.flowi6_oif &&ipv6_addr_is_multicast (&fl6.daddr)) fl6.flowi6_oif =READ_ONCE (np->mcast_oif);else if (!fl6.flowi6_oif) - fl6.flowi6_oif = np->ucast_oif; + fl6.flowi6_oif =READ_ONCE (np->ucast_oif); pfh.icmph.type = user_icmph.icmp6_type; pfh.icmph.code = user_icmph.icmp6_code;
net/ipv6/raw.c +1 -1
@@ -878,7 +878,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)if (!fl6.flowi6_oif &&ipv6_addr_is_multicast (&fl6.daddr)) fl6.flowi6_oif =READ_ONCE (np->mcast_oif);else if (!fl6.flowi6_oif) - fl6.flowi6_oif = np->ucast_oif; + fl6.flowi6_oif =READ_ONCE (np->ucast_oif);security_sk_classify_flow (sk,flowi6_to_flowi_common (&fl6));if (hdrincl)
net/ipv6/udp.c +1 -1
@@ -1544,7 +1544,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6->flowi6_oif =READ_ONCE (np->mcast_oif); connected = false; }else if (!fl6->flowi6_oif) - fl6->flowi6_oif = np->ucast_oif; + fl6->flowi6_oif =READ_ONCE (np->ucast_oif);security_sk_classify_flow (sk,flowi6_to_flowi_common (fl6));
net/l2tp/l2tp_ip6.c +1 -1
@@ -601,7 +601,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)if (!fl6.flowi6_oif &&ipv6_addr_is_multicast (&fl6.daddr)) fl6.flowi6_oif =READ_ONCE (np->mcast_oif);else if (!fl6.flowi6_oif) - fl6.flowi6_oif = np->ucast_oif; + fl6.flowi6_oif =READ_ONCE (np->ucast_oif);security_sk_classify_flow (sk,flowi6_to_flowi_common (&fl6));
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH net-next 2/2] ipv6: annotate data-races around np->ucast_oif
Quoted 8 lines · Eric Dumazet
np->ucast_oifis read locklessly in some contexts.Make all accesses to this field lockless, adding appropriate annotations.
This also makes
setsockopt( IPV6_UNICAST_IF )lockless.Signed-off-by Eric Dumazet <[email protected]>
Quoted 10 lines
--- net/ipv6/datagram.c | 2 +- net/ipv6/icmp.c | 4 +-- net/ipv6/ipv6_sockglue.c | 58 ++++++++++++++++++---------------------- net/ipv6/ping.c | 4 +-- net/ipv6/raw.c | 2 +- net/ipv6/udp.c | 2 +- net/l2tp/l2tp_ip6.c | 2 +- 7 files changed, 34 insertions(+), 40 deletions(-)
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 8 lines · On Fri, 8 Dec 2023 10:12:42 +0000 you wrote:
Small follow up series, taking care of races around
np->mcast_oifandnp->ucast_oif.Eric Dumazet (2):
ipv6: annotate data-races aroundnp->mcast_oif
ipv6: annotate data-races aroundnp->ucast_oif[...]
Here is the summary with links:
- [net-next,1/2] ipv6: annotate data-races around np->mcast_oif
https://git.kernel.org/netdev/net-next/c/d2f011a0bf28 - [net-next,2/2] ipv6: annotate data-races around np->ucast_oif https://git.kernel.org/netdev/net-next/c/1ac13efd614c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html