All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com,
	 Eric Dumazet <edumazet@google.com>,
	En-Wei Wu <en-wei.wu@canonical.com>
Subject: [PATCH net-next 1/7] net: skb_reset_mac_len() must check if mac_header was set
Date: Tue,  5 Nov 2024 17:43:57 +0000	[thread overview]
Message-ID: <20241105174403.850330-2-edumazet@google.com> (raw)
In-Reply-To: <20241105174403.850330-1-edumazet@google.com>

Recent discussions show that skb_reset_mac_len() should be more careful.

We expect the MAC header being set.

If not, clear skb->mac_len and fire a warning for CONFIG_DEBUG_NET=y builds.

If after investigations we find that not having a MAC header was okay,
we can remove the warning.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/netdev/CANn89iJZGH+yEfJxfPWa3Hm7jxb-aeY2Up4HufmLMnVuQXt38A@mail.gmail.com/T/
Cc: En-Wei Wu <en-wei.wu@canonical.com>
---
 include/linux/skbuff.h | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 48f1e0fa2a13619e41dfba40f2593dd61f9b9a06..5d8fefa71cac78d83b9565d9038c319112da1e2d 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2909,9 +2909,19 @@ static inline void skb_reset_inner_headers(struct sk_buff *skb)
 	skb->inner_transport_header = skb->transport_header;
 }
 
+static inline int skb_mac_header_was_set(const struct sk_buff *skb)
+{
+	return skb->mac_header != (typeof(skb->mac_header))~0U;
+}
+
 static inline void skb_reset_mac_len(struct sk_buff *skb)
 {
-	skb->mac_len = skb->network_header - skb->mac_header;
+	if (!skb_mac_header_was_set(skb)) {
+		DEBUG_NET_WARN_ON_ONCE(1);
+		skb->mac_len = 0;
+	} else {
+		skb->mac_len = skb->network_header - skb->mac_header;
+	}
 }
 
 static inline unsigned char *skb_inner_transport_header(const struct sk_buff
@@ -3014,11 +3024,6 @@ static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
 	skb->network_header += offset;
 }
 
-static inline int skb_mac_header_was_set(const struct sk_buff *skb)
-{
-	return skb->mac_header != (typeof(skb->mac_header))~0U;
-}
-
 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
 {
 	DEBUG_NET_WARN_ON_ONCE(!skb_mac_header_was_set(skb));
-- 
2.47.0.199.ga7371fff76-goog


  reply	other threads:[~2024-11-05 17:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05 17:43 [PATCH net-next 0/7] net: add debug checks to skb_reset_xxx_header() Eric Dumazet
2024-11-05 17:43 ` Eric Dumazet [this message]
2024-11-05 17:56   ` [PATCH net-next 1/7] net: skb_reset_mac_len() must check if mac_header was set Joe Damato
2024-11-05 17:43 ` [PATCH net-next 2/7] net: add debug check in skb_reset_inner_transport_header() Eric Dumazet
2024-11-05 17:57   ` Joe Damato
2024-11-05 17:43 ` [PATCH net-next 3/7] net: add debug check in skb_reset_inner_network_header() Eric Dumazet
2024-11-05 17:57   ` Joe Damato
2024-11-05 17:44 ` [PATCH net-next 4/7] net: add debug check in skb_reset_inner_mac_header() Eric Dumazet
2024-11-05 17:58   ` Joe Damato
2024-11-05 17:44 ` [PATCH net-next 5/7] net: add debug check in skb_reset_transport_header() Eric Dumazet
2024-11-05 17:58   ` Joe Damato
2024-11-05 17:44 ` [PATCH net-next 6/7] net: add debug check in skb_reset_network_header() Eric Dumazet
2024-11-05 17:58   ` Joe Damato
2024-11-05 17:44 ` [PATCH net-next 7/7] net: add debug check in skb_reset_mac_header() Eric Dumazet
2024-11-05 17:59   ` Joe Damato
2024-11-06  9:52 ` [PATCH net-next 0/7] net: add debug checks to skb_reset_xxx_header() Xuan Zhuo
2024-11-07  2:00 ` patchwork-bot+netdevbpf

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=20241105174403.850330-2-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=davem@davemloft.net \
    --cc=en-wei.wu@canonical.com \
    --cc=eric.dumazet@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.