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

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

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

We will likely need RCU protection in the future.

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-6-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 ef7f88f018818909cb4662d5f4ea875b3a04361e..60fb5d2faf43e4df812f8a13be6bfff4b3c6b82c 100644 (file)
@@ -464,7 +464,7 @@ INDIRECT_CALLABLE_DECLARE(int ip_output(struct net *, struct sock *,
 /* Output packet to network from transport.  */
 static inline int dst_output(struct net *net, struct sock *sk, struct sk_buff *skb)
 {
-       return INDIRECT_CALL_INET(skb_dst(skb)->output,
+       return INDIRECT_CALL_INET(READ_ONCE(skb_dst(skb)->output),
                                  ip6_output, ip_output,
                                  net, sk, skb);
 }
index a4632a64daae32ee8b4340915412b16f013b787d..09791f5d9b6ec8f06ff093ec1adcbf75e08bed62 100644 (file)
@@ -138,8 +138,8 @@ int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len,
 static inline void lwtunnel_set_redirect(struct dst_entry *dst)
 {
        if (lwtunnel_output_redirect(dst->lwtstate)) {
-               dst->lwtstate->orig_output = dst->output;
-               dst->output = lwtunnel_output;
+               dst->lwtstate->orig_output = READ_ONCE(dst->output);
+               WRITE_ONCE(dst->output, lwtunnel_output);
        }
        if (lwtunnel_input_redirect(dst->lwtstate)) {
                dst->lwtstate->orig_input = READ_ONCE(dst->input);
index def3dbbd37e3f0d8f62e954ef861b88a64a207ba..2513665696f693c723d74b3132a166e3a93b3ba3 100644 (file)
@@ -151,7 +151,7 @@ void dst_dev_put(struct dst_entry *dst)
        if (dst->ops->ifdown)
                dst->ops->ifdown(dst, dev);
        WRITE_ONCE(dst->input, dst_discard);
-       dst->output = dst_discard_out;
+       WRITE_ONCE(dst->output, dst_discard_out);
        dst->dev = blackhole_netdev;
        netdev_ref_replace(dev, blackhole_netdev, &dst->dev_tracker,
                           GFP_ATOMIC);
index f8538507ce3ffcd6dbdfa0d08402904de2777fcc..6ee77f7f911473b46927ca222cd40f48fc54899d 100644 (file)
@@ -1700,7 +1700,7 @@ struct rtable *rt_dst_clone(struct net_device *dev, struct rtable *rt)
                        new_rt->rt_gw6 = rt->rt_gw6;
 
                new_rt->dst.input = READ_ONCE(rt->dst.input);
-               new_rt->dst.output = rt->dst.output;
+               new_rt->dst.output = READ_ONCE(rt->dst.output);
                new_rt->dst.error = rt->dst.error;
                new_rt->dst.lastuse = jiffies;
                new_rt->dst.lwtstate = lwtstate_get(rt->dst.lwtstate);