ipv6: lockless IPV6_ROUTER_ALERT_ISOLATE implementation
authorEric Dumazet <edumazet@google.com>
Tue, 12 Sep 2023 16:02:10 +0000 (16:02 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 15 Sep 2023 09:33:48 +0000 (10:33 +0100)
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>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/ipv6.h
include/net/inet_sock.h
net/ipv6/ip6_output.c
net/ipv6/ipv6_sockglue.c

index e62413371ea40cbd9f13aa6ac6b6be41a6831237..f288a35f157f73ded445639c30f3365047fd9ddc 100644 (file)
@@ -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;
index 5d61c7dc6577827740254f0e9aa288065f1bda7f..befee0f66c0555f3ac4524fd8f7780ff21c04aaa 100644 (file)
@@ -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 */
index 8851fe5d45a0781c8b78c995c2c4c6c81e10cd52..f87d8491d7e273f167b7b144a7e134783e1b80f6 100644 (file)
@@ -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;
                        }
index ec10b45c49c15f9655466a529046f741f8b9fc69..c22a492e05360b68ef6868707e363f2ce84a4c35 100644 (file)
@@ -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 @@ done:
                        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: