Skip to content

Commit b24bfee

Browse files
committed
net: skb_reset_mac_len() must check if mac_header was set
JIRA: https://issues.redhat.com/browse/RHEL-96625 Upstream Status: net-next.git commit 1e4033b commit 1e4033b Author: Eric Dumazet <edumazet@google.com> Date: Tue Nov 5 17:43:57 2024 +0000 net: skb_reset_mac_len() must check if mac_header was set 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> Reviewed-by: Joe Damato <jdamato@fastly.com> Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Link: https://patch.msgid.link/20241105174403.850330-2-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Davide Caratti <dcaratti@redhat.com>
1 parent f683009 commit b24bfee

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

include/linux/skbuff.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,9 +2916,19 @@ static inline void skb_reset_inner_headers(struct sk_buff *skb)
29162916
skb->inner_transport_header = skb->transport_header;
29172917
}
29182918

2919+
static inline int skb_mac_header_was_set(const struct sk_buff *skb)
2920+
{
2921+
return skb->mac_header != (typeof(skb->mac_header))~0U;
2922+
}
2923+
29192924
static inline void skb_reset_mac_len(struct sk_buff *skb)
29202925
{
2921-
skb->mac_len = skb->network_header - skb->mac_header;
2926+
if (!skb_mac_header_was_set(skb)) {
2927+
DEBUG_NET_WARN_ON_ONCE(1);
2928+
skb->mac_len = 0;
2929+
} else {
2930+
skb->mac_len = skb->network_header - skb->mac_header;
2931+
}
29222932
}
29232933

29242934
static inline unsigned char *skb_inner_transport_header(const struct sk_buff
@@ -3021,11 +3031,6 @@ static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
30213031
skb->network_header += offset;
30223032
}
30233033

3024-
static inline int skb_mac_header_was_set(const struct sk_buff *skb)
3025-
{
3026-
return skb->mac_header != (typeof(skb->mac_header))~0U;
3027-
}
3028-
30293034
static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
30303035
{
30313036
DEBUG_NET_WARN_ON_ONCE(!skb_mac_header_was_set(skb));

0 commit comments

Comments
 (0)