]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: dst: annotate data-races around dst->input
authorEric Dumazet <edumazet@google.com>
Mon, 30 Jun 2025 12:19:28 +0000 (12:19 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Aug 2025 10:08:46 +0000 (12:08 +0200)
[ Upstream commit f1c5fd34891a1c242885f48c2e4dc52df180f311 ]

dst_dev_put() can overwrite dst->input while other
cpus might read this field (for instance from dst_input())

Add READ_ONCE()/WRITE_ONCE() annotations to suppress
potential issues.

We will likely need full RCU protection later.

Fixes: 4a6ce2b6f2ec ("net: introduce a new function dst_dev_put()")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20250630121934.3399505-5-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/dst.h
include/net/lwtunnel.h
net/core/dst.c
net/ipv4/route.c

index 16b7b99b5f309c4e456cd09e5b2137d48c7405a4..ef7f88f018818909cb4662d5f4ea875b3a04361e 100644 (file)
@@ -474,7 +474,7 @@ INDIRECT_CALLABLE_DECLARE(int ip_local_deliver(struct sk_buff *));
 /* Input packet from network to transport.  */
 static inline int dst_input(struct sk_buff *skb)
 {
-       return INDIRECT_CALL_INET(skb_dst(skb)->input,
+       return INDIRECT_CALL_INET(READ_ONCE(skb_dst(skb)->input),
                                  ip6_input, ip_local_deliver, skb);
 }
 
index 53bd2d02a4f0db374b3920386afd12b0d7cbe6a0..a4632a64daae32ee8b4340915412b16f013b787d 100644 (file)
@@ -142,8 +142,8 @@ static inline void lwtunnel_set_redirect(struct dst_entry *dst)
                dst->output = lwtunnel_output;
        }
        if (lwtunnel_input_redirect(dst->lwtstate)) {
-               dst->lwtstate->orig_input = dst->input;
-               dst->input = lwtunnel_input;
+               dst->lwtstate->orig_input = READ_ONCE(dst->input);
+               WRITE_ONCE(dst->input, lwtunnel_input);
        }
 }
 #else
index aad197e761cb4c92d79a330c9849dcf980bf5dca..def3dbbd37e3f0d8f62e954ef861b88a64a207ba 100644 (file)
@@ -150,7 +150,7 @@ void dst_dev_put(struct dst_entry *dst)
        dst->obsolete = DST_OBSOLETE_DEAD;
        if (dst->ops->ifdown)
                dst->ops->ifdown(dst, dev);
-       dst->input = dst_discard;
+       WRITE_ONCE(dst->input, dst_discard);
        dst->output = dst_discard_out;
        dst->dev = blackhole_netdev;
        netdev_ref_replace(dev, blackhole_netdev, &dst->dev_tracker,
index 8ee1ad2d8c13f63de1193f59d68eff1fb596e249..f8538507ce3ffcd6dbdfa0d08402904de2777fcc 100644 (file)
@@ -1699,7 +1699,7 @@ struct rtable *rt_dst_clone(struct net_device *dev, struct rtable *rt)
                else if (rt->rt_gw_family == AF_INET6)
                        new_rt->rt_gw6 = rt->rt_gw6;
 
-               new_rt->dst.input = rt->dst.input;
+               new_rt->dst.input = READ_ONCE(rt->dst.input);
                new_rt->dst.output = rt->dst.output;
                new_rt->dst.error = rt->dst.error;
                new_rt->dst.lastuse = jiffies;