From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: David Ahern <dsahern@kernel.org>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next 12/14] ipv6: lockless IPV6_ROUTER_ALERT_ISOLATE implementation
Date: Tue, 12 Sep 2023 16:02:10 +0000 [thread overview]
Message-ID: <20230912160212.3467976-13-edumazet@google.com> (raw)
In-Reply-To: <20230912160212.3467976-1-edumazet@google.com>
Reads from np->rtalert_isolate are racy.
Move this flag to inet->inet_flags to fix data-races.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
include/linux/ipv6.h | 3 +--
include/net/inet_sock.h | 1 +
net/ipv6/ip6_output.c | 3 +--
net/ipv6/ipv6_sockglue.c | 13 ++++++-------
4 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
index e62413371ea40cbd9f13aa6ac6b6be41a6831237..f288a35f157f73ded445639c30f3365047fd9ddc 100644
--- a/include/linux/ipv6.h
+++ b/include/linux/ipv6.h
@@ -246,11 +246,10 @@ struct ipv6_pinfo {
__u16 sndflow:1,
pmtudisc:3,
padding:1, /* 1 bit hole */
- srcprefs:3, /* 001: prefer temporary address
+ srcprefs:3; /* 001: prefer temporary address
* 010: prefer public address
* 100: prefer care-of address
*/
- rtalert_isolate:1;
__u8 min_hopcount;
__u8 tclass;
__be32 rcv_flowinfo;
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index 5d61c7dc6577827740254f0e9aa288065f1bda7f..befee0f66c0555f3ac4524fd8f7780ff21c04aaa 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -276,6 +276,7 @@ enum {
INET_FLAGS_DONTFRAG = 25,
INET_FLAGS_RECVERR6 = 26,
INET_FLAGS_REPFLOW = 27,
+ INET_FLAGS_RTALERT_ISOLATE = 28,
};
/* cmsg flags for inet */
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 8851fe5d45a0781c8b78c995c2c4c6c81e10cd52..f87d8491d7e273f167b7b144a7e134783e1b80f6 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -368,9 +368,8 @@ static int ip6_call_ra_chain(struct sk_buff *skb, int sel)
if (sk && ra->sel == sel &&
(!sk->sk_bound_dev_if ||
sk->sk_bound_dev_if == skb->dev->ifindex)) {
- struct ipv6_pinfo *np = inet6_sk(sk);
- if (np && np->rtalert_isolate &&
+ if (inet6_test_bit(RTALERT_ISOLATE, sk) &&
!net_eq(sock_net(sk), dev_net(skb->dev))) {
continue;
}
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index ec10b45c49c15f9655466a529046f741f8b9fc69..c22a492e05360b68ef6868707e363f2ce84a4c35 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -488,6 +488,11 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
if (!val)
skb_errqueue_purge(&sk->sk_error_queue);
return 0;
+ case IPV6_ROUTER_ALERT_ISOLATE:
+ if (optlen < sizeof(int))
+ return -EINVAL;
+ inet6_assign_bit(RTALERT_ISOLATE, sk, valbool);
+ return 0;
}
if (needs_rtnl)
rtnl_lock();
@@ -936,12 +941,6 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
goto e_inval;
retv = ip6_ra_control(sk, val);
break;
- case IPV6_ROUTER_ALERT_ISOLATE:
- if (optlen < sizeof(int))
- goto e_inval;
- np->rtalert_isolate = valbool;
- retv = 0;
- break;
case IPV6_MTU_DISCOVER:
if (optlen < sizeof(int))
goto e_inval;
@@ -1452,7 +1451,7 @@ int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
break;
case IPV6_ROUTER_ALERT_ISOLATE:
- val = np->rtalert_isolate;
+ val = inet6_test_bit(RTALERT_ISOLATE, sk);
break;
case IPV6_RECVERR_RFC4884:
--
2.42.0.283.g2d96d420d3-goog
next prev parent reply other threads:[~2023-09-12 16:02 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-12 16:01 [PATCH net-next 00/14] ipv6: round of data-races fixes Eric Dumazet
2023-09-12 16:01 ` [PATCH net-next 01/14] ipv6: lockless IPV6_UNICAST_HOPS implementation Eric Dumazet
2023-09-14 14:51 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 02/14] ipv6: lockless IPV6_MULTICAST_LOOP implementation Eric Dumazet
2023-09-14 14:54 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 03/14] ipv6: lockless IPV6_MULTICAST_HOPS implementation Eric Dumazet
2023-09-14 14:55 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 04/14] ipv6: lockless IPV6_MTU implementation Eric Dumazet
2023-09-14 14:58 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 05/14] ipv6: lockless IPV6_MINHOPCOUNT implementation Eric Dumazet
2023-09-14 15:01 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 06/14] ipv6: lockless IPV6_RECVERR_RFC4884 implementation Eric Dumazet
2023-09-14 15:02 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 07/14] ipv6: lockless IPV6_MULTICAST_ALL implementation Eric Dumazet
2023-09-14 15:03 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 08/14] ipv6: lockless IPV6_AUTOFLOWLABEL implementation Eric Dumazet
2023-09-14 15:04 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 09/14] ipv6: lockless IPV6_DONTFRAG implementation Eric Dumazet
2023-09-14 15:05 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 10/14] ipv6: lockless IPV6_RECVERR implemetation Eric Dumazet
2023-09-14 15:06 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 11/14] ipv6: move np->repflow to atomic flags Eric Dumazet
2023-09-14 15:07 ` David Ahern
2023-09-12 16:02 ` Eric Dumazet [this message]
2023-09-14 15:08 ` [PATCH net-next 12/14] ipv6: lockless IPV6_ROUTER_ALERT_ISOLATE implementation David Ahern
2023-09-12 16:02 ` [PATCH net-next 13/14] ipv6: lockless IPV6_MTU_DISCOVER implementation Eric Dumazet
2023-09-14 15:10 ` David Ahern
2023-09-12 16:02 ` [PATCH net-next 14/14] ipv6: lockless IPV6_FLOWINFO_SEND implementation Eric Dumazet
2023-09-14 15:11 ` David Ahern
2023-09-14 10:25 ` [PATCH net-next 00/14] ipv6: round of data-races fixes Simon Horman
2023-09-15 9:40 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230912160212.3467976-13-edumazet@google.com \
--to=edumazet@google.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=eric.dumazet@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).