net: Check the expect of skb->data at mac header
Subsystems (2)
PATCH 1/1 net: Check the expect of skb->data at mac header
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 <[email protected]>
--- net/core/skbuff.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/core/skbuff.c +8 -0
@@ -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;
Signature · 1 line
2.19.1
David Miller
maintainerFrom: Miaohe Lin <[email protected]>
Date: Thu, 20 Aug 2020 08:28:22 -0400
Quoted 4 lines
skb_mpls_push()andskb_mpls_pop()expectskb->dataat mac header. Check this assumption or we would get wrongmac_headerandnetwork_header.Signed-off-by Miaohe Lin <[email protected]>
Both openvswitch and act_mpls.c seem to adhere to this constraint.
I don't see real value to these extra checks, sorry.