summaryrefslogtreecommitdiff
path: root/include/net/dst_ops.h
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2024-05-28 11:43:53 +0000
committerJakub Kicinski <kuba@kernel.org>2024-05-29 17:34:49 -0700
commit92f1655aa2b2294d0b49925f3b875a634bd3b59e (patch)
treed4bb375a5cda5ca5a82e3d30a01fc4bbbb616872 /include/net/dst_ops.h
parent068648aab72c9ba7b0597354ef4d81ffaac7b979 (diff)
downloadlwn-92f1655aa2b2294d0b49925f3b875a634bd3b59e.tar.gz
lwn-92f1655aa2b2294d0b49925f3b875a634bd3b59e.zip
net: fix __dst_negative_advice() race
__dst_negative_advice() does not enforce proper RCU rules when sk->dst_cache must be cleared, leading to possible UAF. RCU rules are that we must first clear sk->sk_dst_cache, then call dst_release(old_dst). Note that sk_dst_reset(sk) is implementing this protocol correctly, while __dst_negative_advice() uses the wrong order. Given that ip6_negative_advice() has special logic against RTF_CACHE, this means each of the three ->negative_advice() existing methods must perform the sk_dst_reset() themselves. Note the check against NULL dst is centralized in __dst_negative_advice(), there is no need to duplicate it in various callbacks. Many thanks to Clement Lecigne for tracking this issue. This old bug became visible after the blamed commit, using UDP sockets. Fixes: a87cb3e48ee8 ("net: Facility to report route quality of connected sockets") Reported-by: Clement Lecigne <clecigne@google.com> Diagnosed-by: Clement Lecigne <clecigne@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Tom Herbert <tom@herbertland.com> Reviewed-by: David Ahern <dsahern@kernel.org> Link: https://lore.kernel.org/r/20240528114353.1794151-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'include/net/dst_ops.h')
-rw-r--r--include/net/dst_ops.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/net/dst_ops.h b/include/net/dst_ops.h
index 6d1c8541183d..3a9001a042a5 100644
--- a/include/net/dst_ops.h
+++ b/include/net/dst_ops.h
@@ -24,7 +24,7 @@ struct dst_ops {
void (*destroy)(struct dst_entry *);
void (*ifdown)(struct dst_entry *,
struct net_device *dev);
- struct dst_entry * (*negative_advice)(struct dst_entry *);
+ void (*negative_advice)(struct sock *sk, struct dst_entry *);
void (*link_failure)(struct sk_buff *);
void (*update_pmtu)(struct dst_entry *dst, struct sock *sk,
struct sk_buff *skb, u32 mtu,