net: warn if mac header was not set
Subsystems (2)
PATCH 1/1 net: warn if mac header was not set
From: Eric Dumazet <[email protected]>
Make sure skb_mac_header(), skb_mac_offset() and skb_mac_header_len() uses are not fooled if the mac header has not been set.
These checks are enabled if CONFIG_DEBUG_NET=y
This commit will likely expose existing bugs in linux networking stacks.
--- include/linux/skbuff.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
include/linux/skbuff.h +7 -5
@@ -2763,8 +2763,14 @@ 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));return skb->head + skb->mac_header; }
@@ -2775,14 +2781,10 @@ static inline int skb_mac_offset(const struct sk_buff *skb)static inline u32 skb_mac_header_len (const struct sk_buff *skb) { +DEBUG_NET_WARN_ON_ONCE (!skb_mac_header_was_set (skb));return skb->network_header - skb->mac_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_unset_mac_header (struct sk_buff *skb) { skb->mac_header = (typeof(skb->mac_header))~0U;
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
Paolo Abeni
maintainerHello,
Quoted 34 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
Make sure
skb_mac_header(),skb_mac_offset()andskb_mac_header_len()uses are not fooled if the mac header has not been set.These checks are enabled if
CONFIG_DEBUG_NET=yThis commit will likely expose existing bugs in linux networking stacks.
Signed-off-by Eric Dumazet <[email protected]>--- include/linux/skbuff.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)include/linux/skbuff.h +6
-0@@ -2763,8 +2763,14 @@ 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));return skb->head + skb->mac_header; }
include/linux/skbuff.h static inline int skb_mac_offset(const struct sk_buff *skb) · line 2784
Quoted 4 lines
include/linux/skbuff.h +1
-0@@ -2775,14 +2781,10 @@ static inline int skb_mac_offset(const struct sk_buff *skb)static inline u32 skb_mac_header_len (const struct sk_buff *skb) { +DEBUG_NET_WARN_ON_ONCE (!skb_mac_header_was_set (skb));
The patch LGTM.
I'm wondering if it's worthy adding similar debug checks for network and transport offset (with more patches). e.g. still in skb_mac_header_len():
DEBUG_NET_WARN_ON_ONCE(skb->network_header < skb->mac_header);
Thanks!
Paolo
This patch was applied to netdev/net-next.git (master) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Mon, 20 Jun 2022 02:30:17 -0700 you wrote:
From: Eric Dumazet <[email protected]>
Make sure
skb_mac_header(),skb_mac_offset()andskb_mac_header_len()uses are not fooled if the mac header has not been set.These checks are enabled if
CONFIG_DEBUG_NET=y[...]
Here is the summary with links:
- [net-next] net: warn if mac header was not set
https://git.kernel.org/netdev/net-next/c/f9aefd6b2aa3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html