Skip to content

Commit f9aefd6

Browse files
edumazetPaolo Abeni
authored andcommitted
net: warn if mac header was not set
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. Signed-off-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 4336487 commit f9aefd6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

include/linux/skbuff.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,8 +2763,14 @@ static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
27632763
skb->network_header += offset;
27642764
}
27652765

2766+
static inline int skb_mac_header_was_set(const struct sk_buff *skb)
2767+
{
2768+
return skb->mac_header != (typeof(skb->mac_header))~0U;
2769+
}
2770+
27662771
static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
27672772
{
2773+
DEBUG_NET_WARN_ON_ONCE(!skb_mac_header_was_set(skb));
27682774
return skb->head + skb->mac_header;
27692775
}
27702776

@@ -2775,14 +2781,10 @@ static inline int skb_mac_offset(const struct sk_buff *skb)
27752781

27762782
static inline u32 skb_mac_header_len(const struct sk_buff *skb)
27772783
{
2784+
DEBUG_NET_WARN_ON_ONCE(!skb_mac_header_was_set(skb));
27782785
return skb->network_header - skb->mac_header;
27792786
}
27802787

2781-
static inline int skb_mac_header_was_set(const struct sk_buff *skb)
2782-
{
2783-
return skb->mac_header != (typeof(skb->mac_header))~0U;
2784-
}
2785-
27862788
static inline void skb_unset_mac_header(struct sk_buff *skb)
27872789
{
27882790
skb->mac_header = (typeof(skb->mac_header))~0U;

0 commit comments

Comments
 (0)