skb_mpls_push() and skb_mpls_pop() expect skb->data at mac header. Check this assumption or we would get wrong mac_header and network_header.
Signed-off-by: Miaohe Lin <linmia...@huawei.com> --- net/core/skbuff.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index e18184ffa9c3..52d2ad54aa97 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5590,6 +5590,7 @@ static void skb_mod_eth_type(struct sk_buff *skb, struct ethhdr *hdr, int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto, int mac_len, bool ethernet) { + int offset = skb->data - skb_mac_header(skb); struct mpls_shim_hdr *lse; int err; @@ -5600,6 +5601,9 @@ int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto, if (skb->encapsulation) return -EINVAL; + if (WARN_ONCE(offset, "We got skb with skb->data not at mac header (offset %d)\n", offset)) + return -EINVAL; + err = skb_cow_head(skb, MPLS_HLEN); if (unlikely(err)) return err; @@ -5643,11 +5647,15 @@ EXPORT_SYMBOL_GPL(skb_mpls_push); int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len, bool ethernet) { + int offset = skb->data - skb_mac_header(skb); int err; if (unlikely(!eth_p_mpls(skb->protocol))) return 0; + if (WARN_ONCE(offset, "We got skb with skb->data not at mac header (offset %d)\n", offset)) + return -EINVAL; + err = skb_ensure_writable(skb, mac_len + MPLS_HLEN); if (unlikely(err)) return err; -- 2.19.1