Skip to contentSkip to conversation

net: Check the expect of skb->data at mac header

PATCH In review Miaohe Lin 2 participants 2 messages Aug 20, 2020 – Aug 24, 2020

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

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.

---
 net/core/skbuff.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/core/skbuff.c +8 -0
index e18184ffa9c3..52d2ad54aa97 100644
@@ -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
maintainer
#1 lore raw

From: Miaohe Lin <[email protected]>
Date: Thu, 20 Aug 2020 08:28:22 -0400

Quoted 4 lines

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.

Both openvswitch and act_mpls.c seem to adhere to this constraint.

I don't see real value to these extra checks, sorry.