Add WARN_ON_ONCE with CONFIG_NET_DEBUG to warn on overriding referenced dst entries. This should get a better signal than tracing leaked objects from kmemleak. Signed-off-by: Stanislav Fomichev --- include/linux/skbuff.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 5520524c93bf..c89931ac01e5 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1159,6 +1159,12 @@ static inline struct dst_entry *skb_dst(const struct sk_buff *skb) return (struct dst_entry *)(skb->_skb_refdst & SKB_DST_PTRMASK); } +static inline void skb_dst_check(struct sk_buff *skb) +{ + DEBUG_NET_WARN_ON_ONCE(skb_dst(skb) && + !(skb->_skb_refdst & SKB_DST_NOREF)); +} + /** * skb_dst_set - sets skb dst * @skb: buffer @@ -1169,6 +1175,7 @@ static inline struct dst_entry *skb_dst(const struct sk_buff *skb) */ static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst) { + skb_dst_check(skb); skb->slow_gro |= !!dst; skb->_skb_refdst = (unsigned long)dst; } @@ -1185,6 +1192,7 @@ static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst) */ static inline void skb_dst_set_noref(struct sk_buff *skb, struct dst_entry *dst) { + skb_dst_check(skb); WARN_ON(!rcu_read_lock_held() && !rcu_read_lock_bh_held()); skb->slow_gro |= !!dst; skb->_skb_refdst = (unsigned long)dst | SKB_DST_NOREF; -- 2.50.1