[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aID8FaYlyuVjeOH_@mini-arch>
Date: Wed, 23 Jul 2025 08:13:25 -0700
From: Stanislav Fomichev <stfomichev@...il.com>
To: Jakub Kicinski <kuba@...nel.org>
Cc: Stanislav Fomichev <sdf@...ichev.me>, netdev@...r.kernel.org,
davem@...emloft.net, edumazet@...gle.com, pabeni@...hat.com,
dsahern@...nel.org, andrew+netdev@...n.ch, horms@...nel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH net 2/2] net: Warn when overriding referenced dst entry
On 07/22, Jakub Kicinski wrote:
> On Tue, 22 Jul 2025 14:02:56 -0700 Stanislav Fomichev wrote:
> > 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.
>
> Looks like we're tripping the severe nastiness in icmp.c:
>
> /* Ugh! */
> orefdst = skb_in->_skb_refdst; /* save old refdst */
> skb_dst_set(skb_in, NULL);
> err = ip_route_input(skb_in, fl4_dec.daddr, fl4_dec.saddr,
> dscp, rt2->dst.dev) ? -EINVAL : 0;
>
> dst_release(&rt2->dst);
> rt2 = skb_rtable(skb_in);
> skb_in->_skb_refdst = orefdst; /* restore old refdst */
>
> There's more of these around. I think we need a new helper for
> "saving" and "restoring" the refdst? Either way, I reckon the
> patch with the check belongs in net-next.
SG, will run all tests locally and try to weed these out before
reposting for net-next.
> > 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)
>
> skb_dst_check_unset() ? Right now we assume the caller will override.
> Or will there be more conditions added?
skb_dst_check_unset sounds good. I was not planning to add more checks.
> > +{
> > + DEBUG_NET_WARN_ON_ONCE(skb_dst(skb) &&
> > + !(skb->_skb_refdst & SKB_DST_NOREF));
>
> Why not
>
> DEBUG_NET_WARN_ON_ONCE(skb->_skb_refdst & SKB_DST_PTRMASK);
>
> ?
That's more precise, agreed!
Powered by blists - more mailing lists