ipv6: annotate data-races around devconf->disable_policy
authorEric Dumazet <edumazet@google.com>
Wed, 28 Feb 2024 13:54:35 +0000 (13:54 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 1 Mar 2024 08:42:32 +0000 (08:42 +0000)
idev->cnf.disable_policy and net->ipv6.devconf_all->disable_policy
can be read locklessly. Add appropriate annotations on reads
and writes.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/addrconf.c
net/ipv6/ip6_output.c
net/ipv6/route.c

index 409aa5d..44340ff 100644 (file)
@@ -6699,7 +6699,7 @@ int addrconf_disable_policy(struct ctl_table *ctl, int *valp, int val)
        if (!rtnl_trylock())
                return restart_syscall();
 
-       *valp = val;
+       WRITE_ONCE(*valp, val);
 
        net = (struct net *)ctl->extra2;
        if (valp == &net->ipv6.devconf_dflt->disable_policy) {
index f08af3f..b9dd3a6 100644 (file)
@@ -513,8 +513,8 @@ int ip6_forward(struct sk_buff *skb)
        if (skb_warn_if_lro(skb))
                goto drop;
 
-       if (!net->ipv6.devconf_all->disable_policy &&
-           (!idev || !idev->cnf.disable_policy) &&
+       if (!READ_ONCE(net->ipv6.devconf_all->disable_policy) &&
+           (!idev || !READ_ONCE(idev->cnf.disable_policy)) &&
            !xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)) {
                __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
                goto drop;
index 1b897c5..a92fcac 100644 (file)
@@ -4584,8 +4584,8 @@ struct fib6_info *addrconf_f6i_alloc(struct net *net,
                f6i->dst_nocount = true;
 
                if (!anycast &&
-                   (net->ipv6.devconf_all->disable_policy ||
-                    idev->cnf.disable_policy))
+                   (READ_ONCE(net->ipv6.devconf_all->disable_policy) ||
+                    READ_ONCE(idev->cnf.disable_policy)))
                        f6i->dst_nopolicy = true;
        }