mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@fomichev.me>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, ayush.sawal@chelsio.com,
	andrew+netdev@lunn.ch, gregkh@linuxfoundation.org,
	horms@kernel.org, dsahern@kernel.org, pablo@netfilter.org,
	kadlec@netfilter.org, steffen.klassert@secunet.com,
	sdf@fomichev.me, mhal@rbox.co, abhishektamboli9@gmail.com,
	linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	herbert@gondor.apana.org.au
Subject: [PATCH net-next 7/7] net: Add skb_dst_check_unset
Date: Tue, 12 Aug 2025 08:52:45 -0700	[thread overview]
Message-ID: <20250812155245.507012-8-sdf@fomichev.me> (raw)
In-Reply-To: <20250812155245.507012-1-sdf@fomichev.me>

To prevent dst_entry leaks, add warning when the non-NULL dst_entry
is rewritten.

Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
---
 include/linux/skbuff.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 8240e0826204..2f9dac54d627 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_unset(struct sk_buff *skb)
+{
+	DEBUG_NET_WARN_ON_ONCE((skb->_skb_refdst & SKB_DST_PTRMASK) &&
+			       !(skb->_skb_refdst & SKB_DST_NOREF));
+}
+
 /**
  * skb_dst_reset() - return current dst_entry value and clear it
  * @skb: buffer
@@ -1187,6 +1193,7 @@ static inline unsigned long skb_dst_reset(struct sk_buff *skb)
  */
 static inline void skb_dst_restore(struct sk_buff *skb, unsigned long refdst)
 {
+	skb_dst_check_unset(skb);
 	skb->_skb_refdst = refdst;
 }
 
@@ -1200,6 +1207,7 @@ static inline void skb_dst_restore(struct sk_buff *skb, unsigned long refdst)
  */
 static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst)
 {
+	skb_dst_check_unset(skb);
 	skb->slow_gro |= !!dst;
 	skb->_skb_refdst = (unsigned long)dst;
 }
@@ -1216,6 +1224,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_unset(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


  parent reply	other threads:[~2025-08-12 15:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-12 15:52 [PATCH net-next 0/7] net: Convert to skb_dst_reset and skb_dst_restore Stanislav Fomichev
2025-08-12 15:52 ` [PATCH net-next 1/7] net: Add " Stanislav Fomichev
2025-08-14  0:57   ` Jakub Kicinski
2025-08-14  1:03     ` Jakub Kicinski
2025-08-14 15:45       ` Stanislav Fomichev
2025-08-12 15:52 ` [PATCH net-next 2/7] xfrm: Switch to skb_dst_reset to clear dst_entry Stanislav Fomichev
2025-08-12 15:52 ` [PATCH net-next 3/7] netfilter: " Stanislav Fomichev
2025-08-13  6:43   ` Florian Westphal
2025-08-12 15:52 ` [PATCH net-next 4/7] net: Switch to skb_dst_reset/skb_dst_restore for ip_route_input callers Stanislav Fomichev
2025-08-12 15:52 ` [PATCH net-next 5/7] staging: octeon: Convert to skb_dst_drop Stanislav Fomichev
2025-08-13 14:20   ` Greg KH
2025-08-12 15:52 ` [PATCH net-next 6/7] chtls: Convert to skb_dst_reset Stanislav Fomichev
2025-08-12 15:52 ` Stanislav Fomichev [this message]
2025-08-13  7:57 ` [syzbot ci] Re: net: Convert to skb_dst_reset and skb_dst_restore syzbot ci
2025-08-13 10:01   ` Florian Westphal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250812155245.507012-8-sdf@fomichev.me \
    --to=sdf@fomichev.me \
    --cc=abhishektamboli9@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=ayush.sawal@chelsio.com \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=kadlec@netfilter.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mhal@rbox.co \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=steffen.klassert@secunet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®